For loop and if loop
2 次查看(过去 30 天)
显示 更早的评论
Hi, every one.
I have a problem of simulating the operation of a ship, in which I have used loops "For and if" for solving. I wrote in matlab and obtained results but Result is not correct. I think i did mistake with these loop. Please fix me the following code. In the picture show the scheme of this model. Many thanks
clear all;
clc;
R=300;
v=11;
zt=33;
P=77;
Q=0;
Q2=0;
q=4;
hpr=2;
hw=[1.5 1.8 2.2 2.3 2 2.3 2.4 2.5 2.7 3 1.8 1.5 1.5 1.8 2.2 2.3 2.1 2.3 2.4 2.5 2.7 3 1.8 1.5 1.5 1.8 2.2 2.3 2.1 2.3 2.4 2.5 2.7 3 1.8 1.5...
1.5 1.8 2.2 2.3 2.1 2.3 2.4 2.5 2.7 3 1.8 1.5 1.5 1.8 2.2 2.3 2.1 2.3 2.4 2.5 2.7 3 1.8 1];
t=0;
tper=R*1.6/(v*1.82)*1.1/24
tst=2;
for i=1:60
if hw(i)<hpr
t2=0
Q=q+Q
z=(i+tper)*2
else
t2=tst
Q=q+Q
z=(i+tper)*2
if (z/zt<1.1) || Q>P
t=i+tper+tper+t2
if t>30
Q1=Q
break;
end
end
end
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!