Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'time to convergence within e' topicStudent Support Forum > General > "time to convergence within e"

< Previous CommentHelp | Reply To Comment | Reply To Topic
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,

Subject (listing for 'time to convergence within e')
Author Date Posted
time to convergence within e Andy 10/27/08 01:02am
Re: time to convergence within e Peter Pein 10/27/08 07:00am
Re: time to convergence within e yehuda ben-s... 10/28/08 01:24am
Re: time to convergence within e yehuda ben-s... 10/28/08 03:35am
Re: time to convergence within e Xavier 10/29/08 07:56am
< Previous CommentHelp | Reply To Comment | Reply To Topic