MATLAB: Solve system of second order differential equations with ode45

differential equationsMATLABmatrixodeode45

I'm trying to solve a system of second order differential equations numerically with ode45. The equation is of the form y" = A*y + 2*y' + f, where A is an n*n matrix and f is an n*1 column vektor dependent on the main variable t. I've tried setting up a function which I call through ode45 as below:
function dydt = rhs(t,y)
dydt_1 = y(2);
dydt_2 = A*y(1) + 2*y(2) + f;
dydt = [dydt_1; dydt_2];
end
This just gives me an "Error using vertcat – Dimensions of matrices being concatenated are not consistent." I sort of understand why this doesn't work, but I cannot solve it; the problem being that I have a second order and a matrix system (either one I can get working by its own, just not together).
I'm calling my function with ode45 and the code below (where n is a large number and y0 is a constant).
t = 0:0.1:10;
y_init = y0*ones(n,1);
[t,y] = ode45(@rhs,t,y_init);

Best Answer

t = 0:0.1:10;
y_init = [y0*ones(n,1); zeros(n,1)]
[t,y] = ode45(@rhs,t,y_init);
function dydt = rhs(t,y)
y1 = zeros(n,1);
y2 = zeros(n,1);
dydt_1 = zeros(n,1);
dydt_2 = zeros(n,1);
dydt = zeros(2*n,1);
y1 = y(1:n);
y2 = y(n+1:2*n);
dydt_1 = y2;
dydt_2 = A*y1 + 2*y2 + f;
dydt = [dydt_1; dydt_2];
end
Best wishes
Torsten.