I have this function $y = \exp(-x)$. I have a list of $x$ values and corresponding $y$ values.
X = [-3., -2., -1., 0., 1., 2., 3., 4., 5., 6.]
Y = [20.085536923187668, 7.38905609893065, 2.718281828459045, 1.0, 0.36787944117144233, 0.1353352832366127, 0.049787068367863944, 0.01831563888873418, 0.006737946999085467, 0.0024787521766663585]
For each list element, I am getting $y-x = 0$, which is good.
for xi,yi in zip (X,Y):
print(yi-np.exp(-xi))
What I am trying to do is to change my equation slightly and find the optimum value of the parameter $B$. So the modified equation is,
$y = \exp(-B*x)$
Ideally, I should get a $B=1$ for each of the list elements of X
and Y
.
The $B$ value is 1 as expected.
def test_cost5(param):
B=param
#print(b)
return Y[3]-np.exp(-beta*X[3])
test_initial_guess=1
results=optimize.minimize(test_cost5, test_initial_guess, method='BFGS')
results
Gives output,
fun: array([0.])
hess_inv: array([[1]])
jac: array([0.])
message: 'Optimization terminated successfully.'
nfev: 3
nit: 0
njev: 1
status: 0
success: True
x: array([1.])
Can I have some help on the following problems?
- Can I use one more parameter apart from $B$?
- I want to optimize these multiple parameters for a set of data and find the optimal values of the parameters. Can it be done?