So I have defined a function that evaluates a number of parameters
def chisq(I,energy,Bethe,N,Z,InverseBethe,Range,SThickness,SigmaThickness):
for i in range(len(energy)):
Bethe.append( 3.801e-19*(N*Z/energy[i])*(np.log(energy[i])+6.307-np.log(I)));
InverseBethe.append(1/Bethe[i])
chisq = 0
dof = 0
for i in range(len(energy)):
Range.append(-1*sci.simps(InverseBethe[0:i+1],energy[0:i+1], even='avg'))
Diff = SThickness[i]-Range[i]
Div = Diff/SigmaThickness[i]
chii = pow(Div,2)
chisq = chisq + chii
dof= dof+1
redChisq = chisq/dof
return redChisq;
I want to be able to loop the parameter I over a number of values, ie in an array or otherwise, until I can find the minimum value of the function.
I have used a 'for' loop when calling the function further down, and referred to the I[i], but it doesn't iterate over the array and only selects the first value of the array I have tried using scipy's minimize function, but that also only does one iteration.
How can I iterate over this one parameter whilst keeping the others the same?