Re: creating functions from the result of Solve[]
- To: mathgroup at smc.vnet.net
 - Subject: [mg41858] Re: creating functions from the result of Solve[]
 - From: bobhanlon at aol.com (Bob Hanlon)
 - Date: Sat, 7 Jun 2003 00:08:47 -0400 (EDT)
 - References: <bbq83u$d4r$1@smc.vnet.net>
 - Sender: owner-wri-mathgroup at wolfram.com
 
Your equation is recursive: use RSolve.  You also need to define starting
values, 
say y[0] and y[1].
Needs["DiscreteMath`RSolve`"];
Clear[y];
y[n_?NonNegative] := 
  Evaluate[y[n] /. 
      Simplify[RSolve[{3y[n - 2] + 6y[n - 1] - 2y[n] == 0,y[0]==y0,y[1]==y1}, 
            y[n],n], n>=0][[1]]]
Table[y[n], {n,0,5}]//Simplify
{y0, y1, (3/2)*(y0 + 2*y1), (3/2)*(3*y0 + 7*y1), 
  (63*y0)/4 + 36*y1, 54*y0 + (495*y1)/4}
Bob Hanlon
In article <bbq83u$d4r$1 at smc.vnet.net>, kroosu at tref.nl (Okke) wrote:
<< Subject:	creating functions from the result of Solve[]
From:		kroosu at tref.nl (Okke)
To: mathgroup at smc.vnet.net
Date:		Fri, 6 Jun 2003 14:22:54 +0000 (UTC)
hello,
i have an equation and i want to make a function from the result of
Solve[]. 
for example:
IN: Solve[3y[n - 2] + 6y[n - 1] - 2y[n] == 0, y[n]]
OUT: {{y[n] -> (3*y[-2 + n] + 6*y[-1 + n])/2}}
and now i'd like to have the function
y[n_/;n>=0] := (3*y[-2 + n] + 6*y[-1 + n])/2
y[n]/.Flatten[Solve[eqn==0,y[n]]]       is possible, but
y[n_]:=y[n]/.Flatten[Solve[eqn==0,y[n]]] isn't
is there anybody who could help me get this to work?