Filter löschen
Filter löschen

Bisection method in matlab

9 Ansichten (letzte 30 Tage)
Dai Nguyen
Dai Nguyen am 2 Okt. 2020
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 Kommentare
Dai Nguyen
Dai Nguyen am 2 Okt. 2020
I don't really know how to create the loop for the iteration, can you help me?
Dai Nguyen
Dai Nguyen am 2 Okt. 2020
is it for i=1:xm in this case

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam am 2 Okt. 2020
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

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by