• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jun 27th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from scipy import *
2. import numpy as np
3. from numpy import array
4. from scipy import integrate
5. import matplotlib.pyplot as plt
6. import scipy.integrate as si
7. from scipy.optimize import fsolve
8. from math import log
9. import matplotlib as mpl
10. import itertools
11.
12.
13. def applog(n,x):
14.     a0=(1+x)/2
15.     b0=sqrt(x)
16.
17.     for i in range(n):
18.         a0=(a0+b0)/2
19.         b0=sqrt((a0)*b0)
20.    return (x-1)/a0
21.
22. def Euler_accelerate(sequence):
23.
24.     s0 = next(sequence)
25.     s1 = next(sequence)
26.     s2 = next(sequence)
27.     while True:
28.         yield s0 - ((s1 - s0)**2)/(s2 - 2*s1 + s0)
29.         s0, s1, s2 = s1, s2, next(sequence)
30.
31.
32. x = np.linspace(10, 500, 100)
33. nn=range(1,6)
34. colors = mpl.cm.rainbow(np.linspace(0, 1, len(nn)))
35.
36.
37. for c,n in zip(colors,nn):
38.     print(itertools.islice(Euler_accelerate(applog(n,x)), 10))
39.     plt.plot(itertools.islice(Euler_accelerate(applog(n,x)), 10))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?