I'm unsure of why there is an error on F=@x
1 次查看(过去 30 天)
显示 更早的评论
function Xs= newtonM(fun,FunDer,Xest,err)
for i=1:100
Xs= Xest-Fun(Xest)/FunDer(Xest);
error =abs((Xs-Xest)/Xs)*100;
fprintf('%3i %11.6f %11.6\n', i, Xs, error)
if error < err
break;
end
Xest= Xs;
end
end
f=@(x)exp(-0.5*x)*(4-x)-2;
df=@(x)exp(-0.5*x)*(-3+0.5*x);
Xs = newtonM(f,df,5);
0 个评论
采纳的回答
Star Strider
2024-3-1
The statement order is reversed from what it should be —
f=@(x)exp(-0.5*x)*(4-x)-2;
df=@(x)exp(-0.5*x)*(-3+0.5*x);
Xs = newtonM(f,df,5,0.001)
function Xs= newtonM(fun,FunDer,Xest,err)
for i=1:100
Xs= Xest-fun(Xest)/FunDer(Xest);
error =abs((Xs-Xest)/Xs)*100;
fprintf('%3i %11.6f %11.6\n', i, Xs, error)
if error < err
break;
end
Xest= Xs;
end
end
Also, ‘newtonM’ needed an ‘err’ argument.
.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!