Search code examples
pythoncurve-fittingtrigonometrycurve

How can I fit my position vs light intensity data into a diffraction pattern curve?


I am trying to fit my position vs. light intensity data into a function of the form:

Intensity pattern of single slit diffraction

The data is from a single slit diffraction experiment, the slit with was 0.08 mm = 0.00008 m, wavelength was 650 nm = 0.00000065 m. The distance between the slit and the light sensor was 70 cm = 0.7 m. In the experiment, light sensor was placed in front of the slit with a distance 70 cm (lets call the point where slit stands the point S and lets call the point where light sensor placed the point O), before taking data, the location of the light sensor is changed along the axis that is perpendicular to SO line, then the data is taken along this axis. I tried to fit my data into intensity of single slit diffraction equation in python but since it had to work with numbers that are too small it couldn't be optimized, then I tried with Matlab, it also doesn't work and I don't know why. Matlab curve fitting

Note that sin(theta) is x/sqrt(x^2+L^2) where L=0.7 and b is the horizontal shifting of x values.

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit

def intensityFunction(x, a, b):
    numerator = np.sin(np.pi * (x - b) * 0.00008 / (np.sqrt(0.49 + x ** 2 - 2 * b * x + b ** 2) * 0.00000065))
    denominator = np.pi * (x - b) * 0.00008 / (np.sqrt(0.49 + x ** 2 - 2 * b * x + b ** 2) * 0.00000065)
    return a* (numerator/denominator)**2

positions = np.array(positionArray)
lightIntensity=np.array([LightIntensityArray])

popt, pcov = curve_fit(intensityFunction, positions, lightIntensity, p0=[1,0])

a_opt, b_opt = popt

plt.scatter(positions, lightIntensity, label="Data", s=4)
plt.plot(positions, intensityFunction(positions, a_opt, b_opt), color='red', label='Fit: a={:.2f}, b={:.2f}'.format(a_opt, b_opt))
plt.xlabel('Position (m)')
plt.ylabel('Light Intensity (% max)')
plt.legend()
plt.show()

Position (m): [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001108, 0.0001108, 0.0001663, 0.0003325, 0.0004433, 0.000665, 0.0007758, 0.0008867, 0.0008867, 0.0009421, 0.0009975, 0.001, 0.001, 0.002, 0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.005, 0.005, 0.005, 0.005, 0.006, 0.006, 0.007, 0.007, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.01, 0.01, 0.01, 0.011, 0.011, 0.012, 0.012, 0.013, 0.013, 0.013, 0.014, 0.014, 0.014, 0.014, 0.014, 0.014, 0.015, 0.015, 0.015, 0.015, 0.016, 0.016, 0.017, 0.017, 0.017, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.019, 0.019, 0.019, 0.02, 0.02, 0.02, 0.021, 0.021, 0.022, 0.022, 0.023, 0.023, 0.023, 0.023, 0.023, 0.023, 0.024, 0.024, 0.025, 0.025, 0.025, 0.025, 0.026, 0.026, 0.026, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.028, 0.028, 0.028, 0.029, 0.03, 0.031, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.033, 0.033, 0.033, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.035, 0.035, 0.035, 0.035, 0.036, 0.037, 0.037, 0.037, 0.037, 0.038, 0.038, 0.039, 0.039, 0.04, 0.04, 0.041, 0.041, 0.042, 0.042, 0.043, 0.043, 0.044, 0.044, 0.044, 0.045, 0.045, 0.045, 0.045, 0.045, 0.046, 0.046, 0.047, 0.047, 0.048, 0.048, 0.048, 0.048, 0.049, 0.049, 0.049, 0.049, 0.049, 0.049, 0.049, 0.05, 0.05, 0.05, 0.051, 0.051, 0.051, 0.052, 0.052, 0.052, 0.053, 0.053, 0.053, 0.053, 0.053, 0.053, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.055, 0.056, 0.056, 0.056, 0.056, 0.057, 0.057, 0.057, 0.057, 0.058, 0.059, 0.059, 0.059, 0.06, 0.06, 0.061, 0.061, 0.061, 0.061, 0.061, 0.062, 0.062, 0.062, 0.062, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.064, 0.064, 0.064, 0.065, 0.066, 0.066, 0.066, 0.067, 0.067, 0.067, 0.068, 0.068, 0.068, 0.069, 0.07, 0.07, 0.071, 0.071, 0.071, 0.072, 0.072, 0.073, 0.073, 0.073, 0.073, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.075, 0.075, 0.075, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.078, 0.078, 0.079, 0.079, 0.079, 0.08, 0.081, 0.082, 0.082, 0.083, 0.084, 0.085, 0.086, 0.086, 0.086, 0.087, 0.087, 0.087, 0.087, 0.087, 0.087, 0.088, 0.088, 0.088, 0.089, 0.09, 0.09, 0.091, 0.091, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.093, 0.093, 0.094, 0.094, 0.094, 0.095, 0.095, 0.095, 0.096, 0.096, 0.096, 0.097, 0.097, 0.097, 0.098, 0.098, 0.098, 0.099, 0.099, 0.099, 0.1, 0.1, 0.1, 0.101, 0.101, 0.101, 0.101, 0.101, 0.102, 0.102, 0.102, 0.102, 0.102, 0.103, 0.103, 0.103, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104]

Light Intensity (%max): [0.061, 0.061, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.067, 0.061, 0.067, 0.067, 0.061, 0.079, 0.055, 0.061, 0.055, 0.061, 0.061, 0.067, 0.079, 0.067, 0.061, 0.061, 0.067, 0.067, 0.061, 0.073, 0.049, 0.055, 0.067, 0.073, 0.061, 0.061, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.061, 0.061, 0.061, 0.049, 0.055, 0.067, 0.049, 0.055, 0.055, 0.043, 0.067, 0.061, 0.067, 0.067, 0.061, 0.061, 0.085, 0.067, 0.055, 0.061, 0.061, 0.055, 0.055, 0.049, 0.061, 0.055, 0.043, 0.061, 0.067, 0.061, 0.079, 0.043, 0.061, 0.049, 0.061, 0.055, 0.061, 0.061, 0.061, 0.055, 0.067, 0.073, 0.061, 0.061, 0.061, 0.055, 0.055, 0.061, 0.067, 0.055, 0.043, 0.055, 0.049, 0.061, 0.055, 0.073, 0.061, 0.055, 0.061, 0.061, 0.055, 0.055, 0.073, 0.049, 0.061, 0.055, 0.073, 0.055, 0.073, 0.043, 0.061, 0.055, 0.049, 0.073, 0.061, 0.061, 0.061, 0.055, 0.049, 0.061, 0.073, 0.067, 0.061, 0.061, 0.049, 0.067, 0.049, 0.067, 0.055, 0.061, 0.061, 0.061, 0.067, 0.055, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.061, 0.061, 0.049, 0.079, 0.061, 0.079, 0.079, 0.067, 0.079, 0.079, 0.055, 0.049, 0.067, 0.085, 0.061, 0.067, 0.092, 0.067, 0.073, 0.079, 0.061, 0.049, 0.061, 0.073, 0.067, 0.061, 0.067, 0.067, 0.073, 0.079, 0.085, 0.085, 0.073, 0.085, 0.098, 0.067, 0.073, 0.098, 0.079, 0.067, 0.073, 0.085, 0.073, 0.073, 0.067, 0.067, 0.079, 0.049, 0.073, 0.055, 0.055, 0.049, 0.067, 0.067, 0.061, 0.079, 0.079, 0.085, 0.098, 0.098, 0.098, 0.098, 0.116, 0.067, 0.061, 0.055, 0.085, 0.067, 0.085, 0.104, 0.146, 0.146, 0.146, 0.171, 0.159, 0.159, 0.165, 0.153, 0.146, 0.098, 0.092, 0.079, 0.073, 0.079, 0.085, 0.098, 0.098, 0.104, 0.098, 0.11, 0.14, 0.183, 0.195, 0.244, 0.287, 0.342, 0.372, 0.391, 0.403, 0.391, 0.342, 0.293, 0.244, 0.238, 0.22, 0.238, 0.195, 0.195, 0.195, 0.195, 0.183, 0.177, 0.183, 0.165, 0.244, 0.488, 0.678, 0.708, 1.007, 1.428, 1.679, 1.99, 2.539, 3.272, 4.254, 5.176, 5.689, 5.963, 6.116, 6.299, 6.25, 6.11, 6.079, 6.012, 5.756, 5.438, 5.078, 4.651, 4.193, 3.864, 3.662, 3.565, 3.424, 3.272, 3.174, 3.082, 3.076, 3.125, 3.198, 3.369, 3.412, 3.418, 3.369, 3.29, 3.174, 3.131, 3.107, 3.095, 3.088, 3.088, 3.082, 3.064, 3.04, 3.052, 3.003, 2.948, 2.966, 2.93, 2.905, 2.863, 2.832, 2.783, 2.655, 2.344, 1.758, 1.27, 0.885, 0.482, 0.244, 0.159, 0.159, 0.165, 0.214, 0.25, 0.293, 0.354, 0.391, 0.385, 0.342, 0.269, 0.208, 0.189, 0.14, 0.098, 0.098, 0.098, 0.098, 0.134, 0.159, 0.146, 0.159, 0.153, 0.171, 0.177, 0.165, 0.195, 0.195, 0.183, 0.189, 0.171, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.189, 0.195, 0.177, 0.177, 0.165, 0.195, 0.159, 0.153, 0.153, 0.146, 0.146, 0.14, 0.153, 0.134, 0.122, 0.128, 0.116, 0.11, 0.098, 0.098, 0.073, 0.079, 0.073, 0.092, 0.079, 0.104, 0.14, 0.14, 0.098, 0.098, 0.092, 0.061, 0.079, 0.073, 0.073, 0.085, 0.085, 0.104, 0.098, 0.098, 0.104, 0.098, 0.098, 0.098, 0.079, 0.079, 0.061, 0.061, 0.067, 0.061, 0.061, 0.055, 0.055, 0.055, 0.067, 0.085, 0.079, 0.073, 0.085, 0.079, 0.079, 0.092, 0.104, 0.073, 0.073, 0.073, 0.085, 0.055, 0.067, 0.055, 0.067, 0.061, 0.055, 0.067, 0.055, 0.085, 0.085, 0.073, 0.079, 0.073, 0.092, 0.073, 0.073, 0.079, 0.079, 0.079, 0.067, 0.085, 0.073, 0.055, 0.061, 0.055, 0.061, 0.061, 0.055, 0.061, 0.055, 0.073, 0.067, 0.055, 0.061, 0.067, 0.061, 0.055, 0.055, 0.061, 0.055, 0.067, 0.061, 0.055, 0.067, 0.061, 0.073, 0.061, 0.061, 0.061, 0.067, 0.049, 0.067, 0.043, 0.061, 0.055, 0.067, 0.067, 0.055, 0.061, 0.067, 0.061, 0.061, 0.055, 0.079, 0.061, 0.055, 0.061, 0.055, 0.061, 0.067, 0.067, 0.055, 0.055, 0.055, 0.061, 0.055, 0.055, 0.055, 0.055, 0.067, 0.061, 0.055, 0.061, 0.067, 0.055, 0.061, 0.061, 0.055, 0.067, 0.055, 0.061, 0.055, 0.055, 0.067, 0.061, 0.067, 0.061, 0.061, 0.067, 0.073, 0.067, 0.061, 0.055, 0.055, 0.055, 0.061]


Solution

  • Physically a diffraction pattern is similar to a Lorentzian curve. You can fit it as follows, by changing your p0.

    import numpy as np
    import matplotlib.pyplot as plt
    from scipy.optimize import curve_fit
    
    def intensityFunction(x, a, b):
        numerator = np.sin(np.pi * (x - b) * 0.00008 / (np.sqrt(0.49 + x ** 2 - 2 * b * x + b ** 2) * 0.00000065))
        denominator = np.pi * (x - b) * 0.00008 / (np.sqrt(0.49 + x ** 2 - 2 * b * x + b ** 2) * 0.00000065)
        return a* (numerator/denominator)**2
    
    positionArray = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001108, 0.0001108, 0.0001663, 0.0003325, 0.0004433, 0.000665, 0.0007758, 0.0008867, 0.0008867, 0.0009421, 0.0009975, 0.001, 0.001, 0.002, 0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.005, 0.005, 0.005, 0.005, 0.006, 0.006, 0.007, 0.007, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.01, 0.01, 0.01, 0.011, 0.011, 0.012, 0.012, 0.013, 0.013, 0.013, 0.014, 0.014, 0.014, 0.014, 0.014, 0.014, 0.015, 0.015, 0.015, 0.015, 0.016, 0.016, 0.017, 0.017, 0.017, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.019, 0.019, 0.019, 0.02, 0.02, 0.02, 0.021, 0.021, 0.022, 0.022, 0.023, 0.023, 0.023, 0.023, 0.023, 0.023, 0.024, 0.024, 0.025, 0.025, 0.025, 0.025, 0.026, 0.026, 0.026, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.028, 0.028, 0.028, 0.029, 0.03, 0.031, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.033, 0.033, 0.033, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.035, 0.035, 0.035, 0.035, 0.036, 0.037, 0.037, 0.037, 0.037, 0.038, 0.038, 0.039, 0.039, 0.04, 0.04, 0.041, 0.041, 0.042, 0.042, 0.043, 0.043, 0.044, 0.044, 0.044, 0.045, 0.045, 0.045, 0.045, 0.045, 0.046, 0.046, 0.047, 0.047, 0.048, 0.048, 0.048, 0.048, 0.049, 0.049, 0.049, 0.049, 0.049, 0.049, 0.049, 0.05, 0.05, 0.05, 0.051, 0.051, 0.051, 0.052, 0.052, 0.052, 0.053, 0.053, 0.053, 0.053, 0.053, 0.053, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.055, 0.056, 0.056, 0.056, 0.056, 0.057, 0.057, 0.057, 0.057, 0.058, 0.059, 0.059, 0.059, 0.06, 0.06, 0.061, 0.061, 0.061, 0.061, 0.061, 0.062, 0.062, 0.062, 0.062, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.064, 0.064, 0.064, 0.065, 0.066, 0.066, 0.066, 0.067, 0.067, 0.067, 0.068, 0.068, 0.068, 0.069, 0.07, 0.07, 0.071, 0.071, 0.071, 0.072, 0.072, 0.073, 0.073, 0.073, 0.073, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.075, 0.075, 0.075, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.078, 0.078, 0.079, 0.079, 0.079, 0.08, 0.081, 0.082, 0.082, 0.083, 0.084, 0.085, 0.086, 0.086, 0.086, 0.087, 0.087, 0.087, 0.087, 0.087, 0.087, 0.088, 0.088, 0.088, 0.089, 0.09, 0.09, 0.091, 0.091, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.093, 0.093, 0.094, 0.094, 0.094, 0.095, 0.095, 0.095, 0.096, 0.096, 0.096, 0.097, 0.097, 0.097, 0.098, 0.098, 0.098, 0.099, 0.099, 0.099, 0.1, 0.1, 0.1, 0.101, 0.101, 0.101, 0.101, 0.101, 0.102, 0.102, 0.102, 0.102, 0.102, 0.103, 0.103, 0.103, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104]
    LightIntensityArray = [0.061, 0.061, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.067, 0.061, 0.067, 0.067, 0.061, 0.079, 0.055, 0.061, 0.055, 0.061, 0.061, 0.067, 0.079, 0.067, 0.061, 0.061, 0.067, 0.067, 0.061, 0.073, 0.049, 0.055, 0.067, 0.073, 0.061, 0.061, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.061, 0.061, 0.061, 0.049, 0.055, 0.067, 0.049, 0.055, 0.055, 0.043, 0.067, 0.061, 0.067, 0.067, 0.061, 0.061, 0.085, 0.067, 0.055, 0.061, 0.061, 0.055, 0.055, 0.049, 0.061, 0.055, 0.043, 0.061, 0.067, 0.061, 0.079, 0.043, 0.061, 0.049, 0.061, 0.055, 0.061, 0.061, 0.061, 0.055, 0.067, 0.073, 0.061, 0.061, 0.061, 0.055, 0.055, 0.061, 0.067, 0.055, 0.043, 0.055, 0.049, 0.061, 0.055, 0.073, 0.061, 0.055, 0.061, 0.061, 0.055, 0.055, 0.073, 0.049, 0.061, 0.055, 0.073, 0.055, 0.073, 0.043, 0.061, 0.055, 0.049, 0.073, 0.061, 0.061, 0.061, 0.055, 0.049, 0.061, 0.073, 0.067, 0.061, 0.061, 0.049, 0.067, 0.049, 0.067, 0.055, 0.061, 0.061, 0.061, 0.067, 0.055, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.061, 0.061, 0.049, 0.079, 0.061, 0.079, 0.079, 0.067, 0.079, 0.079, 0.055, 0.049, 0.067, 0.085, 0.061, 0.067, 0.092, 0.067, 0.073, 0.079, 0.061, 0.049, 0.061, 0.073, 0.067, 0.061, 0.067, 0.067, 0.073, 0.079, 0.085, 0.085, 0.073, 0.085, 0.098, 0.067, 0.073, 0.098, 0.079, 0.067, 0.073, 0.085, 0.073, 0.073, 0.067, 0.067, 0.079, 0.049, 0.073, 0.055, 0.055, 0.049, 0.067, 0.067, 0.061, 0.079, 0.079, 0.085, 0.098, 0.098, 0.098, 0.098, 0.116, 0.067, 0.061, 0.055, 0.085, 0.067, 0.085, 0.104, 0.146, 0.146, 0.146, 0.171, 0.159, 0.159, 0.165, 0.153, 0.146, 0.098, 0.092, 0.079, 0.073, 0.079, 0.085, 0.098, 0.098, 0.104, 0.098, 0.11, 0.14, 0.183, 0.195, 0.244, 0.287, 0.342, 0.372, 0.391, 0.403, 0.391, 0.342, 0.293, 0.244, 0.238, 0.22, 0.238, 0.195, 0.195, 0.195, 0.195, 0.183, 0.177, 0.183, 0.165, 0.244, 0.488, 0.678, 0.708, 1.007, 1.428, 1.679, 1.99, 2.539, 3.272, 4.254, 5.176, 5.689, 5.963, 6.116, 6.299, 6.25, 6.11, 6.079, 6.012, 5.756, 5.438, 5.078, 4.651, 4.193, 3.864, 3.662, 3.565, 3.424, 3.272, 3.174, 3.082, 3.076, 3.125, 3.198, 3.369, 3.412, 3.418, 3.369, 3.29, 3.174, 3.131, 3.107, 3.095, 3.088, 3.088, 3.082, 3.064, 3.04, 3.052, 3.003, 2.948, 2.966, 2.93, 2.905, 2.863, 2.832, 2.783, 2.655, 2.344, 1.758, 1.27, 0.885, 0.482, 0.244, 0.159, 0.159, 0.165, 0.214, 0.25, 0.293, 0.354, 0.391, 0.385, 0.342, 0.269, 0.208, 0.189, 0.14, 0.098, 0.098, 0.098, 0.098, 0.134, 0.159, 0.146, 0.159, 0.153, 0.171, 0.177, 0.165, 0.195, 0.195, 0.183, 0.189, 0.171, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.189, 0.195, 0.177, 0.177, 0.165, 0.195, 0.159, 0.153, 0.153, 0.146, 0.146, 0.14, 0.153, 0.134, 0.122, 0.128, 0.116, 0.11, 0.098, 0.098, 0.073, 0.079, 0.073, 0.092, 0.079, 0.104, 0.14, 0.14, 0.098, 0.098, 0.092, 0.061, 0.079, 0.073, 0.073, 0.085, 0.085, 0.104, 0.098, 0.098, 0.104, 0.098, 0.098, 0.098, 0.079, 0.079, 0.061, 0.061, 0.067, 0.061, 0.061, 0.055, 0.055, 0.055, 0.067, 0.085, 0.079, 0.073, 0.085, 0.079, 0.079, 0.092, 0.104, 0.073, 0.073, 0.073, 0.085, 0.055, 0.067, 0.055, 0.067, 0.061, 0.055, 0.067, 0.055, 0.085, 0.085, 0.073, 0.079, 0.073, 0.092, 0.073, 0.073, 0.079, 0.079, 0.079, 0.067, 0.085, 0.073, 0.055, 0.061, 0.055, 0.061, 0.061, 0.055, 0.061, 0.055, 0.073, 0.067, 0.055, 0.061, 0.067, 0.061, 0.055, 0.055, 0.061, 0.055, 0.067, 0.061, 0.055, 0.067, 0.061, 0.073, 0.061, 0.061, 0.061, 0.067, 0.049, 0.067, 0.043, 0.061, 0.055, 0.067, 0.067, 0.055, 0.061, 0.067, 0.061, 0.061, 0.055, 0.079, 0.061, 0.055, 0.061, 0.055, 0.061, 0.067, 0.067, 0.055, 0.055, 0.055, 0.061, 0.055, 0.055, 0.055, 0.055, 0.067, 0.061, 0.055, 0.061, 0.067, 0.055, 0.061, 0.061, 0.055, 0.067, 0.055, 0.061, 0.055, 0.055, 0.067, 0.061, 0.067, 0.061, 0.061, 0.067, 0.073, 0.067, 0.061, 0.055, 0.055, 0.055, 0.061]
    
    
    positions = np.array(positionArray)
    lightIntensity=np.array(LightIntensityArray)
    
    
    x0_loren = np.sum(np.multiply(positions,lightIntensity)) / np.sum(lightIntensity)
    k_loren = 1 / (np.pi*np.max(lightIntensity))
    
    p = [k_loren, x0_loren]
    popt, pcov = curve_fit(intensityFunction, positions, lightIntensity, p0=p)
    a_opt, b_opt = popt
    
    plt.scatter(positions, lightIntensity, label="Data", s=4)
    plt.plot(positions, intensityFunction(positions, a_opt, b_opt), color='red', label='Fit: a={:.2f}, b={:.2f}'.format(a_opt, b_opt))
    plt.xlabel('Position (m)')
    plt.ylabel('Light Intensity (% max)')
    plt.legend()
    plt.show()
    

    Output: enter image description here

    Compared to Lorentzian, gaussian is not a good fit. It will miss the side bumps of the diffraction patterns. See the following fitting result.

    import numpy as np
    import matplotlib.pyplot as plt
    from scipy.optimize import curve_fit
    def intensityFunction(x,a,b,sigma):
        return a*np.exp(-(x-b)**2/(2*sigma**2))
        
    positionArray = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0001108, 0.0001108, 0.0001663, 0.0003325, 0.0004433, 0.000665, 0.0007758, 0.0008867, 0.0008867, 0.0009421, 0.0009975, 0.001, 0.001, 0.002, 0.002, 0.002, 0.002, 0.002, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.004, 0.005, 0.005, 0.005, 0.005, 0.006, 0.006, 0.007, 0.007, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.008, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.01, 0.01, 0.01, 0.011, 0.011, 0.012, 0.012, 0.013, 0.013, 0.013, 0.014, 0.014, 0.014, 0.014, 0.014, 0.014, 0.015, 0.015, 0.015, 0.015, 0.016, 0.016, 0.017, 0.017, 0.017, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.019, 0.019, 0.019, 0.02, 0.02, 0.02, 0.021, 0.021, 0.022, 0.022, 0.023, 0.023, 0.023, 0.023, 0.023, 0.023, 0.024, 0.024, 0.025, 0.025, 0.025, 0.025, 0.026, 0.026, 0.026, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.027, 0.028, 0.028, 0.028, 0.029, 0.03, 0.031, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.033, 0.033, 0.033, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.034, 0.035, 0.035, 0.035, 0.035, 0.036, 0.037, 0.037, 0.037, 0.037, 0.038, 0.038, 0.039, 0.039, 0.04, 0.04, 0.041, 0.041, 0.042, 0.042, 0.043, 0.043, 0.044, 0.044, 0.044, 0.045, 0.045, 0.045, 0.045, 0.045, 0.046, 0.046, 0.047, 0.047, 0.048, 0.048, 0.048, 0.048, 0.049, 0.049, 0.049, 0.049, 0.049, 0.049, 0.049, 0.05, 0.05, 0.05, 0.051, 0.051, 0.051, 0.052, 0.052, 0.052, 0.053, 0.053, 0.053, 0.053, 0.053, 0.053, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.055, 0.056, 0.056, 0.056, 0.056, 0.057, 0.057, 0.057, 0.057, 0.058, 0.059, 0.059, 0.059, 0.06, 0.06, 0.061, 0.061, 0.061, 0.061, 0.061, 0.062, 0.062, 0.062, 0.062, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.063, 0.064, 0.064, 0.064, 0.065, 0.066, 0.066, 0.066, 0.067, 0.067, 0.067, 0.068, 0.068, 0.068, 0.069, 0.07, 0.07, 0.071, 0.071, 0.071, 0.072, 0.072, 0.073, 0.073, 0.073, 0.073, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.074, 0.075, 0.075, 0.075, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.076, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.077, 0.078, 0.078, 0.079, 0.079, 0.079, 0.08, 0.081, 0.082, 0.082, 0.083, 0.084, 0.085, 0.086, 0.086, 0.086, 0.087, 0.087, 0.087, 0.087, 0.087, 0.087, 0.088, 0.088, 0.088, 0.089, 0.09, 0.09, 0.091, 0.091, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.092, 0.093, 0.093, 0.094, 0.094, 0.094, 0.095, 0.095, 0.095, 0.096, 0.096, 0.096, 0.097, 0.097, 0.097, 0.098, 0.098, 0.098, 0.099, 0.099, 0.099, 0.1, 0.1, 0.1, 0.101, 0.101, 0.101, 0.101, 0.101, 0.102, 0.102, 0.102, 0.102, 0.102, 0.103, 0.103, 0.103, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104, 0.104]
    LightIntensityArray = [0.061, 0.061, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.067, 0.061, 0.067, 0.067, 0.061, 0.079, 0.055, 0.061, 0.055, 0.061, 0.061, 0.067, 0.079, 0.067, 0.061, 0.061, 0.067, 0.067, 0.061, 0.073, 0.049, 0.055, 0.067, 0.073, 0.061, 0.061, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.061, 0.061, 0.061, 0.049, 0.055, 0.067, 0.049, 0.055, 0.055, 0.043, 0.067, 0.061, 0.067, 0.067, 0.061, 0.061, 0.085, 0.067, 0.055, 0.061, 0.061, 0.055, 0.055, 0.049, 0.061, 0.055, 0.043, 0.061, 0.067, 0.061, 0.079, 0.043, 0.061, 0.049, 0.061, 0.055, 0.061, 0.061, 0.061, 0.055, 0.067, 0.073, 0.061, 0.061, 0.061, 0.055, 0.055, 0.061, 0.067, 0.055, 0.043, 0.055, 0.049, 0.061, 0.055, 0.073, 0.061, 0.055, 0.061, 0.061, 0.055, 0.055, 0.073, 0.049, 0.061, 0.055, 0.073, 0.055, 0.073, 0.043, 0.061, 0.055, 0.049, 0.073, 0.061, 0.061, 0.061, 0.055, 0.049, 0.061, 0.073, 0.067, 0.061, 0.061, 0.049, 0.067, 0.049, 0.067, 0.055, 0.061, 0.061, 0.061, 0.067, 0.055, 0.061, 0.061, 0.061, 0.061, 0.073, 0.061, 0.061, 0.061, 0.049, 0.079, 0.061, 0.079, 0.079, 0.067, 0.079, 0.079, 0.055, 0.049, 0.067, 0.085, 0.061, 0.067, 0.092, 0.067, 0.073, 0.079, 0.061, 0.049, 0.061, 0.073, 0.067, 0.061, 0.067, 0.067, 0.073, 0.079, 0.085, 0.085, 0.073, 0.085, 0.098, 0.067, 0.073, 0.098, 0.079, 0.067, 0.073, 0.085, 0.073, 0.073, 0.067, 0.067, 0.079, 0.049, 0.073, 0.055, 0.055, 0.049, 0.067, 0.067, 0.061, 0.079, 0.079, 0.085, 0.098, 0.098, 0.098, 0.098, 0.116, 0.067, 0.061, 0.055, 0.085, 0.067, 0.085, 0.104, 0.146, 0.146, 0.146, 0.171, 0.159, 0.159, 0.165, 0.153, 0.146, 0.098, 0.092, 0.079, 0.073, 0.079, 0.085, 0.098, 0.098, 0.104, 0.098, 0.11, 0.14, 0.183, 0.195, 0.244, 0.287, 0.342, 0.372, 0.391, 0.403, 0.391, 0.342, 0.293, 0.244, 0.238, 0.22, 0.238, 0.195, 0.195, 0.195, 0.195, 0.183, 0.177, 0.183, 0.165, 0.244, 0.488, 0.678, 0.708, 1.007, 1.428, 1.679, 1.99, 2.539, 3.272, 4.254, 5.176, 5.689, 5.963, 6.116, 6.299, 6.25, 6.11, 6.079, 6.012, 5.756, 5.438, 5.078, 4.651, 4.193, 3.864, 3.662, 3.565, 3.424, 3.272, 3.174, 3.082, 3.076, 3.125, 3.198, 3.369, 3.412, 3.418, 3.369, 3.29, 3.174, 3.131, 3.107, 3.095, 3.088, 3.088, 3.082, 3.064, 3.04, 3.052, 3.003, 2.948, 2.966, 2.93, 2.905, 2.863, 2.832, 2.783, 2.655, 2.344, 1.758, 1.27, 0.885, 0.482, 0.244, 0.159, 0.159, 0.165, 0.214, 0.25, 0.293, 0.354, 0.391, 0.385, 0.342, 0.269, 0.208, 0.189, 0.14, 0.098, 0.098, 0.098, 0.098, 0.134, 0.159, 0.146, 0.159, 0.153, 0.171, 0.177, 0.165, 0.195, 0.195, 0.183, 0.189, 0.171, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.195, 0.189, 0.195, 0.177, 0.177, 0.165, 0.195, 0.159, 0.153, 0.153, 0.146, 0.146, 0.14, 0.153, 0.134, 0.122, 0.128, 0.116, 0.11, 0.098, 0.098, 0.073, 0.079, 0.073, 0.092, 0.079, 0.104, 0.14, 0.14, 0.098, 0.098, 0.092, 0.061, 0.079, 0.073, 0.073, 0.085, 0.085, 0.104, 0.098, 0.098, 0.104, 0.098, 0.098, 0.098, 0.079, 0.079, 0.061, 0.061, 0.067, 0.061, 0.061, 0.055, 0.055, 0.055, 0.067, 0.085, 0.079, 0.073, 0.085, 0.079, 0.079, 0.092, 0.104, 0.073, 0.073, 0.073, 0.085, 0.055, 0.067, 0.055, 0.067, 0.061, 0.055, 0.067, 0.055, 0.085, 0.085, 0.073, 0.079, 0.073, 0.092, 0.073, 0.073, 0.079, 0.079, 0.079, 0.067, 0.085, 0.073, 0.055, 0.061, 0.055, 0.061, 0.061, 0.055, 0.061, 0.055, 0.073, 0.067, 0.055, 0.061, 0.067, 0.061, 0.055, 0.055, 0.061, 0.055, 0.067, 0.061, 0.055, 0.067, 0.061, 0.073, 0.061, 0.061, 0.061, 0.067, 0.049, 0.067, 0.043, 0.061, 0.055, 0.067, 0.067, 0.055, 0.061, 0.067, 0.061, 0.061, 0.055, 0.079, 0.061, 0.055, 0.061, 0.055, 0.061, 0.067, 0.067, 0.055, 0.055, 0.055, 0.061, 0.055, 0.055, 0.055, 0.055, 0.067, 0.061, 0.055, 0.061, 0.067, 0.055, 0.061, 0.061, 0.055, 0.067, 0.055, 0.061, 0.055, 0.055, 0.067, 0.061, 0.067, 0.061, 0.061, 0.067, 0.073, 0.067, 0.061, 0.055, 0.055, 0.055, 0.061]
    
    
    positions = np.array(positionArray)
    lightIntensity=np.array(LightIntensityArray)
    
    mean = sum(np.multiply(positions,lightIntensity))/len(positions)
    sigma = sum(lightIntensity * (positions - mean)**2)/len(positions)
    
    p = [1, mean, sigma]
    popt, pcov = curve_fit(intensityFunction, positions, lightIntensity, p0=p)
    
    plt.scatter(positions, lightIntensity, s=4)
    plt.plot(positions, gaus(positions,*popt), color='red')
    plt.xlabel('Position (m)')
    plt.ylabel('Light Intensity (% max)')
    plt.legend()
    plt.show()
    

    Output: enter image description here