@ BenedictWilkinsAI предложение - самый простой способ, написать уравнение с фиксированным значением, заменяющим среднее. Однако, если вы хотите использовать программное решение, вот графический установщик Python, который позволяет подгонять как нормальное (каламбур), так и фиксированное уравнение гауссовского пика. Когда используется фиксированное среднее значение параметра 9,0, подгонка заметно хуже - как и ожидалось. Кроме того, curve_fit () выдает предупреждение о том, что не может рассчитать ковариационную матрицу, поскольку средний параметр не может изменяться.
![plot1](https://i.stack.imgur.com/ONtMZ.png)
![plot2](https://i.stack.imgur.com/TlgP3.png)
import numpy, scipy, matplotlib
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
xData = numpy.array([5.357, 5.797, 5.936, 6.161, 6.697, 6.731, 6.775, 8.442, 9.861])
yData = numpy.array([0.376, 0.874, 1.049, 1.327, 2.054, 2.077, 2.138, 4.744, 7.104])
# normally fitted mean is 10.67571675
# set this value to None to fit normally, else
# set to the value of the fixed mean
fixedMean = 9.0
def func(x, a, b, c): # Gaussian peak equation
if fixedMean:
b = fixedMean
return a * numpy.exp(-0.5 * numpy.power((x-b) / c, 2.0))
# these are the same as the scipy defaults except for the fixed mean
if fixedMean:
initialParameters = numpy.array([1.0, fixedMean, 1.0])
else:
initialParameters = numpy.array([1.0, 1.0, 1.0])
# curve fit the test data
fittedParameters, pcov = curve_fit(func, xData, yData, p0=initialParameters)
modelPredictions = func(xData, *fittedParameters)
absError = modelPredictions - yData
SE = numpy.square(absError) # squared errors
MSE = numpy.mean(SE) # mean squared errors
RMSE = numpy.sqrt(MSE) # Root Mean Squared Error, RMSE
Rsquared = 1.0 - (numpy.var(absError) / numpy.var(yData))
print('Parameters:', fittedParameters)
print('RMSE:', RMSE)
print('R-squared:', Rsquared)
print()
##########################################################
# graphics output section
def ModelAndScatterPlot(graphWidth, graphHeight):
f = plt.figure(figsize=(graphWidth/100.0, graphHeight/100.0), dpi=100)
axes = f.add_subplot(111)
# first the raw data as a scatter plot
axes.plot(xData, yData, 'D')
# create data for the fitted equation plot
xModel = numpy.linspace(min(xData), max(xData))
yModel = func(xModel, *fittedParameters)
# now the model as a line plot
axes.plot(xModel, yModel)
axes.set_xlabel('X Data') # X axis data label
axes.set_ylabel('Y Data') # Y axis data label
plt.show()
plt.close('all') # clean up after using pyplot
graphWidth = 800
graphHeight = 600
ModelAndScatterPlot(graphWidth, graphHeight)