Re: Puzzled over (un)changing argument symbols in functions
- To: mathgroup at smc.vnet.net
- Subject: [mg27971] Re: Puzzled over (un)changing argument symbols in functions
- From: Erich Mueller <emuelle1 at uiuc.edu>
- Date: Tue, 27 Mar 2001 01:26:08 -0500 (EST)
- Organization: University of Illinois at Urbana-Champaign
- References: <99n5t5$ihf@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Your problem is with delayed asignments. Here is a simpler example that
illustrates the same problem:
g = 1+y; f[x_,y_] := x+ g
Typing in f[3,2] gives 4+y, rather than 6. The variables 3 and 2 are
substituted into the expression x+g before g is expanded.
In this simple case, one can get around the problem by writing
f[x_,y_] := Evaluate[x+g]
or
f[x_,y_] = x+g
In your case you will probably want to make fSoln an explicit function of
b, and use a delayed assynment for it.
Good luck,
Erich
On 26 Mar 2001, A. E. Siegman wrote:
> Here are three cells just to confirm that if I define a trivial function
> f1[y,z], then substitute y1 and z1 for y and z, the result is what you'd
> think it would be
>
> In[1] := f1[y_, z_] := y - z;
>
> In[2] := f1[y, z]
>
> Out[2] = y - z
>
> In[3] := f1[y1, z1]
>
> Out[3] = y1 - z1
>
> Now I define a slightly more complex but still algebraic function
> f2[n,b] using RSolve. For simplicity I haven't printed the Outputs
> below, but the essential result is that b is *not* replaced by b1 in
> Output[] -- Outputs [7] and [8] are identical:
>
> In[4] := << DiscreteMath`RSolve`;
>
> In[5] := fSoln = RSolve[ { a[n] == (2 + b)a[n - 1] - a[n - 2],
> a[3] == 1, a[-3] == 1}, a[n], n ] /. (n ? -3) ->True;
>
> In[6] := f2[n_, b_] := (a[n] /. fSoln[[1]]);
>
> In[7]:= f2[n, b]
>
> In[8]:= f2[n, b1]
>
> Why doesn't f2[n,b] behave like f1[y,x] did?
>
>