Question on how to use Forward Euler to simulate double pendulum

9 views (last 30 days)
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?

Answers (1)

Dongyue
Dongyue on 17 Nov 2022
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

Categories

Find more on Classical Mechanics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!