error in code

1 次查看(过去 30 天)
John
John 2012-2-28
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.

回答(3 个)

Jiro Doke
Jiro Doke 2012-2-28
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 个评论
Srinivas
Srinivas 2012-2-28
and then make sure you define
'F_tanker'

请先登录,再进行评论。


John
John 2012-2-28
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 2012-2-28
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)) ;

类别

Help CenterFile Exchange 中查找有关 Automotive 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by