Root of functions by Bisection method

It obtains the root of a function
38 téléchargements
Mise à jour 1 fév. 2017

Afficher la licence

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

Citation pour cette source

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. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2015a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur MATLAB Data API for C++ dans Help Center et MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version
1.0.0.0