I am trying to minimize a function using scipy.optimize.minimize()
. Below is the piece of code which I am trying to execute.
When I execute the same I am getting
NameError: name 'j' is not defined
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.optimize import minimize
from sklearn.metrics import r2_score
url = 'test_data.txt'
z = pd.read_csv(url)
#
e1 = z['strain'].values
sigx = z['stress'].values
e=np.array(e1)
sig1=np.array(sigx)
#print (sig1)
def sig2(e):
j=[1000,0.2]
return np.mean((sig1-(j[0]*np.power(e,j[1])))*(sig1-(j[0]*np.power(e,j[1]))))
print (sig2(e))
res= minimize(sig2,j)
print(res)
What I expect as the outcome was values of j[0] & j[1] to get the function value (sig2) to be near to zero