I am a novice user of MATLAB. I have code that is trying to find the time history of a state space model. There are four first order ODEs that I want to solve simultaneously using ode45
. The essence of the equations to be solved is as follows:
x1_dot = x2
x2_dot = -[M] * [K] * x1 - [M] * [C] * x2 + constant*[M] * [P3] * x3 + constant*[M] * [P4] * x4
x3_dot = x2 - constant*x3
x4_dot = x2 - constant*x4
Where [M]
, [K]
, [C]
, [P3]
, and [P4]
are 3x3 matrices; x1
, x2
, x3
, x4
are all 3x1 vectors; and x1_dot
etc. represent the time derivatives (which are 3x1 vectors). I have initial conditions only for x1
.
The MATLAB code I've written is below. This code is within my overall program. I am not calling a separate function because I do not know how to pass all of the matrices/vectors into ode45
through a function. I am getting the error: "Index exceeds matrix dimensions."
tspan = 0:1:20;
initial = [0 0.03491 0];
f = @(t,x) [x(2);
-inv(M_Dbl_Bar_Matrix)*K_Dbl_Bar_Matrix*x(1) - inv(M_Dbl_Bar_Matrix)*C_Dbl_Bar_Matrix*x(2) + (0.5*rho*U^2)*inv(M_Dbl_Bar_Matrix)*P3_Matrix*x(3) + (0.5*rho*U^2)*inv(M_Dbl_Bar_Matrix)*P4_Matrix*x(4);
x(2) - Beta_1*x(3);
x(2) - Beta_2*x(4)];
[t,xp] = ode45(f,tspan,initial);
Questions:
How do I address the
x(1)
,x(2)
,x(3)
, andx(4)
inode45
being 3x1 vectors?How do I apply initial conditions for this system of equations? For example, do I use a vector format such as:
initial = [0 0.03491 0; 0 0 0; 0 0 0; 0 0 0]
?Am I correctly using / written the function (
f
) andode45
?