For loop and if loop

2 views (last 30 days)
Dam Tung
Dam Tung on 17 Sep 2020
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

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!