필터 지우기
필터 지우기

Bisection method in matlab

조회 수: 3 (최근 30일)
Dai Nguyen
Dai Nguyen 2020년 10월 2일
답변: Asad (Mehrzad) Khoddam 2020년 10월 2일
HI I wanna graph the bisection method with the function that I have but Idk how to do it. I also want to Iterate until the relative approximate error falls below 0.01% or the number of iterations exceeds 100. this is what I have so far but for some
this is the code
clc
clear
lc=3; lp=3; w=160;
T= 700;
f=@(d) (w*lc*lp/(d*sqrt(lp^2-d^2)))-T;
xl=input('enter the value for Xl');
xu=input('enter the value for Xu');
xm = (xu + xl) / 2;
if f(xl)*f(xu)>0
xmnew=xl
xunew=xu
%calculate the error
error=abs((xmnew-xm)/xmnew)
else if f(xl)*f(xu)<0
xmnew=xu
xlnew=xl
error=abs((xmnew-xm)/xmnew);
else
fprintf('xm is the root')
end
end
  댓글 수: 3
Dai Nguyen
Dai Nguyen 2020년 10월 2일
I don't really know how to create the loop for the iteration, can you help me?
Dai Nguyen
Dai Nguyen 2020년 10월 2일
is it for i=1:xm in this case

댓글을 달려면 로그인하십시오.

답변 (1개)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 10월 2일
clc
clear
lc=3; lp=3; w=160;
T= 700;
f=@(d) (w*lc*lp/(d*sqrt(lp^2-d^2)))-T;
xl=input('enter the value for Xl ');
xu=input('enter the value for Xu ');
for i=1:100
xm = (xu + xl) / 2;
error=abs(xm-xu)/xm;
if error< 0.01
break;
end
if f(xl)*f(xm)>0
xl = xm;
elseif f(xl)*f(xu)<0
xu = xm;
else
fprintf('%f is the root\n', xm)
break;
end
end

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by