| Author |
Comment/Response |
Xavier
|
10/29/08 07:56am
Hey,
Here is a possibility: after having defined N (call it Num or else because N is protected), n as the recursion function, and e the precision, you have just to type:
NestWhile[{#[[1]] + 1, n[#[[1]] + 1]} &, {0, 0},
Abs[Num - #[[2]]] >= e &]
This function operates the function
{#[[1]] + 1, n[#[[1]] + 1]} &
on itself until the moment
Abs[Num - #[[2]]] >= e &
is no longer true (hence the >= !!!)
This function can be written like this:
Function[ {t, n[t]}, {t+1, n[t+1]} ]
simply to remember the value of t since this what you are interested it. Then, the condition to stop corresponds to basically this:
Function[ {t, n[t]}, Abs[Num - n[t]] >= e &
Since at each step you get both the value of t and n[t], at the end of this command, you will get them too and if you are interested in the only value of t, apply First on this whole thing.
Don't hesitate if you have any question,
Cheers
Xavier
Attachment: Recursion.nb, URL: http://zavou.zxr.fr, |
|