Root of functions by Bisection method
clc, clear, close all
% f is the function to be used
disp('Obtening the root of the function Y=X^3-2');
ao= input('Enter the first possible limit: ');
bo= input('Enter the second possible limit: ');
Y1=f(ao);
Y2=f(bo);
Uo=(ao+bo)/2;
Yo=f(Uo);
zo=Y1*Y2;
iter=0;
tic()
while abs(Yo)>0.0001
iter=iter+1;
if zo>0
if abs(Y1)> abs(Y2)
Uo=bo;
else
Uo=ao;
end
Yo=f(Uo);
Y2=Yo;
if Y2<0
U1= Uo+abs(Uo)*100*rand(1);
Y1=f(U1);
else
U1= Uo-abs(Uo)*100*rand(1);
Y1=f(U1);
end
zo=Y1*Y2;
U=(U1+Uo)/2;
Yo=f(U);
else
if abs(Y1)> abs(Y2)
ao=bo;
else
end
Uo=(ao+Uo)/2;
ao=Uo;
Yo=f(Uo);
Y2=f(Uo);
Y1=Yo;
zo=Y1*Y2;
Uo=(ao+Uo)/2;
end
end
y=toc;
disp(['The root of the function Y=X^3-2 is approximately: ', num2str(U,6)]);
disp(['Checking the Y value: ', num2str(Yo,6)]);
disp(['The number of iteration was: ', num2str(iter)]);
disp(['Duration of the process: ', num2str(y)]);
% f function from here
function y=f(a)
y=a.^3-2;
end
Cite As
carolina franco (2024). Root of functions by Bisection method (https://www.mathworks.com/matlabcentral/fileexchange/61385-root-of-functions-by-bisection-method), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |