'Problems optimizing a three variable function using pythom
I'm trying to minimize a three-variabled function. I don't really care which method to use, but since I'm no expert I'm using scipy.optimize, which seemed easy to use. My code is the following:
from math import e
import scipy.integrate
import scipy.optimize as optimize
def func(y):
a=y[0]
b=y[1]
c=y[2]
Tx=70
Abac=lambda x:(a/b)*(e**(b*x)-1)*e**(-c*(x**2))
A=(a/b)*(e**(b*Tx)-1)*e**(-c*(Tx**2))
i=scipy.integrate.quad(Abac,0,Tx)
return(A/(1-i[0])-4.808e-4)
solution=optimize.minimize(func,(0.00291*10**(-8),0.46,2.91e-3),method="Powell",tol=1e-12)
But when I run it, I do not get a solution:
direc: array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]])
fun: nan
message: 'NaN result encountered.'
nfev: 318
nit: 2
status: 3
success: False
x: array([ 2.618034 , 3.07782822, -0.615124 ])
And I get the following error messages: overflow encountered in double_scalars invalid value encountered in double_scalars It doesn't seem to matter which tolerance or method I use, I tried changing it but with no luck. I think the error might be related to the fact that the equation has a "divide by 0" for certain values for the constants, but I'm not sure of how to solve this. Any help would be greatly appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
