Help with Newton's method function?
3 ビュー (過去 30 日間)
古いコメントを表示
This is the function I've been making to run Newton's method, but I can't get it to work. Any help with what I might be missing? Thanks!
function xn = newtonmethod(f,fd,x0,tol)
xn=x0;
err=abs(f(xn)-0);
i=0;
while err>tol
i=i+1;
xnew=xn-(f(xn)/fd(xn));
err=abs(f(xnew)-0);
end
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 11 月 20 日
I suspect your
err=abs(f(xnew)-0);
should be
err=abs(f(xnew)-f(xn));
unless you know that your f() has a "right" value of 0.
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!