In [1]:
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
In [7]:
x = np.array([5.05, 5.25, 5.91, 6.54, 7.11, 7.68, 8.26, 8.85, 9.44, 10.01, 10.62, 11.17, 11.75, 12.32, 12.89, 13.46, 14.05, 14.66, 15.28, 15.87, 16.52, 17.12, 17.75, 18.38, 19.04, 19.61, 20.33, 20.94, 21.60, 22.23, 22.91, 23.50, 24.12, 24.77, 25.43, 26.02, 26.68, 27.29, 27.95, 28.58, 29.22, 29.87, 30.53, 31.21, 31.86, 32.39, 32.97, 33.54, 34.09, 34.60, 35.03])
In [8]:
y = [-7.82, -7.78, -7.41, -7.04, -6.63, -6.14, -5.57, -4.96, -4.43, -3.94, -3.41, -2.88, -2.27, -1.70, -1.09, -0.52, -0.07, 0.41, 0.82, 1.23, 1.60, 1.85, 2.10, 2.31, 2.40, 2.56, 2.53, 2.58, 2.55, 2.52, 2.40, 2.25, 2.10, 1.90, 1.67, 1.48, 1.24, 0.97, 0.82, 0.58, 0.39, 0.24, 0.12, -0.03, -0.06, -0.05, -0.05, -0.08, -0.07, -0.07, -0.06]
In [9]:
x += 5
In [11]:
order = 4
plt.figure()
p = np.poly1d(np.polyfit(x, y, order))
xp = np.linspace(5, 50, 1000)
_ = plt.plot(x, y, '.', xp, p(xp), '-')
In [20]:
for order in range(8):
plt.figure()
p = np.poly1d(np.polyfit(x, y, order))
xp = np.linspace(0, 50, 1000)
_ = plt.plot(x, y, '.', xp, p(xp), '-')
In [6]:
p = np.poly1d(np.polyfit(x, y, 5))
In [7]:
p
Out[7]:
In [12]:
d = np.polyder(p, m=1)
roots = np.roots(d)
print(roots)
In [9]:
p(43.03356301)
Out[9]:
In [10]:
ynew = y - p(43.03356301)
In [11]:
p = np.poly1d(np.polyfit(x, ynew, 5))
d = np.polyder(p, m=1)
roots = np.roots(d)
print(roots)
In [12]:
p = np.poly1d(np.polyfit(x, ynew, 5))
In [13]:
p
Out[13]:
In [14]:
pp =p
In [15]:
# a = np.poly1d([1.24e-4, -9.28e-3, 2.02e-1, -7.92e-1, -8.08])
# a = np.poly1d([-3.9816e-06, 5.22e-4, -2.4123e-2, 4.5666e-1, -2.75987, -2.54728])
a = np.poly1d([-3.98164e-6, 7.2108e-4, -4.8985e-2, 1.53337, -2.1417e1, 1.004588e2])
p = a
xp = np.linspace(10, 45, 1000)
_ = plt.plot(x, ynew, '.', xp, p(xp), '-')
In [49]:
print(p)
In [50]:
d = np.polyder(p, m=1)
roots = np.roots(d)
print(roots)
In [56]:
d
Out[56]:
In [51]:
d(14.32902487)
Out[51]:
In [53]:
dold = np.polyder(pp, m=1)
In [ ]:
d = np.polyder(p, m=1)
In [55]:
xp = np.linspace(10, 50, 10)
_ = plt.plot(xp, d(xp), '-', xp, dold(xp), ".")
In [ ]: