MATLAB: Solving a differential equation coupling together in matrix and vector form with ode45

differential equationsmatrixode45

I have two problem:
1) I used two functions for solving a set of equation not in matrix or vector form but like
[x(2);3+x(4)+x(3);x(4);………………..]
then [t,x] = ode45(@(t,x) lili(t,x),tspan,x0);
now I need the vector of dx=[x(2) x(4) x(6)]
but it doesnt return this vector.
2) i want to solve equation like this D2y=d2x+cross(m,n)
its clear cross product is in vector form
how could i solve matrix form of differential equation?
especially initial values is a vector

Best Answer

clc
clear
x_1=[1 8 9];
x_2=[2 3 4];
x0=[x_1 x_2].';
tspan = [0 20];
one = 1:3;
two = 4:6;
n=[0 1 2]';
f = @(t,x) [x(two);x(one)+n]
[t, xR] = ode45(f, tspan, x0);
x1 = xR(:,one)
x2 = xR(:,two)
plot(x1,t)
%plot(x2,t)
I have found a solution could any make me sure?