ODE 45 gives unexpected result on pendulum tuned mass damper
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to obtain a numerical solution for the motion of a pendulum mass damper using nonlinear differential equations obtained from Lagrange's equation.
I am changing the mass ratio to observe the resulting performance. It is expected that as the ratio gets closer to 1, the displacement of the main structure should be smaller.
However, the ode45 solver is providing completely different results. What could be wrong with my code?
I have used the state variable from an essay, so it should be correct. I have replaced "u" with "M*ag".
I also replaced the symbols like this: "x1" remains "x1", "x2" remains as "x2", "theta1" with "x3", and "theta2" with "x4".

clear;
ratio = [1,0.5,0.25];
for r = 1:numel(ratio)
M = 0.400;
m = M*ratio(r);
[t,y] = ode45(@(t,y) f(t,y,m), [0 20], [0,0,0,0]);
%%Finding Acceleration
accelerationDifference = diff(y(:, 2));
timeDifference = diff(t);
a = accelerationDifference ./ timeDifference;
a(end+1) = a(end-1);
subplot(4,1,1);
hold on;
plot(t, y(:,1), 'DisplayName', [num2str(ratio(r)), 'Ratio']);
xlabel('Time(s)');
ylabel('Displacement(m)');
title('Displacement vs Time graph of primary structure');
legend('show');
subplot(4,1,2);
hold on;
plot(t, y(:,2), 'DisplayName', [num2str(ratio(r)), 'Ratio']);
xlabel('Time(s)');
ylabel('Velocity (m/s)');
title('Velocity vs Time graph of primary structure');
legend('show');
subplot(4, 1, 3);
hold on;
plot(t, a, 'DisplayName', [num2str(ratio(r)), ' Ratio']);
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Acceleration vs Time graph of primary structure');
legend('show');
subplot(4,1,4);
hold on;
plot(t, y(:,3), 'DisplayName', [num2str(m), 'Ratio']);
xlabel('Time(s)');
ylabel('Displacement(m)');
title('PTMD Displacement vs Time ');
legend('show');
end
function dydt = f(t,y,m)
L = 0.058;
M = 0.400;
b = 0.1353;
d = 0.15;
c = 100*0.000098*60/(20*2*pi);
g = 9.807;
k = 67;
ag = 0.025*(2*pi/0.9)^2*sin(2*pi/0.9*t);
x1 = y(1); % x1 = displacement of main structure
x2 = y(2); % x2 = velocity of main structure
theta1 = y(3); %theta1 = angular displacement of pendulum
theta2 = y(4); %theta1 = angular velocity of pendulum
x3 = ( M*ag + m*g*cos(theta1)*sin(theta1) + cos(theta1)*(c/L+d*L*cos(theta1)^2)*theta2 - k*x1 - b*x2 + m*L*theta2^2*sin(theta1) ) / ( M + m*(1 - cos(theta1)^2) );
theta3 = ( -(M+m)/m*(c/L+d*L*cos(theta1)^2)*theta2 - (M+m)*g*sin(theta1) - cos(theta1)*(m*L*theta2^2*sin(theta1) + M*ag - k*x1 + b*x2) ) / ( L*(M + m*(1 - cos(theta1)^2)) );
dydt = [y(2);x3;y(4);theta3];
end
9 个评论
Torsten
2023-8-18
Can you please explain what are you refering in expression (3-15) and (3-18) with the arrow?
Should be -b/(L*M) instead of b/(L*M) in the matrix.
回答(1 个)
Sam Chak
2023-8-19
Hi @Baker
You can use the odeToVectorField() function to derive the dynamical model from the Euler–Lagrange equations. The accuracy of the derivation depends on the defined Lagrangian.
L = 0.058;
M = 0.400;
mu = 1;
m = M*mu;
g = 9.807;
k = 67;
b = 0.1353;
c = 100*0.000098*60/(20*2*pi);
d = 0.15;
sympref('AbbreviateOutput', false);
syms x(t) theta(t)
% definitions
Dx = diff(x, 1);
Dtheta = diff(theta, 1);
% Langrangian
T = 1/2*M*Dx^2 + 1/2*m*((Dx + L*Dtheta*cos(theta))^2 + (L*Dtheta*sin(theta))^2);
V = 1/2*k*x^2 + m*g*L*(1 - cos(theta));
L = T - V;
ag = 0.025*(2*pi/0.9)^2*sin(2*pi/0.9*t);
F = M*ag;
% Euler–Lagrange equations
eqn1 = diff(diff(L, Dx), 1) - diff(L, x) == F - b*Dx;
eqn2 = diff(diff(L, Dtheta), 1) - diff(L, theta) == - c*Dtheta - d*Dtheta*(L*cos(theta))^2;
eqns = [eqn1 eqn2];
[V, S] = odeToVectorField(eqns)
dydt = matlabFunction(V, 'vars', {'t', 'Y'});
tspan = [0 20]; % time span of simulation
y0 = [0 0 0.1 0]; % initial values
[t, Y] = ode45(@(t, Y) dydt(t, Y), tspan, y0);
plot(t, Y(:,3)), grid on
xlabel('Time(s)');
ylabel('Displacement(m)');
title('Displacement vs Time graph of primary structure');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Robotics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!