Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Query regarding Function
Replies: 7   Last Post: Mar 14, 2013 7:12 AM

 Messages: [ Previous | Next ]
 David Bailey Posts: 714 Registered: 11/7/08
Re: Query regarding Function
Posted: Mar 13, 2013 4:18 AM

[This thread is now closed. There have been enough answers. - Moderator]

On 12/03/2013 04:34, Rahul Chakraborty wrote:
> Dear all,
>
> Case1: In the following code
>
> Clear[f,x,y]
> g=Function[{x,y},x^2+2xy][b,a]
>
> The output is found to be b^2+2 xy
>
> Case2: But for the code
>
> Clear[f,x,y]
> g=Function[{x,y},x^2+2y][b,a]
>
> The output is 2 a+b^2
>
> Hence my query is why in case 1 x*y is not replaced by b and a whereas in case 2 it got replaced ?
>
> Regards,
> rc
>

Variable names in Mathemnatica can be more than one character long -
remember that computer algebra can require a lot of variables! Thus xy
is a quite distinct variable - space the two characters out to get a
product: x y .

Note that it is always useful to examine dubious expressions using
FullForm (possibly with Hold to prevent evaluation) to determine their
true structure. This resolved a host of puzzles:

In[1]:= x y //FullForm
Out[1]//FullForm= Times[x,y]

In[2]:= xy //FullForm
Out[2]//FullForm= xy

In[3]:= x*y //FullForm
Out[3]//FullForm= Times[x,y]

David Bailey
http://www.dbaileyconsultancy.co.uk

Date Subject Author
3/12/13 Rahul Chakraborty
3/13/13 Peter Pein
3/13/13 Dr. Wolfgang Hintze
3/13/13 Richard Fateman
3/13/13 Frank K
3/13/13 svkeeley@aol.com
3/13/13 David Bailey
3/14/13 Alexei Boulbitch