0% found this document useful (0 votes)
3 views1 page

Bisection Method Root Finding Code

Uploaded by

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

Bisection Method Root Finding Code

Uploaded by

shahedhossin326
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

% Root finding using bisection method

f = @(m) sqrt((9.81 * m)/0.25) * tanh(4 * sqrt((9.81 * 0.25)/m)) - 36;

% Initial guesses for the root

left = 1;

right = 500;

% Ensure the function changes sign in the interval

if f(left) * f(right) > 0

error('Function has same sign at both ends. Pick a different interval.');

end

% Set error threshold

eps = 1e-4;

count = 0;

% Begin iterative process

while abs(left - right) > eps

guess = (left + right) / 2;

val = f(guess);

if val == 0

break;

elseif f(left) * val < 0

right = guess;

else

left = guess;

end

count = count + 1;

end

% Show the result

fprintf('Root %.5f found after %d steps\n', guess, count);

You might also like