In: Advanced Math
1. The equation 8?2 − 3?? = 0 has three roots. Find:
(i) The first root, which is between -1 and 0, by the bisection method;
(ii) The second root, which is between 1 and 2, by Newton’s method;
(iii) The third root, which is between 3 and 4, by both the bisection method and Newton’s method.
All the answers should be correct to 2 decimal places.
MATLAB Script:
close all
clear
clc
f = @(x) 8*x^2 - 3*exp(x); % f(x)
tol = 0.01; % 2 decimal place accuracy
fprintf('Part
(i)\n-------------------------------------\n')
a = -1; b = 0;
x = bisection(f,a,b,tol);
fprintf('Solution (Using Bisection Method): %.2f\n', x)
fprintf('\nPart
(ii)\n-------------------------------------\n')
x0 = 1.5;
df = @(x) 16*x - 3*exp(x); % f'(x)
x = newton(f,df,x0,tol);
fprintf('Solution (Using Newton''s Method): %.2f\n', x)
fprintf('\nPart
(iii)\n-------------------------------------\n')
a = 3; b = 4;
x = bisection(f,a,b,tol);
fprintf('Solution (Using Bisection Method): %.2f\n', x)
x0 = 3.5;
x = newton(f,df,x0,tol);
fprintf('Solution (Using Newton''s Method): %.2f\n', x)
function p = bisection(f, a, b, tol)
p = nan;
if f(a)*f(b) > 0
fprintf('Error:\tf(a) and f(b) have the same sign.\n')
fprintf('\t\tHence, f(x) does not contain a root in the given
interval.\n')
else
p = a;
while true
p_h = p;
p = (a + b)/2; % Bisection method's root update
if abs(p - p_h) < tol % Termination condition
break
end
if f(a)*f(p) < 0 % Changing the interval
b = p;
else
a = p;
end
end
end
end
function x = newton(f,df,x0,tol)
x = x0;
while true
x_ = x; % Previous approximate root
x = x - f(x)/df(x);
if abs(x_ - x) < tol % Termination condition
break;
end
end
end
Output:
Part (i)
-------------------------------------
Solution (Using Bisection Method): -0.48
Part (ii)
-------------------------------------
Solution (Using Newton's Method): 1.02
Part (iii)
-------------------------------------
Solution (Using Bisection Method): 3.46
Solution (Using Newton's Method): 3.47