0

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?

1 Answer 1

1

You should be able to do something like:

min([f(a,b,c) for a in list_of_a_values])

to get the minimum value of f for a looping through some values and fixed b and c

Sign up to request clarification or add additional context in comments.

2 Comments

This still only evaluates for the first value in the list instead of evaluating the function for each value.
If I make f print something, and run the above, it prints for every value of a in the list provided

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.