Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

David Fletcher
David Fletcher am 20 Apr. 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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by