Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Problem with iterating loop again if output is less than some fixed value
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I am trying to calculate theta1, theta2 and r using following equations.
N=100;
for j=2:N
t(j)=t(j-1)+dt; %theta1, theta2 and r do not depend on time explicitly.
k=0.95;% input parameter
theta1(j)=theta1(j-1)+dt*k*(sin(theta2(j-1)-theta1(j-1))));
theta2(j)=theta2(j-1)+dt*k*(sin(theta1(j-1)-theta2(j-1))));
r(j)=Equation that depends on theta1 and theta2
At the middle of iteration if the value of r goes below some value say 0.5 then I want to use higher value of k(>0.95) and recalculate from the beginning using same equations given above.
I will be thankful for your help. Dharma
0 Commenti
Risposte (1)
Walter Roberson
il 7 Mar 2018
k = 0.95;
N = 100;
while true
did_all = true;
for j = 2 : N
t(j)=t(j-1)+dt; %theta1, theta2 and r do not depend on time explicitly.
theta1(j)=theta1(j-1)+dt*k*(sin(theta2(j-1)-theta1(j-1))));
theta2(j)=theta2(j-1)+dt*k*(sin(theta1(j-1)-theta2(j-1))));
r(j)=Equation that depends on theta1 and theta2
if r(j) < 0.5;
did_all = false;
break;
end
end
if did_all; break; end
k = k + 0.05;
end
8 Commenti
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!