error in code

1 view (last 30 days)
John
John on 28 Feb 2012
I have this code:
h=1;
a1=linspace(0,0,100);
a2=linspace(0.8,0.8,100);
a3=linspace(-0.8,-0.8,80);
a4=linspace(0,0,120);
kat=[a1 a2 a3 a4];
x=[0.5 0.2 0.5];
k=[linspace(0,0,400);linspace(0,0,400)];
for i=1:1:400
k(i+1;:)=k(i;:)+h*F_tanker(x,kat(i)) ;
end
and when i try tu run it error occurs: Line: 11 Column: 6 Incomplete or misformed expression or statement.

Answers (3)

Jiro Doke
Jiro Doke on 28 Feb 2012
Read this line carefully:
k(i+1;:)=k(i;:)+h*F_tanker(x,kat(i)) ;
You have a couple of extra ; in the line.
  1 Comment
Srinivas
Srinivas on 28 Feb 2012
and then make sure you define
'F_tanker'

Sign in to comment.


John
John on 28 Feb 2012
Can you be more specific which one of ; i shoul remove? I can't see one. F_tanker looks like this:
function [dx]=F_tanker(x,delta);
ell=350; % Length of the ship (in meters)
u=5; % Nominal speed (in meters/sec)
% The parameters for the tanker under "ballast" conditions
% (a heavy ship) are:
% K_0=5.88;
% tau_10=-16.91;
% tau_20=0.45;
% tau_30=1.43;
% The parameters for the tanker under "full" conditions (a ship
% that weighs less than one under "ballast" conditions) are:
K_0=0.83;
tau_10=-2.88;
tau_20=0.38;
tau_30=1.07;
abar=1; % Parameters for nonlinearity
bbar=1;
K=K_0*(u/ell);
tau_1=tau_10*(ell/u);
tau_2=tau_20*(ell/u);
tau_3=tau_30*(ell/u);
dx= [ x(2) ;
x(3)+ (K*tau_3/(tau_1*tau_2))*delta;
-((1/tau_1)+(1/tau_2))*(x(3)+ (K*tau_3/(tau_1*tau_2))*delta)-...
(1/(tau_1*tau_2))*(abar*x(2)^3 + bbar*x(2)) + (K/(tau_1*tau_2))*delta];

Srinivas
Srinivas on 28 Feb 2012
this line
k(i+1;:)=k(i;:)+h*F_tanker(x,kat(i)) ;
should be
k(i+1,:)=k(i,:)+h*F_tanker(x,kat(i)) ;

Categories

Find more on Automotive 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!