Question on how to use Forward Euler to simulate double pendulum

9 ビュー (過去 30 日間)
Zhukun Wang
Zhukun Wang 2021 年 2 月 24 日
回答済み: Dongyue 2022 年 11 月 17 日
m1=1;
m2=1;
l1=1;
l2=1;
g=9.8;
dt=0.1;
theta1=[pi/8];
theta2=[pi/8];
theta1dot=[0];
theta2dot=[0];
%We can define theta1dot as w and wdot as theta1doubledot.
for t=0:dt:100-dt
theta1next=theta1(end)+dt*(theta1dot(end));
theta1dotnext=theta1dot(end)+dt*(((-m2*l2*theta2dot(end)^2*sin(theta1(end)-theta2(end))-(m1+m2)*g*sin(theta1(end)))-m2*l2*cos(theta1(end)-theta2(end))*((l1*theta1dot(end)^2*sin(theta1(end)-theta2(end))-g*sin(theta2(end)))/(l2-(m2*l2*cos(theta1(end)-theta2(end))*l1*cos(theta1(end)-theta2(end)))/((m1+m2)*l1)))));
theta2next=theta2(end)+dt*(theta2dot(end));
theta2dotnext=theta2dot(end)+dt*((l1*theta1dot(end)^2*sin(theta1(end)-theta2(end))-g*sin(theta2(end)))/(l2-(m2*l2*cos(theta1(end)-theta2(end))*l1*cos(theta1(end)-theta2(end)))/((m1+m2)*l1)));
theta1=[theta1,theta1next];
theta1dot=[theta1dot,theta1dotnext];
theta2=[theta2,theta2next];
theta2dot=[theta2dot,theta2dotnext];
end
plot(theta1,theta2);
Above is my code for simulate double pendulum using matlab. However, I do not get expected results. Could someone help me figure our what might be wrong?

回答 (1 件)

Dongyue
Dongyue 2022 年 11 月 17 日
Hi Zhukun,
The following links will show you some examples of how to use MATLAB to simulate the double pendulum motion. Please go through these links to see detailed information and coding:
Best,
Dongyue

カテゴリ

Help Center および File ExchangeClassical Mechanics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by