Im using the mpmath API to calculate the next sum
Consider the series u0, u1, u2, defined as follows:
u0 = 3/2 = 1,5 u1 = 5/3 = 1,6666666… un+1 = 2003 - 6002/un + 4000/un un-1
The series converges at 2, but with the rounding problem it seems to converge at 2000.
n Calculated value Rounded off exact value
2 1.800001 1.800000000
3 1.890000 1.888888889
4 3.116924 1.941176471
5 756.3870306 1.969696970
6 1996.761549 1.984615385
7 1999,99676781 1,992248062
8 1999,999997 1,996108949
9 2000.000000 1.998050682
10 2000.000000 1.999024390
My code is:
from mpmath import * mp.dps = 50 u0=mpf(3/2.0) u1=mpf(5/3.0) u=[] u.append(u0) u.append(u1) for i in range (2,11): un1=(2003-6002/u[i-1]+(mpf(4000)/mpf((u[i-1]*u[i-2])))) u.append(un1) print u
my bad results:
[mpf('1.5'), mpf('1.6666666666666667406815349750104360282421112060546875'), mpf('1.8000000000000888711326751945268011597589466120961647'), mpf('1.8888888889876302386905492787148253684796100079942617'), mpf('1.9411765751351638992775070422559330255517747908588059'), mpf('1.9698046831709839591526211645628191427874374792786951'), mpf('2.093979191783975876606205176530675127058752077926479'), mpf('106.44733511712489354422046139349654833300787666477228'), mpf('1964.5606972399290690749220686397494349501387742896911'), mpf('1999.9639916238009625032390578545797067344576357100626'), mpf('1999.9999640260895343960004614025893194430187653900418')]
I tried to execute some other functions (fdiv ...) or change the accuracy: the same bad result
What is wrong with this code?
Question: How to change my code to find the value 2.0 ??? with the formula:
un + 1 = 2003 - 6002 / un + 4000 / un un-1
thanks
python math floating-point arbitrary-precision fixed-point
aspire99
source share