Borrar filtros
Borrar filtros

Bisection method in matlab

9 visualizaciones (últimos 30 días)
Dai Nguyen
Dai Nguyen el 2 de Oct. de 2020
Respondida: Asad (Mehrzad) Khoddam el 2 de Oct. de 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 comentarios
Dai Nguyen
Dai Nguyen el 2 de Oct. de 2020
I don't really know how to create the loop for the iteration, can you help me?
Dai Nguyen
Dai Nguyen el 2 de Oct. de 2020
is it for i=1:xm in this case

Iniciar sesión para comentar.

Respuestas (1)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam el 2 de Oct. de 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

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by