For a task for school, I have to write my own fit function by using the least squares method. The problem is I don't know how to do that, specifically I don't know how to minimize my function to calculate my fit parameters.The problem here is also that my fit function is not linear, so my book says I have to try guess some values for my fit parameters and then minimize my function. But still I don't know how do to that. The code that you can find below is my code right now, I got it from somebody but I don't understand what it does so :).
Thanks in advance!
def fit(x,mu,gamma,back,A): return A*(gamma/((x-mu)**2+gamma**2))+back def Ls_rechte(y): Ls = 0 for i in range(len(Positie)): Ls = Ls + (Intensiteit[i]- fit(Positie[i],y,y,y,y))**2/(FoutI[i]**2) return Ls nu = len(Positie)-4 mini = minimize(Ls_rechte,(150,0,100,1)) display(mini)