Re: help: recursive functions
- To: mathgroup at smc.vnet.net
- Subject: [mg32636] Re: [mg32616] help: recursive functions
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Fri, 1 Feb 2002 02:02:43 -0500 (EST)
- Organization: JEOL (USA) Ltd.
- References: <200201310645.BAA04374@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Okke wrote: > Hello, > > I'm having some problems with a recursive function. > Could somebody please help me by telling me how I > should enter such a function? > > tia, > > This is what I've done so far: > > f[n_]:=Sin[Pi*n*(0.05+(0.0005*n))] > y[n_]:=1.5*y[n-1]-0.85*y[n-2]+f[n] > > I'm trying to Plot[y[n],{n,0,320}] but that gives me > an error: $RecursionLimit::reclim: Recursion depth of 256 exceeded. > > btw, is there an option to fill the area under the sine? > There are no initial conditions specified for y[n] so the recursion never stops. Is the range of n restricted in some way eg. n>0? Do you happen to know the value of y[n] for some particular values of y eg. y[0]=_, y[1]=_? If you are going to us this function for large values of n you may want to define y[n_]:=y[n]=1.5*y[n-1]-0.85*y[n-2]+f[n] and call this function for some smaller values of n to cache the values before calling it for the largest values of n. Either way though for large n this function will consume a lot of memory and time to calculate, is there a closed form expression for the terms of your series? Also you will probably have to redefine $RecursionLimit to $RecursionLimit = 320 at least once you have set your stopping conditions. Finally, from the definition of y[n_] I assume you expect n to only take on integer values. Using plot may evaluate your function at noninteger values of n, you probably want to use ListPlot[Table[y[n],{n,0,320}],PlotJoined->True] Regards, Sseziwa MUkasa