0% found this document useful (0 votes)
26 views2 pages

Modified False

The document describes a MATLAB function called 'modified_false_position' that implements the Modified False Position Method to find the root of a given function within a specified interval. It includes input parameters for the function, interval bounds, tolerance, and maximum iterations, as well as error handling for cases where the function does not bracket a root. An example usage of the function is also provided, demonstrating how to define a function and call the root-finding method.

Uploaded by

wonwoong5
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)
26 views2 pages

Modified False

The document describes a MATLAB function called 'modified_false_position' that implements the Modified False Position Method to find the root of a given function within a specified interval. It includes input parameters for the function, interval bounds, tolerance, and maximum iterations, as well as error handling for cases where the function does not bracket a root. An example usage of the function is also provided, demonstrating how to define a function and call the root-finding method.

Uploaded by

wonwoong5
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/ 2

[Modified False-position]

function [root, iterations] = modified_false_position(f, a, b, tol, max_iter)


% Function to find the root of f(x) using Modified False Position Method
% Inputs:
% f: function handle (e.g., @(x) x^10 - 1)
% a: lower bound of interval
% b: upper bound of interval
% tol: tolerance for convergence
% max_iter: maximum number of iterations
% Outputs:
% root: estimated root
% iterations: number of iterations performed

% Initialize variables
fa = f(a);
fb = f(b);

if fa * fb > 0
error('The function must have opposite signs at a and b.');
end

il = 0; % Counter for lower bound being retained


iu = 0; % Counter for upper bound being retained

for iter = 1:max_iter


% Compute new approximation of root using Modified False Position formula
xr = b - fb * (b - a) / (fb - fa);
fr = f(xr);

% Check convergence criteria


if abs(fr) < tol || abs(b - a) < tol
root = xr;
iterations = iter;
return;
end

% Update bounds based on signs of function values


if fa * fr < 0
b = xr;
fb = fr;
iu = 0; % Reset upper bound counter
il = il + 1; % Increment lower bound counter

if il >= 2
fa = fa / 2; % Halve the value at lower bound to improve convergence
end

elseif fb * fr < 0
a = xr;
fa = fr;
il = 0; % Reset lower bound counter
iu = iu + 1; % Increment upper bound counter

if iu >= 2
fb = fb / 2; % Halve the value at upper bound to improve convergence
end

else
error('Unexpected behavior: function values do not bracket the root.');
end

fprintf('Iteration %d: xr = %.6f, f(xr) = %.6f\n', iter, xr, fr);


end

error('Maximum number of iterations reached without convergence.');


end

% Example usage:
f = @(x) x^10 - 1; % Define the function
a = 0; % Lower bound of interval
b = 1.3; % Upper bound of interval
tol = 1e-4; % Tolerance for convergence
max_iter = 100; % Maximum number of iterations

[root, iterations] = modified_false_position(f, a, b, tol, max_iter);

fprintf('Root found: %.6f after %d iterations\n', root, iterations);

You might also like