MATLAB Answers

How can I model second order ODE with matrices and external forcing?

3 ビュー (過去 30 日間)
Justin Burzachiello
Justin Burzachiello 2021 年 7 月 15 日
Hello. I am new to MATLAB-based modeling of ODEs, and I was wondering if someone here can help me with simulating the dynamics of the following ODE. Links to resources, code, and/or vocabulary would be appreciated.
M is the mass matrix, E is the damping matrix, K is the stiffness matrix, B describes inputs, and C describes outputs.
My goal is the eventually model an impulse response or simply the evolution of the system with a collection of initial values.
For background, I don't really have sufficient background in FEA or numerical analysis. I am an intern learning the math and the MATLAB on the fly. I read into the documentation of ODE solvers, but I was unable to find a simple way to incorporate the equation above.
  • Thank you

回答 (1 件)

Alan Stevens
Alan Stevens 2021 年 7 月 15 日
Like this perhaps (I've made up arbitrary data; you will obviously have to replace it with your own)
x0 = [1; -1];
v0 = [0; 0];
X0 = [x0; v0];
tspan = [0 1];
[t,X] = ode45(@fn, tspan, X0);
x = X(:,1:2);
v = X(:,3:4);
C = [2, 0; 0, 2];
y = C*x';
xlabel('t'), ylabel('x (black) & y (red)')
function dXdt = fn(t,X)
M = [1, 0.1; 0.5, 0.5];
E = [2, 0; 0, 1];
K = [1, 1; 0.1, 0.2];
B = [1, 0; 0, 1];
u = [1; 0];
x = X(1:2);
v = X(3:4);
dxdt = v;
dvdt = M\(B*u - K*x - E*v);
dXdt = [dxdt; dvdt];
  6 件のコメント
Justin Burzachiello
Justin Burzachiello 2021 年 7 月 19 日
Thank you, Alan. Also, thanks for the help with inputting the data matrices as arguments.






Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by