How to solve the coupled second order differential equations by using
Date: 2023-08-17 11:51:44
Hello,
I try to solve the coupled second order differential equations with ODE45.
But my answer was weird.
My system is two defree of freedom system including spring and damper.
So, the equations are
m1*x1'' + (c1+c2)*x1' + (k1+k2)*x1 - c2*x2' - k2*x2 = 0;
m2*x2'' + x2*x2' + k2*x2 - c2*x1' - k2*x1 = F(t);
And I changed the above equations,
x1'' = v1' = ...
x2'' = v2' = ...
Here are my code..
% mx1'' = -(k1+k2)x1 - (c1+c2)x1' + k2 x2 + c2 x2'
% mx2'' = -k2 x2 - c2 x2' + k2 x1 + c2 x1' + F
tspan = linspace(0,10*pi,2000);
h = tspan(2) - tspan(1);
xini = [0; 0; 0; 0];
[t,x] = ode45(@T2_func, tspan, xini);
------ Function ------
function dxdt = T2_func(t,x)
%%Constants
m1 = 1; % [kg]
m2 = 1; % [kg]
k1 = 10; % [N/m]
k2 = 10; % [N/m]
c1 = 1; % [Ns/m]
c2 = 1; % [Ns/m]
%%Force
p = 10 * ones(1,length(t)); % [N]
%%Matrix
F = zeros(2, length(t));
F(2,:) = p/m2;
K11 = -(k1+k2)/m1;
K12 = k2/m1;
K21 = -k2/m2;
K22 = k2/m2;
Kmat = [K11 K12; K21 K22];
C11 = -(c1+c2)/m1;
C12 = c2/m1;
C21 = -c2/m2;
C22 = c2/m2;
Cmat = [C11 C12; C21 C22];
%%Function
dxdt = zeros(4,1);
dxdt(1) = x(2);
dxdt(2) = - Kmat(1,1)*x(1) - Cmat(1,1)*x(2) + Kmat(1,2)*x(3) + Cmat(1,2)*x(4) + F(1);
dxdt(3) = x(4);
dxdt(4) = - Kmat(2,1)*x(3) - Cmat(2,1)*x(4) + Kmat(2,2)*x(1) + Cmat(2,2)*x(2) + F(2);