我试图将我的位置与光强度数据匹配到以下形式的函数中:

Intensity pattern of single slit diffraction

该数据来自单缝散射实验,缝为0.08毫米= 0.00008 m,波长为650nano = 0.0000065 m.缝隙与光传感器之间的距离为70厘米= 0.7 m.实验中,将光传感器放置在缝隙前面,距离70厘米(将缝隙所在的点称为点S,将光传感器放置的点称为点O),在获取数据之前,沿着垂直于SO线的轴改变光传感器的位置,然后沿着该轴获取数据.我试图将我的数据融入Python中单缝散射方程的强度,但由于它必须处理太小的数字,因此无法优化,然后我try 了用Matlab,它也不起作用,我不知道为什么. Matlab curve fitting

请注意,sin(theta)是x/平方t(x#2 + L#2),其中L=0.7,b是x值的水平移动.

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()

位置(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.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.005、0.006、0.006、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.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.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.028、0.0280.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.034、0.035、0.035、0.035、0.035、0.036、0.037、0.037、0.037、0.0370.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.047、0.047、0.048、0.048、0.048、0.049、0.049、0.049、0.049、0.049、0.049、0.049、0.049、0.051、0.051、0.052、0.052、0.052、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.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.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.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.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.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.093、0.094、0.094、0.094、0.095、0.095、0.095、0.096、0.096、0.096、0.097、0.0970.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.103、0.103、0.104、0.104、0.104、0.104、0.104、0.104、0.104、0.104、0.1040.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]

光照强度(%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.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.085、0.067、0.055、0.061、0.061、0.055、0.055、0.061、0.061、0.0550.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.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.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.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.1950.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.067、0.085、0.079、0.073、0.085、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.067、0.085、0.073、0.055、0.061、0.061、0.055、0.061、0.055、0.055、0.055、0.073、0.067、0.055、0.061、0.067、0.055、0.0610.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.067、0.049、0.067、0.043、0.061、0.055、0.067、0.067、0.055、0.061、0.067、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.061、0.061、0.067、0.073、0.067、0.061、0.055、0.055、0.055、0.061]

推荐答案

从物理上看,折射图案类似于洛伦兹曲线.您可以通过更改您的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

与洛伦兹相比,高斯并不适合.它会错过折射图案的侧凸点.请参阅下面的匹配结果.

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

Python相关问答推荐

是否有使用纯霍夫曼编码的现代图像格式?

使用decorator 自动继承父类

Altair -箱形图边界设置为黑色,中线设置为红色

Python plt.text中重叠,包adjust_text不起作用,如何修复?

jit JAX函数中的迭代器

如何让 turtle 通过点击和拖动来绘制?

根据另一列中的nan重置值后重新加权Pandas列

用Python解密Java加密文件

大小为M的第N位_计数(或人口计数)的公式

log 1 p numpy的意外行为

对所有子图应用相同的轴格式

关于Python异步编程的问题和使用await/await def关键字

实现自定义QWidgets作为QTimeEdit的弹出窗口

Pandas计数符合某些条件的特定列的数量

Plotly Dash Creating Interactive Graph下拉列表

如何在Pyplot表中舍入值

为什么if2/if3会提供两种不同的输出?

Geopandas未返回正确的缓冲区(单位:米)

如何在BeautifulSoup/CSS Select 器中处理regex?

从列表中获取n个元素,其中list [i][0]== value''