I'm unsure of why there is an error on F=@x
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Patrick
am 1 Mär. 2024
Bearbeitet: Walter Roberson
am 2 Mär. 2024
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 Kommentare
Akzeptierte Antwort
Star Strider
am 1 Mär. 2024
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Elementary Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!