MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: problem writing a simple equation--urgent!!!

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50364] Re: problem writing a simple equation--urgent!!!
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Mon, 30 Aug 2004 01:34:37 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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[1], x[2]] = x[1] + 2*x[2] 

>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[1]:= u[x_, y_] = x + 2*y
Out[1]= x + 2*y

In[2]:=u[x[1], x[2]]
Out[2]=x[1] + 2*x[2]

I don't understand what you are trying to do by writing u[x[1], x[2]] = x[1] + 2*x[2]

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[1],x[2]] you are describing a function of specific variables x[1], and x[2]. 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[1],x[2]]= x[1] + 2 x[2] you've told Mathematica how to compute u with the parameters x[1] and x[2] 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


  • Prev by Date: Re: problem writing a simple equation--urgent!!!
  • Next by Date: 0^0=1 (?)
  • Previous by thread: Re: problem writing a simple equation--urgent!!!
  • Next by thread: Time ticks for Parametric plot