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

The equation f(x) = x^2 -5x^1/3 + 1 = 0 has a root between x = 2 and x = 2.5. Wr

ID: 3789159 • Letter: T

Question

The equation f(x) = x^2 -5x^1/3 + 1 = 0 has a root between x = 2 and x = 2.5. Write a MATLAB program to solve this problem with the Newton's method until the approximate percent relative error epsilon variant_a reaches below epsilon variant_a = 10^-6 %. Calculate and print epsilon variant_a at each iteration. Compare epsilon variant_a at each iteration with epsilon variant_a from the fixed-point iteration method (from your HW2). Present your results in the form of a table. Discuss which method converges faster.

Explanation / Answer

Matlab script using Newton's method for finding the root

% Newtons method to find the root of a function f(x) = x^2-5x^(1/3)+1
f = @(x) x.^2-5*nthroot(x,3)+1; % The function f
df = @(x) 2*x-5/(3*nthroot(x.^2,3)); % the derivative of f
tol = 10^-6; % tolerence
N_max = 100; % Maximum number of allowed iterations
x = 2; % initial guess of the root
N = 0; % iteration variable
y = f(x); % function value at x0
dy = df(x); % function derivative at x0
% Printing the results in table format
disp('___________________________________________________')
disp(' iter      x            error')
disp('___________________________________________________')
while (abs(y)>tol)&&(N<=N_max)&&(dy~=0)
    x=x-y/dy; % finding xn+1
    y = f(x); % function value at xn+1
    dy = df(x);%function derivative at xn+1
    N = N+1;% Increasing number of iteration
    fprintf('%2.0f %12.6f %12.6f ',N,x,y); % Result
end
if (dy==0) % Checking devision by zero
   disp(' division by zero')  
end
if (N>N_max) % Checking the convergence of the method
   disp(' Method failed to converge')
end

OUTPUT

>> newtons_method_root
___________________________________________________
iter      x            error
___________________________________________________
1      2.440534      0.224401
2      2.383891      0.003617
3      2.382947      0.000001
4      2.382947      0.000000

Matlab script using fixed point method for finding the root

g = @(x) sqrt(5*nthroot(x,3)-1);
tol = 10^-6; % tolerence
x0 = 2; % initial guess of the root
N = 1; % iteration variable
N_max = 100; % Maximum number of allowed iterations
x = g(x0); % Evaluating g at x0
% Printing the results in table format
disp('__________________________________________')
disp(' iter      x            error')
disp('__________________________________________')
fprintf('%2.0f %12.6f %12.6f ',N,x,abs(x0-x)); % Result
while((abs(x0-x)> tol)&&(N<=N_max))
    x0 = x;% copy the value of new x to old x
    x = g(x0);% Evaluating g at x0
    N =N+1; % increaseing the number of iterations
    fprintf('%2.0f %12.6f %12.6f ',N,x,abs(x0-x)); % Result
end

OUTPUT

>> fixed_pt_mthd
__________________________________________
iter      x            error
__________________________________________
1      2.302087      0.302087
2      2.366860      0.064773
3      2.379784      0.012924
4      2.382327      0.002542
5      2.382825      0.000499
6      2.382923      0.000098
7      2.382942      0.000019
8      2.382946      0.000004
9      2.382947      0.000001

Newton's method converges fastely

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