一个可能符合您描述的常见问题称为curve fitting:您有一些数据(在您的情况下,您已经从图表中读取)并且您想到了一个方程的形式,并且您想要找到最适合图形的方程所需的参数。
一个有用的方法是适合least squares 错误。大多数数据分析工具包都提供最小二乘包。
这是一个例子:假设方程是 A*sin(2*pi*100.x)*x^B,我需要找到最适合我的 A 和 B 的值(A=10.0 和在本例中 B=3.0)。
这是用于生成此拟合的代码。它使用 Python 和 Scipy,并根据示例 here 进行了修改。)
from numpy import *
from scipy.optimize import leastsq
import matplotlib.pyplot as plt
def my_func(x, p): # the function to fit (and also used here to generate the data)
return p[0]*sin(2*pi*100.*x)*x**p[1]
# First make some data to represent what would be read from the graph
p_true = 10., 3.0 # the parameters used to make the true data
x = arange(.5,.5+12e-2,2e-2/60)
y_true = my_func(x, p_true)
y_meas = y_true + .08*random.randn(len(x)) # add some noise to make the data as read from a graph
# Here's where you'd start for reading data from a graph
def residuals(p, y, x): # a function that returns my errors between fit and data
err = y - my_func(x, p)
return err
p0 = [8., 3.5] # some starting parameters to my function (my initial guess)
plsq = leastsq(residuals, p0, args=(y_meas, x)) # do the least squares fit
# plot the results
plt.plot(x, my_func(x, plsq[0]), x, y_meas, '.', x, y_true)
plt.title('Least-squares fit to curve')
plt.legend(['Fit', 'Graph', 'True'])
plt.show()