My program is not stop. I can not stop while command. Please help me.
2 次查看(过去 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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!