My program is not stop. I can not stop while command. Please help me.

1 visualización (últimos 30 días)
clear all
clc
RV=0.31869940426982923;
AE=0;
error=10^-2;
k=1;
l=abs(AE-RV)
while l>error
k=k+1;
for i=1:k
a=[2.5-0.2]/k;
x_1=0.2+a*(i-1);
x_2=0.5+a*i;
y_1=sin(2*x_1);
y_2=sin(2*x_2);
if (y_1*y_2)<0
b=abs(x_2-x_1)/2*[abs(y_1)*y_1/(y_1+y_2)+abs(y_2)*y_2/(y_1+y_2)];
else
b=abs(x_2*x_1)*(y_1+y_2)/2;
end
AE=AE+b;
end
end
k

Respuesta aceptada

David Fletcher
David Fletcher el 20 de Abr. de 2021
Couldn't see too well as your code is a bit of a wall of text, but does l ever get updated in your loop? If not then if the expression was true at the start, then it will always be true and the loop won't end

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by