from __future__ import division from math import sqrt goldenarray=[1]; goldenmean=(sqrt(5)-1)/2; N_max=input("Choose the maximum power of N (at least 2) for time-out purposes:"); N=2; i=1; while (N==2 or goldenarray[N]==recursive[N]) and N<N_max: N+=1; while i<=N: goldenarray.append(goldenmean*goldenarray[i-1]); i+=1; i=N-1; recursive=goldenarray; while i<=N: recursive[i]=recursive[i-2]-recursive[i-1]; i+=1; print "The power at which round off error occurs is "+str(N)+".\nthe value of the non-recursive approximation, which is more wrong, is "+str(goldenarray[N])+",\nwhile the value of the more accurate recursive approximation is "+str(recursive[N]); # we suspect the recursive formula to be more accurate because the error in it is additive rather than multiplicative and the errors in all the different numbers are likely to self-correct somewhat, while the multiplicative errors will not.
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question