Question on how to use Forward Euler to simulate double pendulum
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Classical Mechanics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!