2nd order differential equation solution cant fit the problem

1 次查看(过去 30 天)
I try to simulate the swinging of a Garage door!
The soluation should be found via Lagrange. I get all the derivations as is shown in the sector with the "L_1,L_2,..."
But when solving via ode45 it shows me a normal sinus function and is far from what it should look like
clear
syms phi(t) m c g alpha(t) CB_x CB_z BA_x BA_z v_x v_z x0
m= 100;
copt= 3558.7;
g= 9.81;
x0=1.360564445;
k=0.75;
phi_d=diff(phi);
phi_dd= diff(phi,t,2);
alpha(t)= asin((1.7-2.1*cos(phi(t)))/3.6);
CB_x= -2.1*sin(phi);
CB_z= 2.1*cos(phi);
BA_x= 1.8*cos(alpha(t));
BA_z= 1.8*sin(alpha(t));
v_x=diff(CB_x+BA_x);
v_z=diff(CB_z+BA_z);
v=sqrt(v_x^2+v_z^2);
r1=((CB_x+BA_x)^2+(CB_z+BA_z)^2)^0.5;
alpha_d=diff(alpha(t),t);
x=sqrt(1.8^2+0.6^2-2*1.8*0.6*cos(phi(t)));
U=1/2*copt*k*(x-x0)^2;
W=-m*g*(CB_z+BA_z);
V=U+W;
T_trans=0.5*m*v^2;
T_rot=1/3*m*3.6^2*alpha_d^2;
T=T_trans+T_rot;
L_1=diff(diff(T,phi_d),t);
L_2=diff(T,phi(t));
L_3=diff(V,phi(t));
% L_1=diff(diff(T,phi_d),phi)*phi_d+diff(diff(T,phi_d),phi_d)*phi_dd;
% phi_dd_test=(diff(diff(T,phi_d),phi)*phi_d-L_3+L_2)/diff(diff(T,phi_d),phi_d);
F=L_1-L_2+L_3==0;
[Y,S] = odeToVectorField(F);
tspan=[0 30];
y0_45=[deg2rad(35.9) 0];
M = matlabFunction(Y,'vars', {'t','Y'});
[t,Y] = ode45(@(t, Y) M(t,Y),tspan,y0_45);
plot(t, Y, 'linewidth', 1.5)
xlim([0.00 10.00])
ylim([-4.00 4.00])
zlim([-1.00 1.00])
legend(["Winkel","Winkelgeschwindigkeit"])
xlabel("Time")
  2 个评论
Sam Chak
Sam Chak 2022-6-14
Based on what you described, does it suggest that the Lagrangian formulation should be checked again?
Patrick Nowohradsky
no the formulation should be fine!
because of the angle alpha (in my case the angle between door and horizontal line at the top) it should be nonlinear
phi ist the angle in the "middle"

请先登录,再进行评论。

回答(1 个)

Karan Singh
Karan Singh 2023-10-4
Hi Patrick,
From what I understand, the goal is to simulate the swinging motion of a garage door using Lagrange equations and solving the resulting differential equation using ode45 in MATLAB. However, there are a few issues in the code that might be causing the unexpected results. Let's go through them:
  1. In the definition of CB_x and CB_z, you have used sin(phi) and cos(phi) instead of sin(phi(t)) and cos(phi(t)), respectively. You need to evaluate these trigonometric functions at the current time t by replacing phi with phi(t). Similarly, in the definition of alpha(t), you need to replace phi with phi(t).
  2. In the definition of v_x and v_z, you have used diff(CB_x + BA_x) and diff(CB_z + BA_z), respectively. However, you need to evaluate these derivatives at the current time t by replacing diff(CB_x + BA_x) with diff(CB_x + BA_x, t) and diff(CB_z + BA_z) with diff(CB_z + BA_z, t).
  3. In the definition of x, you have used cos(phi(t)) instead of cos(alpha(t)). Replace cos(phi(t)) with cos(alpha(t)).
  4. The equation F = L_1 - L_2 + L_3 == 0represents the Lagrange equation. However, it seems that you have commented out a line of code that calculates phi_dd_test. Uncomment that line and assign phi_dd_test the value of (diff(diff(T,phi_d),phi)*phi_d - L_3 + L_2) / diff(diff(T,phi_d),phi_d).
Attached below are some documentation links that you may find helpful:
Hope this helps!
Karan Singh Khati

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by