false position method then the Newton-Raphson method

10 views (last 30 days)
Determine the intersection of the two following equations:
g (s) = s 6
h(s) = s + 1
using the false position method and then the Newton-Raphson method. By using the range of [1, 1.5], perform calculation until it converges. Also, at each iteration, calculate the approximate and actual errors if the actual solution is s = 1.13472.

Answers (1)

arushi
arushi on 5 Sep 2024
Hi Ahmed,
False Position Method
The False Position method is a root-finding algorithm that combines the bisection method's bracketing strategy with linear interpolation.
function false_position()
% Given actual solution
actual_solution = 1.13472;
% Define the function
f = @(s) s^6 - (s + 1);
% Initial bracket
a = 1;
b = 1.5;
% Tolerance
tol = 1e-5;
max_iter = 100;
% Initial values
fa = f(a);
fb = f(b);
if fa * fb > 0
error('Function does not change sign in the interval');
end
for iter = 1:max_iter
% Calculate the false position
c = (a * fb - b * fa) / (fb - fa);
fc = f(c);
% Calculate errors
approx_error = abs((b - a) / 2);
actual_error = abs(actual_solution - c);
% Display iteration results
fprintf('Iteration %d: c = %.5f, Approx. Error = %.5f, Actual Error = %.5f\n', iter, c, approx_error, actual_error);
% Check convergence
if abs(fc) < tol
break;
end
% Update the bracket
if fa * fc < 0
b = c;
fb = fc;
else
a = c;
fa = fc;
end
end
end
% Run the false position method
false_position();
Newton-Raphson Method
The Newton-Raphson method is an iterative root-finding technique using the derivative of the function.
function newton_raphson()
% Given actual solution
actual_solution = 1.13472;
% Define the function and its derivative
f = @(s) s^6 - (s + 1);
df = @(s) 6 * s^5 - 1;
% Initial guess
s = 1.25;
% Tolerance
tol = 1e-5;
max_iter = 100;
for iter = 1:max_iter
% Calculate the next approximation
s_new = s - f(s) / df(s);
% Calculate errors
approx_error = abs(s_new - s);
actual_error = abs(actual_solution - s_new);
% Display iteration results
fprintf('Iteration %d: s = %.5f, Approx. Error = %.5f, Actual Error = %.5f\n', iter, s_new, approx_error, actual_error);
% Check convergence
if approx_error < tol
break;
end
% Update the guess
s = s_new;
end
end
% Run the Newton-Raphson method
newton_raphson();
Both methods will display the approximate and actual errors at each iteration, allowing you to observe the convergence process. Adjust the tolerance and maximum iterations as needed for your specific requirements.
Hope this helps.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!