0

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);
ayhan
  • 1
  • 2

1 Answers1

1
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.

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • and another error: Error using vertcat Dimensions of matrices being concatenated are not consistent. Error in non_L_ss (line 3) dX_prime = [ x(2) ; – ayhan Jul 06 '17 at 20:20
  • Your initial vector is a row vector, your directions are column vectors. Are you sure this is compatible? How are there matrices to concatenate, is it the empty space in the 4th component? – Lutz Lehmann Jul 06 '17 at 20:36
  • the following function be called by the same file and be solved : function dX = L_ss(t,x) global qdot mu kt ms v2 dX = [ x(3) - qdot ; -x(3) + x(4) ; -kt/mu * x(1) - ms/mu * v2 ; v2 ] ; end – ayhan Jul 06 '17 at 20:44
  • i think ODE45 solves equations and produces a row matrix (1*m) - m is number of variables, here is 4- each time, and concatenate those rows and produce a (n*m) matrix at the end. each column is answer for the variable with same number. – ayhan Jul 06 '17 at 20:55