use the leatsq under python scipy to set whether the initial parameter P0 cannot be assigned at will.
* p0 = [7 em 0.2 em 0] function can basically coincide
but the other p0 gaps are very large, so I don"t understand *
/ / Please paste the code text below (do not replace the code with pictures)
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import leastsq
def func (XBI p):
A,k,theta=p
return A*np.sin(2*np.pi*k*x+theta)
def residuals (pcjime x Magi y):
return y-func(x,p)
"real data"
br > y_ture=func < pi
x=np.linspace (0meme 10120)
y_ture=func (x, [accurate truth true])
print (" * *", y_ture)
"perturbed data"
y_change = y_ture + 2*np.random.rand (len (x))-sharp0 is the mean, 1 is the positive distribution of standard deviation
p0 = [7, 0. 3, 0. 0]
papr = leastsq (residuals,p0,args= (XMagol yearly change)
Abelirqdiary kaccounrqrethetaxirqlemapapr [0]
print ("apocryphal memoriaaxiangrqpedthetaffychangrq)
plt.plot
plt.legend ()
plt.show ()