Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
approximation
#2
As far as I understood, sub stands for sub-index; If so, sqrt((a0+b0/2)*b0) doesn't equal to sqrt(a sub (i+1) + b sub i) in the formula. So, you have coded another formula than that written above.

from math import sqrt, log
 
def applog(n,x):
    a0=(1+x)/2
    b0=sqrt(x)
    for i in range(n):
        a0=(a0+b0)/2
        b0 = sqrt(a0 + b0)  # This line was changed... 
    return (x-1)/a0
  
for j in range(2, 45):
    error=(abs( applog(j,4)- (log(4))))
    print(f"{j}:{error}")
Output:
2:0.0053156365995163934 3:0.039090279331435385 4:0.061621145018602386 5:0.07728516949056563 6:0.08826319537752325 7:0.09595463102864743 8:0.10133370381925122 9:0.10508932614514 10:0.10770813826749515 11:0.10953258138230271 12:0.11080279652612712 13:0.11168674981804516 14:0.1123017079623232 15:0.11272943559557191 16:0.11302689201201455 17:0.11323373160573724 18:0.11337754927182253 19:0.11347754206638672 20:0.11354706207495191 21:0.11359539468519486 ....
So, iterative process doesn't converge to the expected solution... The iterative formula seems to be wrong...
Reply


Messages In This Thread
approximation - by mcgrim - Apr-13-2019, 08:22 PM
RE: approximation - by scidam - Apr-14-2019, 10:14 AM
RE: approximation - by mcgrim - Apr-14-2019, 11:38 AM
RE: approximation - by scidam - Apr-14-2019, 12:06 PM
RE: approximation - by mcgrim - Apr-15-2019, 10:19 AM
RE: approximation - by scidam - Apr-15-2019, 11:13 PM
RE: approximation - by mcgrim - Apr-17-2019, 08:13 PM
RE: approximation - by scidam - Apr-18-2019, 04:13 AM
RE: approximation - by mcgrim - Apr-18-2019, 07:20 AM
RE: approximation - by mcgrim - Apr-19-2019, 07:32 AM
RE: approximation - by mcgrim - Apr-19-2019, 08:08 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020