[Date Index] [Thread Index] [Author Index]
Re: problem writing a simple equation--urgent!!!
On 8/29/04 at 3:54 AM, erkenays at yahoo.com (aysegul) wrote: >I have a problem about writing an equation in mathematica. >I am writing the following equation: >u[x_, y_] = x + 2*y >and when I write for example u[2,4] , it gives the result. But the >problem that I have is expressing this equation with parameters. That >is >u[x, x] = x + 2*x >but when I ask u[2,4]; it gives u[2,4] result.It doesn't calculate. >So, how can I write this equation? It is difficult for me to determine the source of your confusion since you are using terms in what seems to me a non-standard way. For example, I would describe u[x_,y_] as a function named u with parameters named x, y which you set to x + 2 y. And given the following: In:= u[x_, y_] = x + 2*y Out= x + 2*y In:=u[x, x] Out=x + 2*x I don't understand what you are trying to do by writing u[x, x] = x + 2*x When you write u[x_,y_] you are describing a function of two variables you've named x and y. The "_" matches any expression. OTOH, when you write u[x,x] you are describing a function of specific variables x, and x. These variables cannot be 2 and 4 unless you specifically assign the values 2 and 4 to them elsewhere. And when you write u[x,x]= x + 2 x you've told Mathematica how to compute u with the parameters x and x and only for those parameters. That is 2 and 4 are different. So Mathematica returns u[2,4] unevaluated. I also think you would find it worthwhile to understand the difference between Set, "=" and SetDelayed, ":=". When you write u[x_, y_] = x + 2 y, the expression x + 2 y is evaluated immediately and u is set to the result. OTOH, writing u[x_, y_]:= x + 2 y leaves the expression x + 2 y unevaluated until it is used later. In general, this is the behavior you want for functions. As for an equation, in Mathematica that would be written with Equal, "==". For example x + 2 y == 0 would be an equation of two variables x and y -- To reply via email subtract one hundred and four