animate Double Pendulum with solved ODE.

조회 수: 2 (최근 30일)
Guillaume Theret
Guillaume Theret 2021년 5월 28일
댓글: Guillaume Theret 2021년 5월 28일
Hi,
I'm trying to animate a double pendule with matlab.
I looked at this tutorial but didnt manage to make it work : https://fr.mathworks.com/help/symbolic/animation-and-solution-of-double-pendulum.html
function double_pendule(x,y,L1,L2)
x1 = @(t) L1*sin(y(t));
y1 = @(t) -L1 * cos(y(t));
x2 = @(t) x1 + L2*sin(y(t));
y2 = @(t) y1 - L2*cos(y(t));
M1 = 1;
fanimator(@(t) plot(x1(t),y1(t),'ro','MarkerSize',M1*10,'MarkerFaceColor','r'));
axis equal;
end
y looks like this :
What did i do wrong ? Thanks !
  댓글 수: 1
Guillaume Theret
Guillaume Theret 2021년 5월 28일
f animator starts at indice 0 when my y starts at 1. I can't manage to make the f animator starts from 1.

댓글을 달려면 로그인하십시오.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 28일
Hi,
Here is an updated and corrected code with a different animation procedure:
L2 = 20;
t = 0:.1:2*pi;
double_pendule(t, L1, L2);
function double_pendule(t, L1, L2)
x1 = @(t) L1*sin(t);
y1 = @(t) -L1 * cos(t);
x2 = @(t) (x1(t) + L2*sin(t));
y2 = @(t) (y1(t) - L2*cos(t));
M1 = 1;
for ii=1:numel(t)
plot(x1(ii), y1(ii), 'd', x2(ii), y2(ii), 'o', 'markerfacecolor', 'c'), pause(.1)
hold all
axis equal;
end
end
Good luck.
  댓글 수: 1
Guillaume Theret
Guillaume Theret 2021년 5월 28일
ok thanks, this should work but what about my ODE ? I solved it with euler explicit. The angle needs to be y1(t).
Should i just change it ?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by