Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function myNewtonBasin1D.m with the following definition function [x, fl

ID: 3727727 • Letter: W

Question

Write a function myNewtonBasin1D.m with the following definition function [x, flag, z] = NewtonMethodID(f, df, x0, tol, max!ter) where ·f, df are the function we are looking for the roots of and its derivative respectively ·x0 is an initial approximation tol is a desired level of tolerance for approximating a root and maxIter is the maximum number of iterations of Newton's method You can choose any suitable stopping criteria for your Newton steps. Your results might differ slightly depending on the stopping criterion used but should not be fundamentally different The function should return ·x, an approximation to a root, if the Newton method iterations converge; or an empty variable, if the Newton method doesn't converge and flag that is either 1 if the method converges or 0 if it does not converge or there are other issues

Explanation / Answer

Matlab code :

x =x0;

xOld = x0;

flag=0;

z=[];

for i=1:maxIter

z(i) = xOld;

x = x-(f./df);

err = abs(x-xOld);

xOld =x

flag=1;

if(err < tol)

break;

end

end

end

non-linear equation:

Given Equation fx = x^3-6*x^2+11*x-6=0=>Diff equation for fx is df = 3*x^2 -12*x +11 =0

Given tol = 10^(-12) , maxIter = 10,range : 0:0.1:4

fx = x^3-6*x^2+11*x-6; =>df = 3*x^2 -12*x +11;

tol = 10^(-12) ;

maxIter = 10; ,range =0:0.1:4;

x0=0;   , [x, flag,z] = newtonMethod1D(fx,df,x0,tol,maxIter);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote