       Re: Problems with Set, SetDelayed and replacement rules...

• To: mathgroup at smc.vnet.net
• Subject: [mg72294] Re: Problems with Set, SetDelayed and replacement rules...
• From: dh <dh at metrohm.ch>
• Date: Tue, 19 Dec 2006 06:35:02 -0500 (EST)
• References: <em3a6c\$7fq\$1@smc.vnet.net>

```
Hi Johannes,

there is nothing wrong with your  treatment of parameters, but you have

to pay attentio  to function arguments. Consider: f[p_]:=Print[p].

If you set p to some value: p=1, what would you expect to be printed by:

f. Well, after you got this, we can fix f3. We have to explicitely

bring "p" into the definition, exactly what f1=.. and f2:=.. do. You

could e.g. use Evaluate:

f3[x_, p_] := Evaluate[f[x] /. params]

Daniel

Johannes wrote:

> Hi,

>

> 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;

> h[p_]=1+p^2;

> params={g->g[p],h->h[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,

> Johannes

>

```

• Prev by Date: Re: RE: Problems with Set, SetDelayed and replacement rules...
• Next by Date: RSolve and known indexed variables
• Previous by thread: Re: RE: Problems with Set, SetDelayed and replacement rules...
• Next by thread: Re: Problems with Set, SetDelayed and replacement rules...