Notating and solving equations in whit expr
Hello Guys,
I am trying to learn how to notate and solve this simple equation using expr I want to know the value of x.
x+2 = 3(x-38)
The result is x = 58
I want to know the value of x, using expr, so I am trying to notate to notate this in expr
2= (3 (x-38))-x , so when I send a 2 to expr it should give me 52 in the outlet.
When I notate it in expr as :
expr (3 * ($i1 -38))- $i1
But it does not work, so, how can I notate the equation en expr to know the value of x ?
Please help.
you cannot meaningfully represent a single-term equation as a function (which is what you are trying to do), as any such equation evaluates down to an identity (or is unsolvable). The expr box equivalent of your equation is [expr 58].
if you have two variables (x,y), one of which is dependent on the other, then you can have a meaningful equation, because one represents the input, and the other is the output. So you have to think "what is my input (known)?" and "how does it influence my output (soon-to-be-known)?"
so, if I adapt your equation, this would be meaningful: y+2=3(x-38)
which is equivalent to y = 3x-116
and your expression box equivalent would be [expr $i1*3-116] (output = 3* input-116)
Thank you floating point.
I really appreciate the time you took to explain it to me. I was so confused, now it makes sense.
Actually I solved it this way. Using the logical operator == , only when 58 is in the input the output will give 1(TRUE), means that the value of x is 58.
expr $i1 +2 == 3* ($i1 -38)
or you could simply have the == object, [== 58]
geht nicht gibt´s nicht.
you just have to check X against all possible inputs.
#P window setfont "Sans Serif" 9.;
#P number 197 269 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 130 229 77 9109513 route 0;
#P newex 130 194 192 9109513 expr (($i1+2) == (3*($i1-38)))*$i1;
#P newex 130 107 77 9109513 - 10000001;
#P button 64 37 21 0;
#P newex 64 78 77 9109513 uzi 20000001;
#P connect 2 0 3 0;
#P connect 0 2 2 0;
#P connect 1 0 0 0;
#P connect 3 0 4 0;
#P connect 4 1 5 0;
#P window clipboard copycount 6;
oh yes you already found out that a comparison operator is not exactly doing the same as "=" - but you can just write it the same way here. isnt it fun. :)
you could also do it with [if] and spare that [route]
Thank you guys,
"FLOATING POINT", your answer " or you could simply have the == object, [== 58] " won't work in this case, since the problem consisted in finding out the unknown value of x in an equation. ( I don't know the answer is 58 until we solve the equation: x+2 = 3(x-38)
And the problem with my solution :
expr $i1 +2 == 3* ($i1 -38)
is that I have to input ALL possible numbers until I get the right question, which is a waste of time and processor resources. Actually, I need to build a sort of "scientist calculator " able to solve equations.
then all the string content has to run through complicated text formatting and parsing an then it finally will land in a custom calculator app - i.e. you would have to recreate in max everything what the [expr] object does inside and more...
what is the aim? why not use google or wolframalpha?https://www.wolframalpha.com/input/?i=x%2B2+%3D+3(x-38)
aside from Roman's hyper-generalist suggestion, and aside from the fact I don't really understand what you want, it seems to me that you need to characterize your problem more coherently-- perhaps identify its overall mathematical structure: are all examples of your problem going to be of the form : A + B = C(A-D) ? (for example). If this is the case and that you want to isolate "A", and if the other elements are input variables, then you would have :
A + B = CA-CD
=> A = -B + CA - CD
=> A-CA = -B-CD
=> A(1-C) = -B-CD
=> A= (B+CD)/(C-1)
so then you'd have an expression which can work out what x is for any value of the other elements in the original equation, which would be your inputs (x would be the output):
[expr ($f1+$f2*$f3)/($f2-1)]
hope that is what you want