Info
此问题已关闭。 请重新打开它进行编辑或回答。
Problem with iterating loop again if output is less than some fixed value
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2018-3-7
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
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!