resolution of MDOF using ode45
i have a problem solving the system with ode45. the code works but the displacement in graphed output is not what i would expect from a chirp signal. What could be the error in my code?
%MATRIX
M=diag([m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19]);
% stiffness matrix 19×19
K = zeros(19,19);
K(1,1) = k1 + k4 + k7 + k8;
K(1,2) = -k1;
K(1,5) = -k4;
K(1,7) = -k7;
K(1,8) = -k8;
K(2,1) = -k1;
K(2,2) = k1 + k2;
K(2,3) = -k2;
K(3,2) = -k2;
K(3,3) = k2 + k3;
K(3,4) = -k3;
K(4,3) = -k3;
K(4,4) = k3;
K(5,1) = -k4;
K(5,5) = k4 + k5 + k6;
K(5,6) = -k5;
K(5,7) = -k6;
K(6,5) = -k5;
K(6,6) = k5 + k11;
K(6,11) = -k11;
K(7,1) = -k7;
K(7,5) = -k6;
K(7,7) = k6 + k7 + k23;
K(7,18) = -k23;
K(8,1) = -k8;
K(8,8) = k8 + k9;
K(8,9) = -k9;
K(9,8) = -k9;
K(9,9) = k9 + k10;
K(9,10) = -k10;
K(10,9) = -k10;
K(10,10) = k10;
K(11,6) = -k11;
K(11,7) = -k12;
K(11,11) = k11 + k12 + k13 + k14;
K(11,12) = -k13;
K(11,13) = -k14;
K(12,11) = -k13;
K(12,12) = k13 + k15;
K(12,14) = -k15;
K(13,11) = -k14;
K(13,13) = k14 + k16;
K(13,15) = -k16;
K(14,12) = -k15;
K(14,14) = k15 + k17;
K(14,16) = -k17;
K(15,13) = -k16;
K(15,15) = k16 + k18;
K(15,17) = -k18;
K(16,14) = -k17;
K(16,16) = k17 + k19;
K(17,15) = -k18;
K(17,17) = k18 + k20;
K(18,7) = -k23;
K(18,18) = k23 + k21 + k22;
K(18,19) = -k21 – k22;
K(19,18) = -k21 – k22;
K(19,19) = k21 + k22;
% damping matrix 19×19
C = zeros(19,19);
C(1,1) = c1 + c4 + c7 + c8;
C(1,2) = -c1;
C(1,5) = -c4;
C(1,7) = -c7;
C(1,8) = -c8;
C(2,1) = -c1;
C(2,2) = c1 + c2;
C(2,3) = -c2;
C(3,2) = -c2;
C(3,3) = c2 + c3;
C(3,4) = -c3;
C(4,3) = -c3;
C(4,4) = c3;
C(5,1) = -c4;
C(5,5) = c4 + c5 + c6;
C(5,6) = -c5;
C(5,7) = -c6;
C(6,5) = -c5;
C(6,6) = c5 + c11;
C(6,11) = -c11;
C(7,1) = -c7;
C(7,5) = -c6;
C(7,7) = c6 + c7 + c23;
C(7,18) = -c23;
C(8,1) = -c8;
C(8,8) = c8 + c9;
C(8,9) = -c9;
C(9,8) = -c9;
C(9,9) = c9 + c10;
C(9,10) = -c10;
C(10,9) = -c10;
C(10,10) = c10;
C(11,6) = -c11;
C(11,7) = -c12;
C(11,11) = c11 + c12 + c13 + c14;
C(11,12) = -c13;
C(11,13) = -c14;
C(12,11) = -c13;
C(12,12) = c13 + c15;
C(12,14) = -c15;
C(13,11) = -c14;
C(13,13) = c14 + c16;
C(13,15) = -c16;
C(14,12) = -c15;
C(14,14) = c15 + c17;
C(14,16) = -c17;
C(15,13) = -c16;
C(15,15) = c16 + c18;
C(15,17) = -c18;
C(16,14) = -c17;
C(16,16) = c17 + c19;
C(17,15) = -c18;
C(17,17) = c18 + c20;
C(18,7) = -c23;
C(18,18) = c23 + c21 + c22;
C(18,19) = -c21 – c22;
C(19,18) = -c21 – c22;
C(19,19) = c21 + c22;
n=19;
y0 = zeros(2*n,1);
tspan = [0 120];
% ode45
[t, y] = ode45(@(t, y) odefcn_standing(t, y, M, C, K), tspan, y0);
figure;
plot(t, y(:, 19));
xlabel(‘Time (s)’);
ylabel(‘Displacement (m)’);
% legend(‘y1’, ‘y2’, ‘y3’);
title(‘response of the system 19DOF’);
grid on;
function dy = odefcn_standing(t, y, M, C, K)
n = 19; % Numero di gradi di libertà
dy = zeros(2 * n, 1);
% Construction of matrix A
A = [zeros(n), eye(n);
-inv(M) * K, -inv(M) * C];
F = zeros(19, 1);
f0 = 0.5; % initial frequency
f1 = 80; % final frequency
t_f = 120; % duration of chirp signal
chirp_signal = chirp(t, f0, t_f, f1);
F(16,:) = 10*chirp_signal; % on mass 16
F(17,:) = 10*chirp_signal; % on mass 17
% Construction of matrix B
B = [zeros(n, n); inv(M)];
dy = A * y + B * F;
endi have a problem solving the system with ode45. the code works but the displacement in graphed output is not what i would expect from a chirp signal. What could be the error in my code?
%MATRIX
M=diag([m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19]);
% stiffness matrix 19×19
K = zeros(19,19);
K(1,1) = k1 + k4 + k7 + k8;
K(1,2) = -k1;
K(1,5) = -k4;
K(1,7) = -k7;
K(1,8) = -k8;
K(2,1) = -k1;
K(2,2) = k1 + k2;
K(2,3) = -k2;
K(3,2) = -k2;
K(3,3) = k2 + k3;
K(3,4) = -k3;
K(4,3) = -k3;
K(4,4) = k3;
K(5,1) = -k4;
K(5,5) = k4 + k5 + k6;
K(5,6) = -k5;
K(5,7) = -k6;
K(6,5) = -k5;
K(6,6) = k5 + k11;
K(6,11) = -k11;
K(7,1) = -k7;
K(7,5) = -k6;
K(7,7) = k6 + k7 + k23;
K(7,18) = -k23;
K(8,1) = -k8;
K(8,8) = k8 + k9;
K(8,9) = -k9;
K(9,8) = -k9;
K(9,9) = k9 + k10;
K(9,10) = -k10;
K(10,9) = -k10;
K(10,10) = k10;
K(11,6) = -k11;
K(11,7) = -k12;
K(11,11) = k11 + k12 + k13 + k14;
K(11,12) = -k13;
K(11,13) = -k14;
K(12,11) = -k13;
K(12,12) = k13 + k15;
K(12,14) = -k15;
K(13,11) = -k14;
K(13,13) = k14 + k16;
K(13,15) = -k16;
K(14,12) = -k15;
K(14,14) = k15 + k17;
K(14,16) = -k17;
K(15,13) = -k16;
K(15,15) = k16 + k18;
K(15,17) = -k18;
K(16,14) = -k17;
K(16,16) = k17 + k19;
K(17,15) = -k18;
K(17,17) = k18 + k20;
K(18,7) = -k23;
K(18,18) = k23 + k21 + k22;
K(18,19) = -k21 – k22;
K(19,18) = -k21 – k22;
K(19,19) = k21 + k22;
% damping matrix 19×19
C = zeros(19,19);
C(1,1) = c1 + c4 + c7 + c8;
C(1,2) = -c1;
C(1,5) = -c4;
C(1,7) = -c7;
C(1,8) = -c8;
C(2,1) = -c1;
C(2,2) = c1 + c2;
C(2,3) = -c2;
C(3,2) = -c2;
C(3,3) = c2 + c3;
C(3,4) = -c3;
C(4,3) = -c3;
C(4,4) = c3;
C(5,1) = -c4;
C(5,5) = c4 + c5 + c6;
C(5,6) = -c5;
C(5,7) = -c6;
C(6,5) = -c5;
C(6,6) = c5 + c11;
C(6,11) = -c11;
C(7,1) = -c7;
C(7,5) = -c6;
C(7,7) = c6 + c7 + c23;
C(7,18) = -c23;
C(8,1) = -c8;
C(8,8) = c8 + c9;
C(8,9) = -c9;
C(9,8) = -c9;
C(9,9) = c9 + c10;
C(9,10) = -c10;
C(10,9) = -c10;
C(10,10) = c10;
C(11,6) = -c11;
C(11,7) = -c12;
C(11,11) = c11 + c12 + c13 + c14;
C(11,12) = -c13;
C(11,13) = -c14;
C(12,11) = -c13;
C(12,12) = c13 + c15;
C(12,14) = -c15;
C(13,11) = -c14;
C(13,13) = c14 + c16;
C(13,15) = -c16;
C(14,12) = -c15;
C(14,14) = c15 + c17;
C(14,16) = -c17;
C(15,13) = -c16;
C(15,15) = c16 + c18;
C(15,17) = -c18;
C(16,14) = -c17;
C(16,16) = c17 + c19;
C(17,15) = -c18;
C(17,17) = c18 + c20;
C(18,7) = -c23;
C(18,18) = c23 + c21 + c22;
C(18,19) = -c21 – c22;
C(19,18) = -c21 – c22;
C(19,19) = c21 + c22;
n=19;
y0 = zeros(2*n,1);
tspan = [0 120];
% ode45
[t, y] = ode45(@(t, y) odefcn_standing(t, y, M, C, K), tspan, y0);
figure;
plot(t, y(:, 19));
xlabel(‘Time (s)’);
ylabel(‘Displacement (m)’);
% legend(‘y1’, ‘y2’, ‘y3’);
title(‘response of the system 19DOF’);
grid on;
function dy = odefcn_standing(t, y, M, C, K)
n = 19; % Numero di gradi di libertà
dy = zeros(2 * n, 1);
% Construction of matrix A
A = [zeros(n), eye(n);
-inv(M) * K, -inv(M) * C];
F = zeros(19, 1);
f0 = 0.5; % initial frequency
f1 = 80; % final frequency
t_f = 120; % duration of chirp signal
chirp_signal = chirp(t, f0, t_f, f1);
F(16,:) = 10*chirp_signal; % on mass 16
F(17,:) = 10*chirp_signal; % on mass 17
% Construction of matrix B
B = [zeros(n, n); inv(M)];
dy = A * y + B * F;
end i have a problem solving the system with ode45. the code works but the displacement in graphed output is not what i would expect from a chirp signal. What could be the error in my code?
%MATRIX
M=diag([m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19]);
% stiffness matrix 19×19
K = zeros(19,19);
K(1,1) = k1 + k4 + k7 + k8;
K(1,2) = -k1;
K(1,5) = -k4;
K(1,7) = -k7;
K(1,8) = -k8;
K(2,1) = -k1;
K(2,2) = k1 + k2;
K(2,3) = -k2;
K(3,2) = -k2;
K(3,3) = k2 + k3;
K(3,4) = -k3;
K(4,3) = -k3;
K(4,4) = k3;
K(5,1) = -k4;
K(5,5) = k4 + k5 + k6;
K(5,6) = -k5;
K(5,7) = -k6;
K(6,5) = -k5;
K(6,6) = k5 + k11;
K(6,11) = -k11;
K(7,1) = -k7;
K(7,5) = -k6;
K(7,7) = k6 + k7 + k23;
K(7,18) = -k23;
K(8,1) = -k8;
K(8,8) = k8 + k9;
K(8,9) = -k9;
K(9,8) = -k9;
K(9,9) = k9 + k10;
K(9,10) = -k10;
K(10,9) = -k10;
K(10,10) = k10;
K(11,6) = -k11;
K(11,7) = -k12;
K(11,11) = k11 + k12 + k13 + k14;
K(11,12) = -k13;
K(11,13) = -k14;
K(12,11) = -k13;
K(12,12) = k13 + k15;
K(12,14) = -k15;
K(13,11) = -k14;
K(13,13) = k14 + k16;
K(13,15) = -k16;
K(14,12) = -k15;
K(14,14) = k15 + k17;
K(14,16) = -k17;
K(15,13) = -k16;
K(15,15) = k16 + k18;
K(15,17) = -k18;
K(16,14) = -k17;
K(16,16) = k17 + k19;
K(17,15) = -k18;
K(17,17) = k18 + k20;
K(18,7) = -k23;
K(18,18) = k23 + k21 + k22;
K(18,19) = -k21 – k22;
K(19,18) = -k21 – k22;
K(19,19) = k21 + k22;
% damping matrix 19×19
C = zeros(19,19);
C(1,1) = c1 + c4 + c7 + c8;
C(1,2) = -c1;
C(1,5) = -c4;
C(1,7) = -c7;
C(1,8) = -c8;
C(2,1) = -c1;
C(2,2) = c1 + c2;
C(2,3) = -c2;
C(3,2) = -c2;
C(3,3) = c2 + c3;
C(3,4) = -c3;
C(4,3) = -c3;
C(4,4) = c3;
C(5,1) = -c4;
C(5,5) = c4 + c5 + c6;
C(5,6) = -c5;
C(5,7) = -c6;
C(6,5) = -c5;
C(6,6) = c5 + c11;
C(6,11) = -c11;
C(7,1) = -c7;
C(7,5) = -c6;
C(7,7) = c6 + c7 + c23;
C(7,18) = -c23;
C(8,1) = -c8;
C(8,8) = c8 + c9;
C(8,9) = -c9;
C(9,8) = -c9;
C(9,9) = c9 + c10;
C(9,10) = -c10;
C(10,9) = -c10;
C(10,10) = c10;
C(11,6) = -c11;
C(11,7) = -c12;
C(11,11) = c11 + c12 + c13 + c14;
C(11,12) = -c13;
C(11,13) = -c14;
C(12,11) = -c13;
C(12,12) = c13 + c15;
C(12,14) = -c15;
C(13,11) = -c14;
C(13,13) = c14 + c16;
C(13,15) = -c16;
C(14,12) = -c15;
C(14,14) = c15 + c17;
C(14,16) = -c17;
C(15,13) = -c16;
C(15,15) = c16 + c18;
C(15,17) = -c18;
C(16,14) = -c17;
C(16,16) = c17 + c19;
C(17,15) = -c18;
C(17,17) = c18 + c20;
C(18,7) = -c23;
C(18,18) = c23 + c21 + c22;
C(18,19) = -c21 – c22;
C(19,18) = -c21 – c22;
C(19,19) = c21 + c22;
n=19;
y0 = zeros(2*n,1);
tspan = [0 120];
% ode45
[t, y] = ode45(@(t, y) odefcn_standing(t, y, M, C, K), tspan, y0);
figure;
plot(t, y(:, 19));
xlabel(‘Time (s)’);
ylabel(‘Displacement (m)’);
% legend(‘y1’, ‘y2’, ‘y3’);
title(‘response of the system 19DOF’);
grid on;
function dy = odefcn_standing(t, y, M, C, K)
n = 19; % Numero di gradi di libertà
dy = zeros(2 * n, 1);
% Construction of matrix A
A = [zeros(n), eye(n);
-inv(M) * K, -inv(M) * C];
F = zeros(19, 1);
f0 = 0.5; % initial frequency
f1 = 80; % final frequency
t_f = 120; % duration of chirp signal
chirp_signal = chirp(t, f0, t_f, f1);
F(16,:) = 10*chirp_signal; % on mass 16
F(17,:) = 10*chirp_signal; % on mass 17
% Construction of matrix B
B = [zeros(n, n); inv(M)];
dy = A * y + B * F;
end ode45, mdof MATLAB Answers — New Questions