MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: help: recursive functions


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?
> 
> --
> Okke
> 
> remove NOSPAM from my email address to reply

You should at least define y[n_ /; n < 0], otherwise the recursion will of
course be infinite. 

In your example, at n=0 for example Mathematica will try to evaluate. Using your
formula, it will have to evaluate at n=-1 and n=-2. For these, it will try to
evaluate at n=-4, -3, and again -2. For these, it ... and so on - no recursion
limit! Mathematica gives up after $RecursionLimit.

Ciao
      -erk-
-- 
 Dr.-Ing. Erk JENSEN                    mailto:Erk.Jensen at cern.ch
 CERN  PS/RF  L19510                    http://cern.ch/Erk.Jensen
 CH-1211 Geneva 23                      Tel.:     +41 22 76 74298
 Switzerland                            Fax.:     +41 22 76 78510


  • Prev by Date: Re: help: recursive functions
  • Next by Date: RE: help: recursive functions
  • Previous by thread: Re: help: recursive functions
  • Next by thread: RE: help: recursive functions