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

1 次查看(过去 30 天)
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

采纳的回答

David Fletcher
David Fletcher 2021-4-20
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by