Root of functions by Bisection method

버전 1.0.0.0 (1.17 KB) 작성자: carolina franco
It obtains the root of a function
다운로드 수: 38
업데이트 날짜: 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