Python Forum
semantic error log function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
semantic error log function
#1
the following function gives an approximation to the natural log function
and is totally correct:

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 other code is supposed to make the above function reach convergence faster

def fastln(n, x):
    a0 =(1 + x) / 2
    b0 =x ** (1 / 2)
    for i in range(n):
        a0=(a0 + b0) / 2
        a0=((a0 * b0) ** (1 / 2))
    for i in range(n+1):
        for j in range(1,n):
            a0=xx
            cc=[]
            cc.append(xx)
            ((cc[0][1] - 4 ** (-j) * cc[0][1])/(1 - 4 ** (-j)))
    return (x - 1)/cc[-1][-1]

print(fastln(4,4))
print(fastln(3,3))

x = np.linspace(10, 500, 100)
nn=range(2,10)
colors = mpl.cm.rainbow(np.linspace(0, 1, len(nn)))

for c,n in zip(colors,nn):
    plt.plot(x, (ln(n,x)), label='$n = {nn}$'.format(nn=list(nn)  )) 
however, the graph I obtain is totally unrelated to the log function,
why so? What's wrong with the second code?
Reply


Messages In This Thread
semantic error log function - by mcgrim - Apr-23-2019, 12:54 PM
RE: semantic error log function - by ichabod801 - Apr-23-2019, 01:45 PM
RE: semantic error log function - by mcgrim - Apr-23-2019, 06:16 PM
RE: semantic error log function - by ichabod801 - Apr-23-2019, 06:58 PM
RE: semantic error log function - by mcgrim - Apr-23-2019, 07:12 PM
RE: semantic error log function - by ichabod801 - Apr-23-2019, 07:24 PM
RE: semantic error log function - by mcgrim - Apr-23-2019, 07:29 PM
RE: semantic error log function - by buran - Apr-24-2019, 08:32 AM
RE: semantic error log function - by mcgrim - Apr-24-2019, 08:34 AM
RE: semantic error log function - by buran - Apr-24-2019, 08:50 AM
RE: semantic error log function - by mcgrim - Apr-24-2019, 09:07 AM
RE: semantic error log function - by buran - Apr-24-2019, 09:11 AM
RE: semantic error log function - by mcgrim - Apr-24-2019, 09:14 AM
RE: semantic error log function - by mcgrim - Apr-24-2019, 11:26 AM
RE: semantic error log function - by buran - Apr-24-2019, 11:35 AM
RE: semantic error log function - by mcgrim - Apr-24-2019, 11:39 AM
RE: semantic error log function - by buran - Apr-24-2019, 11:43 AM
RE: semantic error log function - by mcgrim - Apr-24-2019, 11:50 AM
RE: semantic error log function - by buran - Apr-24-2019, 06:34 PM
RE: semantic error log function - by mcgrim - Apr-24-2019, 07:53 PM
RE: semantic error log function - by buran - Apr-24-2019, 08:07 PM
RE: semantic error log function - by mcgrim - Apr-24-2019, 08:17 PM
RE: semantic error log function - by buran - Apr-24-2019, 08:36 PM
RE: semantic error log function - by mcgrim - Apr-24-2019, 08:43 PM
RE: semantic error log function - by buran - Apr-25-2019, 07:56 AM
RE: semantic error log function - by mcgrim - Apr-29-2019, 09:32 PM
invalid index to scalar variable - by mcgrim - Apr-24-2019, 08:22 AM

Forum Jump:

User Panel Messages

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