In: Advanced Math
Consider the root of function f(x) = x 3 − 2x − 5. The function can be rearranged in the form x = g(x) in the following three ways: (a) x = g(x) = x3 − x − 5 (b) x = g(x) = (x 3 − 5)/2 (c) x = g(x) = thirdroot(2x + 5) For each form, apply fixed-point method with an initial guess x0 = 0.5 to approximate the root. Use the error tolerance = 10-5 to terminate the iteration. If the iteration does not converge within 15 steps, stop and provide an explanation for the divergence. Keep at least 6 significant digits in your calculation.
a)
clc;
clear all;
format long
% Given f(x)=(sin(x)/2)+1/2-x, we rewrire (sin(x)/2)+1/2=x
g=@(x)x^3-2*x-5; %function
x1=0.5;%initial value
tol=1e-5; % tolerence (Stoping)
erorr=0.1;
n=1;
max_iter=15;
disp('_____________________________________________________________________________________')
disp('n x(n)) g(x(n)) error')
disp('_____________________________________________________________________________________')
while(erorr>tol&n<max_iter)
x1(n+1)=g(x1(n));
%x=x1;
erorr(n)=abs(x1(n)-x1(n+1));
fprintf('%d\t%15.8f \t %15.8f \t %15.8f \n',n
,x1(n),g(x1(n)),erorr(n))
n=n+1;
end
disp('Root of function is')
y=x1(end)
disp('Number of iteration')
n-1
%%%%%%%%%%%%%%%%%%%%%
_____________________________________________________________________________________
n x(n)) g(x(n)) error
_____________________________________________________________________________________
1 0.50000000 -5.87500000
6.37500000
2 -5.87500000 -196.02929688
190.15429688
3 -196.02929688 -7532525.85236584
7532329.82306897
4 -7532525.85236584
-427387575445953770000.00000000
427387575445946240000.00000000
5 -427387575445953770000.00000000
-78066674213739856000000000000000000000000000000000000000000000.00000000
78066674213739856000000000000000000000000000000000000000000000.00000000
6
-78066674213739856000000000000000000000000000000000000000000000.00000000
-475769978281058810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000
475769978281058810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000
7
-475769978281058810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000
-Inf Inf
8 -Inf NaN NaN
Root of function is
y =
NaN
Number of iteration
ans =
8
>>
b)
clc;
clear all;
format long
% Given f(x)=(sin(x)/2)+1/2-x, we rewrire (sin(x)/2)+1/2=x
g=@(x)(x^3-5)/2; %function
x1=0.5;%initial value
tol=1e-5; % tolerence (Stoping)
erorr=0.1;
n=1;
max_iter=15;
disp('_____________________________________________________________________________________')
disp('n x(n)) g(x(n)) error')
disp('_____________________________________________________________________________________')
while(erorr>tol&n<max_iter)
x1(n+1)=g(x1(n));
%x=x1;
erorr(n)=abs(x1(n)-x1(n+1));
fprintf('%d\t%15.8f \t %15.8f \t %15.8f \n',n
,x1(n),g(x1(n)),erorr(n))
n=n+1;
end
disp('Root of function is')
y=x1(end)
disp('Number of iteration')
n-1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
_____________________________________________________________________________________
n x(n)) g(x(n)) error
_____________________________________________________________________________________
1 0.50000000 -2.43750000
2.93750000
2 -2.43750000 -9.74108887
7.30358887
3 -9.74108887 -464.66017665
454.91908778
4 -464.66017665 -50162178.07116126
50161713.41098461
5 -50162178.07116126
-63110142529143789000000.00000000
63110142529143738000000.00000000
6 -63110142529143789000000.00000000
-125680380630448420000000000000000000000000000000000000000000000000000.00000000
125680380630448420000000000000000000000000000000000000000000000000000.00000000
7
-125680380630448420000000000000000000000000000000000000000000000000000.00000000
-992595875594217240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000
992595875594217240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000
8
-992595875594217240000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.00000000
-Inf Inf
9 -Inf -Inf NaN
Root of function is
y =
-Inf
Number of iteration
ans =
9
>>
c)
clc;
clear all;
format long
% Given f(x)=(sin(x)/2)+1/2-x, we rewrire (sin(x)/2)+1/2=x
g=@(x)(2*x+5)^(1/3); %function
x1=0.5;%initial value
tol=1e-5; % tolerence (Stoping)
erorr=0.1;
n=1;
max_iter=15;
disp('_____________________________________________________________________________________')
disp('n x(n)) g(x(n)) error')
disp('_____________________________________________________________________________________')
while(erorr>tol&n<max_iter)
x1(n+1)=g(x1(n));
%x=x1;
erorr(n)=abs(x1(n)-x1(n+1));
fprintf('%d\t%15.8f \t %15.8f \t %15.8f \n',n
,x1(n),g(x1(n)),erorr(n))
n=n+1;
end
disp('Root of function is')
y=x1(end)
disp('Number of iteration')
n-1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
_____________________________________________________________________________________
n x(n)) g(x(n)) error
_____________________________________________________________________________________
1 0.50000000 1.81712059
1.31712059
2 1.81712059 2.05151513
0.23439454
3 2.05151513 2.08799119
0.03647606
4 2.08799119 2.09355411
0.00556292
5 2.09355411 2.09439991
0.00084580
6 2.09439991 2.09452845
0.00012854
7 2.09452845 2.09454798
0.00001953
8 2.09454798 2.09455095
0.00000297
Root of function is
y =
2.094550949678837
Number of iteration
ans =
8
>>