Root of functions by Bisection method

版本 1.0.0.0 (1.2 KB) 作者: carolina franco
It obtains the root of a function
39.0 次下载
更新时间 2017/2/1

查看许可证

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

引用格式

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. 检索时间: .

MATLAB 版本兼容性
创建方式 R2015a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 MATLAB Data API for C++ 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0