At the beginning of my request I remind you that because of the high volume of my program , it was not possible for me to bring it here, as a result I try to express my problem by an example. So my purpose is its algorithm.

suppose we have some differential equations in which one of the variables is matrix and beside that we have some non-matrix differential equations (by that I mean those which have different dimension with previous matrix and in particular consider it with dimention 1)

ODE45 is used for solving above equations. If we consider this problem in matrix state only, first we use "reshape" script and then we convert it with a columnar matrix at the end.

If we have some equations with dimention 1 beside this equation, how should it be modified?

%-----MAIN M-FILE--------------

clear all

%-----VARIABLE SET-UP--------------

exptime=30;

c=0.1;

g=9.81;

A = [0 1 0 0 0; 0 0 -g 0 1; 0 0 0 1 0; 0 0 0 -1/c 0;0 0 0 0 -20];

B = [0; 0; 0; 1/c; 0];

R = 10;

Q = [1 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0;0 0 0 0 0];

S = [0; 0; 0; 0; 0];

E = eye(5);

dps=70;

stepnum=dps*exptime

I5=eye(5);

%-----TO RUN and PLOT ODE SOLUTION--------------

t01= 0;

tf1=exptime;

tspan1 = LINSPACE(t01,tf1,dps*(tf1-t01));

X01=zeros(5);

[Time1,X1] = ode45(@(t,X) odefuncare(t,X,A,B,Q,R,S,E),tspan1,X01);

plot(Time1,X1)

another m file :

function dxdt = odefuncare(t,X,A,B,Q,R,S,E)

X = reshape(X,5,5); %converting X from a column vector generated by ode45 into a 5 x 5 Matrix

dxdt=((A')*X*E)+((E')*X*A)-(((E')*(X)*(B)+S)*(inv(R))*((B')*(X)*(E)+(S')))+Q;

dxdt = dxdt( : ) ;

here suppose under and up equations are couple(s) and it could not solved in 2 separated m-files

K=X*T

T is a matrix (5*1)

ydot(1) =f (y(1), y(2),y(3) ,y(4) ,y(5)) + k(1)*y(1)

ydot(2)=g( (y(1), y(2),y(3) ,y(4) ,y(5)) + k(2)*y(2)

ydot(3) =h((y(1), y(2),y(3) ,y(4) ,y(5)) + k(3)*y(3)

ydot(4)=I( (y(1), y(2),y(3) ,y(4) ,y(5)) + k(4)*y(4)

ydot(5) =J( y(1), y(2),y(3) ,y(4) ,y(5)) + k(5)*y(5)

initial condition :

y0=[ y10 ; y20; y30 ; y40; y50]