ayhan
ayhan

Reputation: 1

Solving nonlinear system of differential equations in matlab usin ODE45

i am trying to solve a system of nonlinear differential equation using ODE45 MATLAB , i did that many times successfully , but this time i get the following error and i really don't know what is wrong i am confused compeletly. here are the codes.

%% this is the error:

Subscript indices must either be real positive integers or logicals.

Error in non_L_ss (line 6)
        (-Fk*(ds0+x(3)-x(1))+Fk*ds0-Fc(x(4)-x(2)))/ms +Fa/ms ] ;

Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

Error in ode45 (line 115)
odearguments(FcnHandlesUsed,solver_name,ode, tspan,y0,optio varargin);

Error in solve (line 50)
[t X]=ode45(@non_L_ss,t_span,IC);

%% the equations be defined in a function:

function dX=non_L_ss(t,x)
global Fk Fc kt Fa q ds0 ms mu 
dX=[ x(2);
     (Fk*(ds0+x(3)-x(1))-Fk*ds0+Fc*(x(4)-x(2))-kt*x(1))/mu-Fa/m-kt*q/mu ;
     x(4);
     (-Fk*(ds0+x(3)-x(1))+Fk*ds0-Fc(x(4)-x(2)))/ms +Fa/ms ] ;
end

%% and here the function be called to solve by ODE45:

clear
clc
global Fk Fc kt Fa q ds0 ms mu qdot v2
mu = 100 ;
ms = 1242 ;
k1s = 80000 ;
k2s = 32000 ;
kt = 405000 ;
c1s = 4000 ;
c2s = 1600 ;
v = 20 ;
Gq = 256e-6 ;
ds0 = 0.1538 ;
a = 1 ;
b = 0.001 ;
n0 = 0.1 ;
f0 = 0.011*v ;
w = 0.5 ;
Fa = 2000 ;
q = 0.05 ;
xs = 0.1 ;
xu = 0.1 ;
dxs = 0.1 ;
dxu = 0.2 ;

Fk = k1s+k2s*(ds0+xs-xu).^2 ;

if dxs >= dxu
Fc = c1s ;
elseif dxs < dxu
Fc = c2s ;
end  

t_span=[0 1];
IC=[2 3 2 2];
[t X]=ode45(@non_L_ss,t_span,IC);

Upvotes: 0

Views: 1099

Answers (1)

Lutz Lehmann
Lutz Lehmann

Reputation: 25992

Subscript indices must either be real positive integers or logicals.

Error in non_L_ss (line 6)
    (-Fk*(ds0+x(3)-x(1))+Fk*ds0-Fc(x(4)-x(2)))/ms +Fa/ms ] ;

means that you use something as an indexed array with a non-integer index. Which probably means that the object is no array at all. I'd propose to replace

Fc(x(4)-x(2))

by

Fc*(x(4)-x(2))

to try to solve this issue.

Upvotes: 1

Related Questions