In: Advanced Math
The function given possesses real roots:
x^3 – 1.7x^2 + 0.84x – 0·108
Using a precision of 1% of a root, find the estimates of all roots using the secant method. After finding a root, reduce the polynomial using polynomial reduction before finding the next root with the secant method.
PLEASE USE MATLAB
MATLAB Script:
close all
clear
clc
syms x
tol = 1e-2; % Error tolerance
f = x^3 - 1.7*x^2 + 0.84*x - 0.108; % Given function f(x)
% Plot the function to get initial estimates of the roots
x_vals = 0:0.001:1; % Range [0, 1] with step size of 0.001
f_vals = subs(f, x_vals); % Evaluate f(x) at x = x_vals
plot(x_vals, f_vals), grid on % Plot f(x) and turn on the
gridlines
xlabel('x'), ylabel('f(x)') % Label the axes
title('f(x) = x^3 - 1.7x^2 + 0.84x - 0.108') % Add a title
fprintf('Roots:\n')
% Secant method (first root)
x0 = 0; x1 = 0.25;
result = secant(f, x0, x1, tol);
fprintf(' x = %.2f\n', result)
% Polynomial reduction
[~, q] = polynomialReduce(f, x - result);
f = q; % New f(x)
% Secant method (second root)
x0 = 0.25; x1 = 0.75;
result = secant(f, x0, x1, tol);
fprintf(' x = %.2f\n', result)
% Polynomial reduction
[~, q] = polynomialReduce(f, x - result);
f = q; % New f(x)
% Secant method (third root)
x0 = 0.75; x1 = 1;
result = secant(f, x0, x1, tol);
fprintf(' x = %.2f\n', result)
function x = secant(f, a, b, tol)
x = [a b];
while true
xl = x(end-1); xu = x(end);
y = ( xl*subs(f, xu) - xu*subs(f, xl) ) / (subs(f, xu) - subs(f,
xl)); % Secant method's root update
x = [x y];
if abs(x(end-1) - x(end)) < tol % Termination condition
break
end
end
x = x(end);
end
Plot:
Output:
Roots:
x = 0.20
x = 0.60
x = 0.90