Matlab simple iteration error problem
显示 更早的评论
Below is a basic code of finding a root of a function using the Newton Root method. While i set the imax, which is the maximum number of iteration, the final number of iteration running this code has exactly one more than my maximum no. of iterations set. And the no. of iteration is different with the one of the model answer from my teacher. Anyone has an idea why is this? I have exam next week please help.
clear; clc; Fun=@(x)(8-4.5*(x-sin(x))); FunDer=@(x)(-4.5*(1-cos(x))); root=newtonroothaha(Fun,FunDer,2,0.0001,10)
function[Xs]=newtonroothaha(Fun,FunDer,Xest,Err,imax) oerr=100; iteration=0; while (iteration<=imax && oerr>Err) iteration=iteration+1; Xnew=Xest-(Fun(Xest)/FunDer(Xest)); oerr=abs((Xnew-Xest)/Xest); end Xs=Xnew; iact=iteration end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!