Question: Please complete in MATLAB: The Newton's Method code is the following: function x = newton(f,df,x0,tol,kmax); % function x = newton(f,df,x0,tol,kmax); % Given a differentiable function
Please complete in MATLAB:

The Newton's Method code is the following:
function x = newton(f,df,x0,tol,kmax);
% function x = newton(f,df,x0,tol,kmax);
% Given a differentiable function f with df = df/dx, routine,
% when convergent returns an approximate root x obtained via
% Newton-Raphson iteration. Other inputs are an error tolerance
% tol (max over error between successive iterations and abs(f)),
% the max number kmax allowed iterations, and initial iteration
% x0. tol=1e-8 and kmax = 1e5 are defaults, if left unspecified.
switch nargin
case 3,
tol = 1e-8
kmax = 1e5;
case 4,
kmax = 1e5;
case 5,
% Fall through.
otherwise,
error('newton called with incorrect number of arguments')
end
x = x0; err=100; k = 0; % x=x0 here allows return for large tol.
while err >= tol
y = f(x0);
x = x0 - y/df(x0);
err = max(abs(y),abs(x-x0));
x0 = x;
k = k+1;
if k>=kmax
disp(['No convergence after ' num2str(kmax) ' iterations.'])
disp(['Error at this stage is ' num2str(err)])
return
end
end
if isfinite(x)
disp(['Converged in ' num2str(k) ' iterations with tol ' num2str(tol)])
else
disp(['No convergence after ' num2str(k) ' iterations. Iterations' ...
' overflowed to infinity.']);
end
4. Apply Newton's method to find the three roots of the function f(x)=esin3x+x62x4x31 on the interval [2,2]. For each root, print out the sequence of iterates, the errors ei, and the relevant error ratio, ei+1/ei2 or ei+1/ei, that converges to a nonzero limit. Match the limit with the expected value of M=f(r)/(2f(r)) or S=(m1)/m, where m is the order of a multiple root. To measure errors, treat the last iterate as the exact root. Please make sure all tables are well-formatted with numbers reported to enough precision. See page 6 of the lecture root3 for details. Note: for a root of multiplicity Newton's method does not converge quadratically, rather ek+1Sek, with S as above. For example, consider f(x)=(x1)4. Then xf(x)/f(x)=x(x1)4/(4(x1)3)=x41(x1). So Newton's method is xk+1=xk41(xk1). This implies xk+11=43(xk1) and so ek+1=43ek. Linear convergence
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
