2012-04-03 88 views
3

我試圖曲線擬合一些週期性的實驗數據,並發現適用於其他函數曲線擬合的方法對於三角函數不適用 - 至少 - 我是這麼做的。Mathematica中的三角擬合不起作用?

這裏是我的代碼:

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]] 

A failure of a curve fit

它完美,如果我切換仙功能在這個例子中登錄或其他類型的功能,但是當我嘗試使用正弦或餘弦時失敗。

有什麼建議嗎?

+2

此問題已基本上覆蓋在[ mathematica.se]通過這個[答案](http://mathematica.stackexchange.com/a/23 52分之27)。 – rcollyer 2012-04-03 01:40:42

+0

@rcollyer請記住,MMA網站仍處於測試階段... – 2012-04-03 13:15:13

+0

謝謝你rcollyer。我沒有找到與我使用的Google關鍵字的鏈接... – 2012-04-03 13:22:29

回答

3

使用try 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]] 

,這裏是所得到的曲線:

result of fitting