Re: Puzzled over (un)changing argument symbols in functions
- To: mathgroup at smc.vnet.net
- Subject: [mg27977] Re: Puzzled over (un)changing argument symbols in functions
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 27 Mar 2001 01:26:13 -0500 (EST)
- References: <99n5t5$ihf@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
fSoln = RSolve[{a[n] == (2 + b)*a[n - 1] - a[n - 2], a[3] == 1, a[-3] == 1}, a[n], n] /. n - 3 -> True; With f2[n_,b_]:=(a[n]/.fSoln[[1]]); We see that we are storing the rule for ?f2 Global`f2 f2[n_, b_] := a[n] /. fSoln[[1]] Note that there is no b on the right, so the b_ on the left has nowhere to send to. But if we use f2[n_,b_]=(a[n]/.fSoln[[1]]); Then ?f2 Global`f2 f2[n_, b_] = If[n >= -3, ((2 + b - Sqrt[b]*Sqrt[4 + b])^ n + (2 + b + Sqrt[b]*Sqrt[4 + b])^n)/2^n, 0]/ ((2 + b)*(1 + 4*b + b^2)) and f2 behaves as follows f2[n,b] If[n >= -3, ((2 + b - Sqrt[b]*Sqrt[4 + b])^n + (2 + b + Sqrt[b]*Sqrt[4 + b])^n)/2^n, 0]/ ((2 + b)*(1 + 4*b + b^2)) f2[n,b1] If[n >= -3, ((2 + b1 - Sqrt[b1]*Sqrt[4 + b1])^n + (2 + b1 + Sqrt[b1]*Sqrt[4 + b1])^n)/2^n, 0]/ ((2 + b1)*(1 + 4*b1 + b1^2)) -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "A. E. Siegman" <siegman at stanford.edu> wrote in message news:99n5t5$ihf at smc.vnet.net... > 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? >