有没有一种工具可以将方程的图形表示转换为大约的数学方程?(将图形表示转换为近似的数学方程)
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()
我看到过一些将方程拟合到图像中的工具,但现在我想不起它们的名称。快速的谷歌搜索找到了这个商业应用程序: http://imagedig-2d-3d-image-digitizer.smartcode.com/info.html