Search code examples
maple

Double pendulum animation


I'm trying to obtain animated double pendulum. Though I can obtain animation for any (one) mass, I can't obtain it for both.

restart; 
with(DEtools, odeadvisor); 
with(plots); 
with(plottools); 
Sys := [2*(diff(T1(t), t, t))+cos(T1(t)-T2(t))*(diff(T2(t), t, t))+sin(T1(t)-T2(t))*(diff(T2(t), t))^2+19.6*sin(T1(t)) = 0, diff(T2(t), t, t)+cos(T1(t)-T2(t))*(diff(T1(t), t, t))-sin(T1(t)-T2(t))*(diff(T1(t), t))+9.8*sin(T2(t)) = 0, T1(0) = 1, (D(T1))(0) = 0, T2(0) = 1, (D(T2))(0) = 1];
sol := dsolve(Sys, type = numeric, range = 0 .. 20, output = listprocedure);
odeplot(sol, [T1(t), T2(t)], 0 .. 20, refine = 1); 
TT1, TT2 := op(subs(sol, [T1(t), T2(t)])); 
f := proc (t) options operator, arrow; pointplot([cos(TT1(t)), sin(TT1(t))], color = blue, symbol = solidcircle, symbolsize = 25) end proc; 
p := proc (t) options operator, arrow; pointplot([cos(TT2(t)), sin(TT2(t))], color = red, symbol = solidcircle, symbolsize = 25) end proc;

Any help would be appreciated.


Solution

  • You have provided no explanation of the way your equations are intended to model a physical system, which is not helpful.

    So I have made some guesses about your intentions and your model. Please don't blame me if my guesses are not on the mark.

    restart;
    with(plots):
    
    Sys := [2*(diff(T1(t), t, t))+cos(T1(t)-T2(t))*(diff(T2(t), t, t))
        +sin(T1(t)-T2(t))*(diff(T2(t), t))^2+19.6*sin(T1(t)) = 0,
        diff(T2(t), t, t)+cos(T1(t)-T2(t))*(diff(T1(t), t, t))
        -sin(T1(t)-T2(t))*(diff(T1(t), t))+9.8*sin(T2(t)) = 0,
        T1(0) = 1, (D(T1))(0) = 0, T2(0) = 1, (D(T2))(0) = 1]:
    
    sol := dsolve(Sys, numeric, range = 0 .. 20, output = listprocedure):
    
    TT1, TT2 := op(subs(sol, [T1(t), T2(t)])):
    
    fp := t -> plots:-display(
              pointplot([sin(TT1(t))+sin(TT2(t)), -cos(TT1(t))-cos(TT2(t))],
                        color = red, symbol = solidcircle, symbolsize = 25),
              pointplot([sin(TT1(t)), -cos(TT1(t))],
                        color = blue, symbol = solidcircle, symbolsize = 25),
              plottools:-line([0,0],[sin(TT1(t)), -cos(TT1(t))]),
              plottools:-line([sin(TT1(t)), -cos(TT1(t))],
                              [sin(TT1(t))+sin(TT2(t)), -cos(TT1(t))-cos(TT2(t))]),
              scaling=constrained
           ):
    
    animate(fp, [t], t=0..10, frames=200);
    

    enter image description here

    I don't know whether this kind of stacked view is what you're after, as a representation of the position of "both" masses. It's not really clear what you mean by that.

    But perhaps the key thing is that, if the two-element lists you are using within your pointplot calls represent (displacement) vectors, then you can get the stacked/cumulative effect on the second mass by adding those two vectors elementwise. That's how the red point gets its position in my animation. Hopefully this will allow you to get the cumulative effect with both masses, in your own choice of representation.