MATLAB Answers

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

조회 수: 3(최근 30일)
Justin Burzachiello
Justin Burzachiello 2021년 7월 15일
댓글: Justin Burzachiello 2021년 7월 19일
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';
plot(t,x,'k',t,y,'r'),grid
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];
end
  댓글 수: 6
Justin Burzachiello
Justin Burzachiello 2021년 7월 19일
Thank you, Alan. Also, thanks for the help with inputting the data matrices as arguments.

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by