Second order differential equation with large matrices
7 次查看(过去 30 天)
显示 更早的评论
Greetings,
I am tryig to solve this differential equation M * q'' + K * q= - K_d * q' - K_p * (q - q_d) where M is a 15x15 matrix, q is 15x1 vector, K is a 15x15 matrix, K_d and K_p are 15x15 known matrices and q_d is a 15x1 vector which is also known. q'' is a second time derivative. Which solver is the most applicable for this equation? and is there way to solve this in a matrix form and not expand the whole equation. Thanks in advance.
6 个评论
Torsten
2022-12-10
编辑:Torsten
2022-12-10
One question guys. Let's say matrix M is not constant and is dependent on q, so at every time step M changes accordingly to the values of q calculated at previous time step (starting from initial condition q0). How can i incorporate that into the odesystem function for ode45 solver? Thank you in advance
By dividing through M (assuming M is non-singular):
q'' = M \ (- K * q - K_d * q' - K_p * (q - q_d) )
If M is singular, define M as mass-matrix for the ODE solver in the options-structure and use ode15s or ode23t instead of ode45.
采纳的回答
Sam Chak
2022-12-5
SInce this is a linear system, if you have the Control System Toolbox, then you can manipulate the matrix differential equation and convert it to a State-Space Model, that is similar to the system of 1st-order differential equations as advised by @Torsten, and then run the simulation using the lsim() command.
The following example demonstrates a 2-DOF Mass-Spring-Damper System.
M = diag([1 1])
Kd = 2*diag([1 1])
Kp = 0.5*diag([1 1])
K = 0.5*diag([1 1])
Convert the system of ODEs to State-space Model:
where the state vector is defined as
% State matrix
A = [zeros(2) eye(2);
M\(-Kp-K) M\(-Kd)]
% Input matrix
% B = [zeros(2); M\Kp] % based on your original Kp*qd
B = [zeros(2); M\(Kp+K)] % modified to track desired qd
% Output matrix
C = [eye(2) zeros(2)]
% Feedforward matrix
D = 0;
sys = ss(A, B, C, D)
t = 0:0.02:20;
u1 = max(0,min(t-1,1)); % qd1
u2 = max(0,min(t-1,1)); % qd2
U = [u1; u2]; % qd array
lsim(sys, U, t)
% lsim(sys, U, t, x0) % Use this if there is a vector x0 of initial state values
grid on
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!