我正在尝试对一些周期性的实验数据进行曲线拟合,并发现将曲线拟合到其他函数的方法对三角函数不起作用--至少--我正在做的方法。
下面是我的代码:
falseData = Table[{x, N[3*Sin[4*x]]}, {x, 10}];
model = a*Sin[b*x];
fit = NonlinearModelFit[falseData, model, {a, b}, x]
Show[ListPlot[falseData, PlotStyle -> Red], Plot[fit[x], {x, 1, 10}]]
下面是代码生成的代码:
FittedModel[-0.184706 Sin[1.00073 x]]
如果我将本例中的Sin函数切换到Log或其他类型的函数,它可以很好地工作,但当我尝试使用Sin或Cos时,它会失败。
有什么建议吗?
发布于 2012-09-08 02:18:49
尝试使用NMinimize方法:
falseData = Table[{x, N[3*Sin[4*x]]}, {x, 10}];
model = a*Sin[b*x];
fit = NonlinearModelFit[falseData, model, {a, b}, x, Method -> NMinimize]
Show[ListPlot[falseData, PlotStyle -> Red], Plot[fit[x], {x, 1, 10}]]
下面是输出:
FittedModel[-3. Sin[2.28319 x]]
这是生成的曲线:
https://stackoverflow.com/questions/9985967
复制相似问题