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!