
how to solve 2DOF linear time variant differential equations in matlab with non-diagonal mass, stiffness and damping matrixes
11 次查看(过去 30 天)
显示 更早的评论
Hello everyone!
i hope u already have started an amazing summer.
it's been a while i am struggling to solve 2DOF linear time variant differential equations in matlab with non-diagonal mass, stiffness and damping matrixes using newmark beta method. The associated differential equation is uploaded to the chat related to the equivalent bean considering the first mode of vibration and a moving spring mass damper model that applies dynamic force of G(t). the picture of the physical and the mathematical equation of the system is attached to the chat. according to the uploaded matlab code, my bridge response (or generally let's say system response) depends on the time decrement of the numerical modeling. i dont know why for each value of time decrement "dt" i get ddifferent results. can someone kindly take a look on the equation and my code and give me some comments. much appreciate it!
clc;
clear;
close all;
% ---------------------- PARAMETERS ----------------------
m_p = 70; ksi_p = 0.03; f_p = 2.33; omega_p = 2*pi*f_p;
k_p = m_p * omega_p^2;
c_p = 2 * ksi_p * m_p * omega_p;
m_b = 867.5; kisi_b = 0.008; f_b = 4.58; omega_b = 2*pi*f_b;
k_b = m_b * omega_b^2;
c_b = 2 * kisi_b * m_b * omega_b;
% Load properties
L = 22.9; n_mode = 1; fw = 140/60;
V = 0.714 * fw + 0.055;
% Time parameters
dt = 0.001; T = 13.28; t = 0:dt:T; n = length(t);
% GRF input
DLF = [0.4, 0.1, 0.042, 0.041, 0.01]; phi_phase = [0, 0, 0, 0, 0];
W = m_p * 9.81;
phi2 = sin(pi * V * t / L);
GRF = (W + W * (DLF(1) .* cos(1*2*pi*fw*t + phi_phase(1)) + ...
DLF(2) .* cos(2*2*pi*fw*t + phi_phase(2)) + ...
DLF(3) .* cos(3*2*pi*fw*t + phi_phase(3)) + ...
DLF(4) .* cos(4*2*pi*fw*t + phi_phase(4)) + ...
DLF(5) .* cos(5*2*pi*fw*t + phi_phase(5)))) .* phi2;
% Initialize state
x = zeros(2, n); xdot = zeros(2, n); xddot = zeros(2, n);
% Initial matrices at t=0
Phi_t = sin(n_mode * pi * V * t(1) / L);
M = [1, m_p*Phi_t; 0, m_p];
C = [c_b, 0; -c_p*Phi_t, c_p];
K = [k_b, 0; -k_p*Phi_t, k_p];
F0 = [GRF(1)/m_b; 0];
xddot(:,1) = M \ (F0 - C*xdot(:,1) - K*x(:,1));
% Newmark-Beta constants
beta = 1/4; gamma = 0.5;
a0 = 1 / (beta * dt^2);
a1 = gamma / (beta * dt);
a2 = 1 / (beta * dt);
a3 = gamma / beta;
a4 = 1 / (2 * beta);
a5 = dt / 2 * (gamma / beta - 2);
a6 = dt * (1 - gamma / (2 * beta));
maxIter = 20; tol = 1e-6;
for k = 1:n-1
tk = t(k); Phi_t = sin(n_mode * pi * V * tk / L);
M = [1, m_p*Phi_t; 0, m_p];
C = [c_b, 0; -c_p*Phi_t, c_p];
K = [k_b, 0; -k_p*Phi_t, k_p];
Fk = [GRF(k)/m_b; 0];
Keff = a0 * M + a1 * C + K;
A = a2 * M + a3 * C;
B = a4 * M + a5 * C;
dFeff = Fk + A * xdot(:,k) + B * xddot(:,k);
delta_u = Keff \ dFeff;
% Iteration variables
u = x(:,k); du = xdot(:,k); ddu = xddot(:,k);
for i = 1:maxIter
u_trial = u + delta_u;
du_trial = du + (a1 * delta_u - a3 * du + a6 * ddu);
ddu_trial = ddu + (a0 * delta_u - a2 * du - a4 * ddu);
R = Fk - (M * ddu_trial + C * du_trial + K * u_trial);
if norm(R) < tol
break;
end
delta_u_corr = Keff \ R;
delta_u = delta_u + delta_u_corr;
end
% Update states
x(:,k+1) = u + delta_u;
xdot(:,k+1) = du + (a1 * delta_u - a3 * du + a6 * ddu);
xddot(:,k+1) = ddu + (a0 * delta_u - a2 * du - a4 * ddu);
end
% Output
acc1 = xddot(1, :); acc2 = xddot(2, :);
fprintf('Max bridge acc: %.6f m/s²\n', max(abs(acc1)));
fprintf('Max pedestrian acc: %.6f m/s²\n', max(abs(acc2)));
% Plot
figure; plot(t, acc1); title('Bridge Acceleration'); grid on;
% FFT
Fs = 1/dt;
N = length(acc1);
Y = fft(acc1); P = 2 * abs(Y / N); P = P(1:N/2 + 1);
f_vector = Fs * (0:(N/2)) / N;
figure; plot(f_vector, P, 'LineWidth', 2); xlim([0 15]);
title('FFT of Bridge Acceleration');

5 个评论
William Rose
2025-5-12
I think there is an inconsistency between the equation in the figure and the implementation in your code. The equation in the figure suggests that element C(1,1) in your code should equal
. But your code defines c_b = 2*kisi_b*m_b*omega_b and C(1,1)=c_b. In other words, your C(1,1) includes a factor m_b which is not present in the equation in the figure.

A similar problem appears with array K. The equation in the figure suggests that element K(1,1) in your code should equal
. But your code defines k_b=m_b*omega_b^2 and K(1,1)=k_b. In other words, your K(1,1) includes a factor m_b which is not present in the equation in the figure.

Analysis of the presumed units also suggests that the code is incorrect:
The forcing term in the code is Fk = [GRF(k)/m_b; 0] (which is consistent with the equation in the figure). If GRF(k) has units of force, then Fk(1) has units of (force/mass)=acceleration. In that case, you do not want a mass term in K(1,1) or C(1,1).
You said to @Torsten: "however, the acceleration response of the bridge DOF is irrational according to the provided code". Do you mean the acceleration has an imaginary component? If so, could it be related to the values of C(1,1) and K(1,1)?
William Rose
2025-5-15
What is the source of the figure showing the bridge and the coupled equations? I am asking because the equation in the figure looks wrong to me. It appears to have inconsistent units.
I assume
and y(t) are displacements (units of length), and
is dimensionless. The first part of the equation in the figure is



When the top row of the matrix multiplies the column vector, the result is
. This represents adding acceleration (
) to (mass times acceleration) (
). But one may not add quantities with different units. Therefore the equation in the figure is wrong, or my assumptions about the units for the variables are wrong.



Perhaps the equation in the figure should be

where
and
. The units are consistent in this equation. You could use @Torsten's approach or mine to solve this equation.


回答(2 个)
Torsten
2025-5-12
编辑:Torsten
2025-5-12
x0 = [0;0;0;0];
tspan = [0 13.28];
[T,X] = ode45(@fun,tspan,x0);
for i = 1:numel(T)
dxdt = fun(T(i),X(i,:));
q1ddot(i) = dxdt(2);
yddot(i) = dxdt(4);
end
figure(1)
plot(T,X(:,1)) %q1
figure(2)
plot(T,X(:,3)) %y
figure(3)
plot(T,X(:,2)) %q1dot
figure(4)
plot(T,X(:,4)) %ydot
figure(5)
plot(T,q1ddot) %q1ddot
figure(6)
plot(T,yddot) % yddot
function dxdt = fun(t,x)
q1 = x(1);
q1dot = x(2);
y = x(3);
ydot = x(4);
% ---------------------- PARAMETERS ----------------------
m_p = 70; ksi_p = 0.03; f_p = 2.33; omega_p = 2*pi*f_p;
k_p = m_p * omega_p^2;
c_p = 2 * ksi_p * m_p * omega_p;
m_b = 867.5; kisi_b = 0.008; f_b = 4.58; omega_b = 2*pi*f_b;
k_b = m_b * omega_b^2;
c_b = 2 * kisi_b * m_b * omega_b;
% Load properties
L = 22.9; n_mode = 1; fw = 140/60;
V = 0.714 * fw + 0.055;
% GRF input
DLF = [0.4, 0.1, 0.042, 0.041, 0.01]; phi_phase = [0, 0, 0, 0, 0];
W = m_p * 9.81;
phi2 = sin(pi * V * t / L);
GRF = (W + W * (DLF(1) .* cos(1*2*pi*fw*t + phi_phase(1)) + ...
DLF(2) .* cos(2*2*pi*fw*t + phi_phase(2)) + ...
DLF(3) .* cos(3*2*pi*fw*t + phi_phase(3)) + ...
DLF(4) .* cos(4*2*pi*fw*t + phi_phase(4)) + ...
DLF(5) .* cos(5*2*pi*fw*t + phi_phase(5)))) .* phi2;
Phi_t = sin(n_mode * pi * V * t / L);
M = [1, m_p*Phi_t; 0, m_p];
C = [c_b, 0; -c_p*Phi_t, c_p];
K = [k_b, 0; -k_p*Phi_t, k_p];
Fk = [GRF/m_b; 0];
acc = M\(Fk - C*[q1dot;ydot] - K*[q1;y]);
dxdt = [q1dot;acc(1);ydot;acc(2)];
end
4 个评论
William Rose
2025-5-12
@Torsten has given a great answer with plots. Here is another way of looking at the problem - which shoudl lead to the exact same results as @Torsten's approach.
Your original equation is

where
(eq.2).

Define
(eq.3). Then we can write


Combine eq.3 and eq.4:

Equation 5 has the form needed for ode45(), as long as you use eq.2 when evaluating the right hand side of eq.5, at every time step. You could define

and then eq.5 could be written as

And that is what @Torsten has done and solved. His vector dxdt is like my
, except the elements are in a different order. He has
, and I have
.



5 个评论
William Rose
2025-5-14
Sorry I forgot to attach the code earlier. Here is its.
William Rose
2025-5-15
编辑:William Rose
2025-5-15
[Edit: Add plot of acceleration.]
I solved the system using the alternate equation, which I proposed in a comment above.

The equation in the figure you posted indicates the addition of quantities with different units, which is an error. That is why I propose the alternate equation - see comment above for details.. When I solve with the alternate equation, I get the solution shown. Code attached.

另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!