Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'Problems with set, setdelayed and rules' topicStudent Support Forum > General > "Problems with set, setdelayed and rules"

Next Comment >Help | Reply To Topic
Author Comment/Response
12/16/06 05:53am


I am working a lot with physics equations where I have on the one hand variables, and on the other hand paramters, which depend on other parameters which are only given by a polynome.
In the following (very simplified example) f is a function which depends on variable x and parameters g and h which depend both on parameter p:

f[x_]:= g/h*x;
g[p_]= 1+p;

For numerical application, I would like to define a second function f with p as second variable. This I have done with different methods, and there I noticed a difference that I can't explain

f1[x_, p_] = f[x] /. params;
f2[x_, p_] := f[x] /. {g->g[p],h->h[p]};
f3[x_, p_] := f[x] /. params;

If I am now calculating f1[1,1], f2[1,1] and f3[1,1], f1 and f2 deliver as expected a numerical value, but for f3[1,1] p isn't replaced by its value 1.

Can anybody explain me the differences, especially the differences between f2 and f3? I suspected it to be exactly identical.

And does anybody know a better method to treat parameters? My problem is that when doing analytical transformations, an immediate replacement of the parameters g and h would make the result very hard to read, so I was searching for an easy method to replace them as late as possible.

Thanks in advance for any help,

URL: ,

Subject (listing for 'Problems with set, setdelayed and rules')
Author Date Posted
Problems with set, setdelayed and rules Goa 12/16/06 05:53am
Re: Problems with set, setdelayed and rules VL 01/04/07 6:33pm
Next Comment >Help | Reply To Topic