Stats

Popular Posts

Followers

Mathematica 教學:最小平方法

戴忠淵 於 2015年8月15日星期六 下午5:24 發表

Manipulate[
DynamicModule[{pts=RandomReal[{0,5},{k,2}],y,x,function},
LocatorPane[Dynamic[pts],
Dynamic[y[x_]=Normal@Fit[pts,Flatten@{1,Table[x^p,{p,power}]},x];
function=CoefficientList[y[x],x];
Plot[y[x],{x,0,10},PlotRange->{{0,10},{0,10}},
AspectRatio->1,
Frame->True,
Epilog->{
Text[Style[function.Table["x"^p,{p,0,power}],Italic,12],
Scaled[{0.5,0.8}]],
Point[pts],
Dashed,Red,Line[{#,{#[[1]],y[#[[1]]]}}]&/@pts}]]]],
{{k,6,"Points"},3,12,1,ControlType->PopupMenu},
{{power,2,"次方"},{1,2,3}}]

Tags: ,

讀者回應 ( 0 意見 )

發佈留言

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~