code to do a minimised chi squared fit on a function by varying two variables in python for a function with a maximum point not working correctly
I have written a piece of code intended to perform a minimised chi squared fit by varying two parameters, the problem section of code is below:
conversion_factor = 0.3894 * 10**9
def cross_section(parameters, E, Γee):
mZ, ΓZ = parameters
return conversion_factor * (12 * np.pi / (mZ ** 2)) * (
(E ** 2) / ((E ** 2 - mZ ** 2) ** 2) + (mZ ** 2) * (
ΓZ ** 2)) * (Γee ** 2)
def chi_squared(parameters, E, sigma, sigma_error, mZ_start, ΓZ_start, Γee):
mZ, ΓZ = parameters
model = cross_section(parameters, E,Γee)
return np.sum(((model - sigma) / sigma_error) ** 2)
E = combined_data['% centre-of-mass energy (GeV)']
sigma = combined_data['cross section (nb)']
sigma_error = combined_data['uncertainty (nb)']
mZ_start, ΓZ_start = [90, 3]
Γee = 83.91
result = fmin(chi_squared, (mZ_start, ΓZ_start),
args=(E, sigma, sigma_error, mZ_start, ΓZ_start, Γee),
full_output=True, disp=False)
print(result[0][0])
print(result[0][1])
The code only returns my initial values of mZ_start and ΓZ_start, not the maximum point of my chi squared fit. Can anybody help me understand why?
source https://stackoverflow.com/questions/77578836/code-to-do-a-minimised-chi-squared-fit-on-a-function-by-varying-two-variables-in
Comments
Post a Comment