I got the task to calculate the optimal parameters for the following viscosity-formula: Click here for the formula
Our Prof just gave us the hint to try out the scipy.optimize.minimize and the scipy.optimize.differential_evolution function on the square deviation (The formula he gave us for that and the Values in this formula are 3 real points that the viscosity-function should picture) of the viscosity formula. Here's the Graph to imagine how the function should look like.
So after giving my best on finding out how these functions work I gave up with differential_evolution because I couldn't make it work with my code so I focussed on the minimize function and thought I understood whats happening but I dont understand what I need to give the function as "guess" (x0 parameter) so it starts calculating the optimal values.
I got problems with getting the formula into python too, so I hope at least that's right.
My code is:
import scipy.optimize as optimize
import numpy as np
def visc(x, a0, a1, a2, a3, a4, a5):
ergebnis = a0*np.exp(-a1*x) + a2*np.exp(-a3*x) + a4*np.exp(-a5*x)
return ergebnis
def error(a):
a0, a1, a2, a3, a4, a5 = a
ergebnis = (visc(40, a0, a1, a2, a3, a4, a5) - 39.3)**2 + (visc(50, a0, a1, a2, a3, a4, a5) - 26.9)**2 + (visc(100, a0, a1, a2, a3, a4, a5) - 5.4)**2
return ergebnis
print(optimize.minimize(error, (0.1, 5, 0.1, 5, 3, 5)))
So maybe I'm just very lost and the solution is very trivial but right now I'm really desperate because I'm just stuck in my task and I would appreciate if some Scipy Pro's could help me with that.
I never worked with scipy or numpy or any other module before so please be patient with me.
Thanks for helping!