0% found this document useful (0 votes)
32 views5 pages

Assignment 3 Open Method

The document describes numerical methods for finding the highest real root of the function f(x) = 2x^3 - 11.7x^2 + 17.7x - 2. It provides the implementation of fixed-point iteration, Newton-Raphson, and secant methods in MATLAB to calculate the root over 3 iterations starting from initial guesses of x0 = 3, x0 = 3, and x-1 = 3, x0 = 4 respectively. Tables and plots of the results are displayed.

Uploaded by

Paolo Valdez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views5 pages

Assignment 3 Open Method

The document describes numerical methods for finding the highest real root of the function f(x) = 2x^3 - 11.7x^2 + 17.7x - 2. It provides the implementation of fixed-point iteration, Newton-Raphson, and secant methods in MATLAB to calculate the root over 3 iterations starting from initial guesses of x0 = 3, x0 = 3, and x-1 = 3, x0 = 4 respectively. Tables and plots of the results are displayed.

Uploaded by

Paolo Valdez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: PAOLO P.

VALDEZ Date: July 10, 2023


Course Code & Subject: CEM 602 – NUMERICAL METHODS FOR ENGINEERS

ROOTS OF EQUATION (OPEN METHOD)


Fixed-Point Method
Given:

Determine the highest real root of

3 2
f ( x)=2 x −11.7 x +17.7 x−2
Fixed-point iteration method (three iterations, x 0=3 ). Note: Make certain that you develop a solution that converges on
the root.
(c) Newton-Raphson method (three iterations, x 0=3 ).

(d) Secant method (three iterations, x−1=3 , x 0=4).

(e) Modified secant method (three iterations, x 0=3 , δ=0.01). Compute the approximate percent relative errors for your
solutions.
Solution Using Matlab:

% Function definition: f(x) = 2x^3 - 11.7x^2 end


+ 17.7x - 2
f = @(x) 2*x^3 - 11.7*x^2 + 17.7*x - 2; % Display the results in a table
fprintf('Fixed-Point Iteration Method\n');
% Define the fixed-point iteration function fprintf('Iteration | x_n | x_{n+1} |
g(x) Approx. Error\n');
g = @(x) 2 / (2*x^2 - 11.7*x + 17.7); fprintf('------------------------------------
--------\n');
% Initial guess for i = 1:numIterations
x0 = 3; fprintf('%5d | %.6f | %.6f | %.6f\n',
i, x_values(i), x_values(i + 1),
% Number of iterations approx_errors(i));
numIterations = 3; end

% Initialize arrays to store iteration % Plot the convergence


results iterations = 1:numIterations;
x_values = zeros(numIterations + 1, 1); plot(iterations, x_values(1:numIterations),
approx_errors = zeros(numIterations, 1); '-o', 'LineWidth', 2);
xlabel('Iteration');
% Perform fixed-point iteration ylabel('x_n');
x_values(1) = x0; title('Fixed-Point Iteration Convergence');
for i = 1:numIterations grid on;
x_values(i + 1) = g(x_values(i));
approx_errors(i) = abs(x_values(i + 1) -
x_values(i));
ROOTS OF EQUATION (OPEN METHOD)
Newton-Raphson Method
Given:

Determine the highest real root of

3 2
f (x)=2 x −11.7 x +17.7 x−2

Newton-Raphson method (three iterations, x 0=3 ).


Solution in Matlab:
% Define the function disp(['The highest real root is
f = @(x) 2*x^3 - 11.7*x^2 + 17.7*x - 2; approximately: '
num2str(highest_real_root)]);
% Define the derivative of the function
df = @(x) 6*x^2 - 23.4*x + 17.7; % Plot the function
x_vals = linspace(-10, 10, 100);
% Perform Newton-Raphson iterations y_vals = arrayfun(f, x_vals);
x0 = 3; % Initial guess plot(x_vals, y_vals, 'b-', 'LineWidth', 1.5);
x = zeros(1, 4); % Initialize array to store hold on;
iteration values grid on;
x(1) = x0; % Store initial guess as the xlabel('x');
first value ylabel('f(x)');
for iter = 1:3 title('Plot of f(x)');
x(iter+1) = x(iter) - plot(highest_real_root, f(highest_real_root),
f(x(iter))/df(x(iter)); 'ro', 'MarkerSize', 8, 'LineWidth', 1.5);
end legend('f(x)', 'Highest Real Root');

% Display the highest real root % Create a table of iterations


highest_real_root = x(end); iterations = [0:3; x];
table(iterations(1, :)', iterations(2, :)',
'VariableNames', {'Iteration', 'x'})
ROOTS OF EQUATION (OPEN METHOD)
Secant Method
Given:

Determine the highest real root of

3 2
f ( x)=2 x −11.7 x +17.7 x−2
Secant method (three iterations, x−1=3 , x 0=4).

Solution Using Matlab:

% Define the function f(x) table_secant = table(x_secant,


f = @(x) 2*x^3 - 11.7*x^2 + 17.7*x - 2; 'VariableNames', {'Root (Secant Method)'});

% Secant method % Display the table


x_minus1 = 3; disp('Secant Method:');
x0 = 4; disp(table_secant);
iterations_secant = 3;
x_secant = zeros(iterations_secant, 1); % Plot the iterations
figure;
% Perform iterations for secant method plot(1:iterations_secant, x_secant, 'ro-',
for i = 1:iterations_secant 'LineWidth', 1.5);
x1 = x0 - (f(x0) * (x0 - x_minus1)) / xlabel('Iterations');
(f(x0) - f(x_minus1)); ylabel('Root');
x_secant(i) = x1; title('Secant Method Iterations');
x_minus1 = x0; grid on;
x0 = x1;
end % Highlight the highest real root
hold on;
% Calculate the highest real root plot(iterations_secant, highest_real_root,
highest_real_root = max(x_secant); 'b*', 'LineWidth', 2);
legend('Root', 'Highest Real Root');
% Create a table

You might also like