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

Numerical methods (matlab) Q1 The goal is to find the root of 0.3 x /3 1.4 using

ID: 3800370 • Letter: N

Question

Numerical methods (matlab)


Q1 The goal is to find the root of 0.3 x /3 1.4 using the fixed-point method 1/3 1.4 (a) As a potential iteration function, select g (x)J Graphically locate the fixed point of gl(x). 0.3x Execute the user-defined function FixedPoint (Section 3.4) twice, once with initial point chosen as the integer nearest the fixed point on its left, and a second time with the nearest integer on its right. Use default values for kmax and tol, but increase kmax if necessary. Fully discuss convergence issues as related to Theorem 3.1. (b) Next, as the iteration function select g20-(0.3 -14' and repeat all steps in Part a).

Explanation / Answer

The function fixed_point.m

function [x,N] = fixed_point(g,x0,tol,kmax)
   N = 1; % iteration variable
   x = g(x0); % Evaluating g at x0
   while((abs(x0-x)> tol)&&(N<=kmax))
    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
   end
   N= N-1;
end

Testing the function part a) and part b)

g = @(x) 0.3*x.^2-(nthroot(x,3))-1.4; % The function g
g1 = @(x) (nthroot(x,3)+1.4)./(0.3*x); % The function g1
g2 = @(x) (0.3*x.^2-1.4).^3; % the function g2
x = -3:0.1:5; % X vector for the plot
plot(x,g(x),[-3 5],[0 0]); % plotting thye function g to graphicallyt locate
tol = 10^-5; % tolerence
kmax = 100; % Max iterations
x0 = 2; % left point
[x,N] = fixed_point(g1,x0,tol,kmax);
fprintf(' Root = %f for x0 = %f Number of iterations %d ',x,x0,N);
x0 = 4; % Right point
[x,N] = fixed_point(g1,x0,tol,kmax);
fprintf(' Root = %f for x0 = %f number of iterations %d ',x,x0,N);
x0 = -4; % left point
[x,N] = fixed_point(g2,x0,tol,kmax);
fprintf(' Root = %f for x0 = %f Number of iterations %d ',x,x0,N);
x0 = -1; % Right point
[x,N] = fixed_point(g2,x0,tol,kmax);
fprintf(' Root = %f for x0 = %f Number of iterations %d ',x,x0,N);

OUTPUT

>> fixed_point_test
Root = 3.085336 for x0 = 2.000000 Number of iterations 67
Root = 3.085336 for x0 = 4.000000 number of iterations 64
Root = Inf for x0 = -4.000000 Number of iterations 5
Root = -2.743999 for x0 = -1.000000 Number of iterations 100

Remarks

g2 is faild to converge to the root

Not in problem just Testing the code using fzero() fun

x0 = fzero(g,3); % the zero point
[x,N] = fixed_point(g2,x0,tol,kmax);
fprintf(' Root = %f for x0 = %f Number of iterations %d ',x,x0,N);

x0 = fzero(g,3)+0.1; % Right point
[x,N] = fixed_point(g2,x0,tol,kmax);
fprintf(' Root = %f for x0 = %f Number of iterations %d ',x,x0,N);

x0 = fzero(g,3)-0.1; % left point
[x,N] = fixed_point(g2,x0,tol,kmax);
fprintf(' Root = %f for x0 = %f Number of iterations %d ',x,x0,N);

OUTPUT

Root = 3.085340 for x0 = 3.085340 Number of iterations 0

Root = Inf for x0 = 3.185340 Number of iterations 5

Root = -2.095148 for x0 = 2.985340 Number of iterations 100