[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: recursive function
From: |
Windhorn, Allen E [ACIM/LSA/MKT] |
Subject: |
RE: recursive function |
Date: |
Wed, 31 Oct 2018 14:02:26 +0000 |
Ian et al,
> -----Original Message-----
> From: Help-octave [mailto:help-octave-
> address@hidden On Behalf Of Ian McCallion
>
> function ret= f(x)
> if x==1
> ret = 100;
> else
> ret = (f(x-1)+200)*1.05;
> end
> end
Try f(0), or f(1.5). What should this function do with non-integer x? (Probably
just drop the fractional part.) What about x<1? (I guess return 100.) If
x>256,
crashes with maximum recursion error.
A good example for learning recursion, as it illustrates reasons not to use it.
Regards,
Allen