二项式曲线拟合
import numpy as np
from scipy.optimize import curve_fit
def f_fit(x, a, b, c):
return a*x**2+b*x+c
x=list(range(5))
for i in range(5):
x[i]=x[i]+1
y=[5076.4,5076.5,5076,5075.7,5075.8]
p_fit, prov = curve_fit(f_fit, x, y)
print(p_fit) #三个元素
print(p_fit[0]) #其中a,b,c分别元素
最小二乘法拟合
import numpy as np
from scipy.optimize import curve_fit
def f_fit(x, k,b):
return k*x+b
x=list(range(5))
for i in range(5):
x[i]=x[i]+1
y=[5076.4,5076.5,5076,5075.7,5075.8]
p_fit, prov = curve_fit(f_fit, x, y)
print(p_fit) #三个元素
print(p_fit[0]) #其中a,b,c分别元素