Bisection method in matlab

9 ビュー (過去 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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by