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

Consider below equation: x = e^-t (t^2 + 5t + 2) There exist two roots for this

ID: 3818634 • Letter: C

Question

Consider below equation: x = e^-t (t^2 + 5t + 2) There exist two roots for this equation. Plot this equation in MATLAB for-5 lessthanorequalto t lessthanorequalto 0 with step size of 0.001 to see those roots. Obtain the smaller root of the equation with initial guess of -5 as requested below: a. Write a script, named "NAME_SURNAME_A" to calculate the root using Bisection method till relative error is less than 0.0005 and plot the convergence history (Relative error vs. Iteration number). For this part you need to select the second initial guess by yourself according to graph. b. Write a script, named "NAME_SURNAME_B" to calculate the root using Fixed-Point iteration method till relative error is less than 0.0005 and plot the convergence history. c. Write a script, named "NAME_SURNAME_C" to calculate the root using Newton-Raphson method till relative error is less than 0.0005 and plot the convergence history. d. Compare the convergence of three methods.

Explanation / Answer

% bisection method
function res = RootBisection(f,a,b)
   if f(a)*f(b)>0
       disp('taken wrong choice')
   else
       res = (a + b)/2;
       err = abs(f(res));
       while err > 1e-7
   if f(a)*f(res)<0
       b = res;
   else
       a = res;
   end
       res = (a + b)/2;
   err = abs(f(res));
       end
   end
end

% fixed point iteration
function res = fixedPointIteration(f,a, N)
   i = 1;
   m(1) = a;
   tolerance = 1e-05;
   while i <= N
   m(i+1) = f(m(i));
   if abs(m(i+1)-m(i)) < tolerance       %checking tolerance to stop
       k = i
       m(i+1)
       return
   end
   i = i+1;
   end
   res = m(i);  
end

%-------- newton raphson
function res = mynewton(f,a,N)
   z = f(x);
   diffVal = diff(z); %finding initial derivative
   p = a; % initializing initial root

   for idx = 1 : N
       numerator = subs(z,x,p); %munerator
       denominator = subs(diffVal,x,p); % denominator
       p = p - double(numerator)/double(denominator); % calculating and casting to double
   end
   res = p; %printing output
end
%-------------- calling function -------------------------------------------------------------------------------------
f=@(t) (e.^-t) *(t.^2+5*t+2)
a=-5;
b=0;
output1 = RootBisection(f,a,b);
output2 = fixedPointIteration(f,a,10);
output3 = mynewton(f,a,10);
%------------------------------------------------------------------------------------------------------------------------