My program is not stop. I can not stop while command. Please help me.
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Zeki Baran Bingöl
il 20 Apr 2021
Risposto: David Fletcher
il 20 Apr 2021
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 Commenti
Risposta accettata
David Fletcher
il 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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!