V =
syms x1(t) x2(t) y(t)
t0 = [0 1];
% y0 must be given in the order as prescribed by S (see below), thus
% y0 = (x2(0),dx2/dt(0),x1(0),dx1/dt(0),y(0),dy/dt(0))
% The solution is obtained in the same order.
y0 = [1 2 4 7 8 4];
tNum = 100;
gamma_ir = 1;
omega_ir1 = 1;
omega_ir2 = 0.5;
gamma_r = 2;
omega_r = 3;
eq1 = diff(x1,2) == -2*gamma_ir*omega_ir1*diff(x1) - omega_ir1^2*x1 + y + 2*x2*y;
eq2 = diff(x2,2) == -2*gamma_ir*omega_ir2*diff(x2) - omega_ir2^2*x2 + y + 2*x1*y;
eq3 = diff(y,2) == -2*gamma_r*omega_r*diff(y) - omega_r^2*y + x1*x2;
[V,S] = odeToVectorField(eq1,eq2,eq3)
M = matlabFunction(V,'vars', {'t','Y'})
interval = t0;
ySol = ode45(M,interval,y0);
tValues = linspace(interval(1),interval(2),tNum);
sol = deval(ySol,tValues,3);
plot(tValues,sol)
grid on