MathGroup Archive 2006

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

Search the Archive

Problems with Set, SetDelayed and replacement rules...

  • To: mathgroup at
  • Subject: [mg72274] Problems with Set, SetDelayed and replacement rules...
  • From: Johannes <ml.johannes at>
  • Date: Sun, 17 Dec 2006 06:20:36 -0500 (EST)
  • Organization: The Math Forum


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 (Derivatives, Integrations...), 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,

  • Prev by Date: Re: Notebook Typesetting for Printing
  • Next by Date: Re: Matching Or expressions
  • Previous by thread: Re: creating dirac bra-ket notations in Mathematica
  • Next by thread: Re: Problems with Set, SetDelayed and replacement rules...