Message Boards Message Boards

0
|
4994 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

I want to be able to add in a second object into the same animation frame.

Posted 5 years ago

I want to be able to add a second pendulum with independent initial conditions, but at the same time I want it to run on the same frame so I can compare the two systems. Everything that I have tried so far hasn't worked for me. Here is my code, I will attach the file as well. Needs["VariationalMethods`"]

Clear[s1, s2, [Phi]1, [Phi]2, t, g, m1, m2]; variables = {[Phi]1[t], [Phi]2[t]}; r1 = s1 {Sin[[Phi]1[t]], -Cos[[Phi]1[t]]}; r2 = r1 + s2 {Sin[[Phi]2[t]], -Cos[[Phi]2[t]]};

lagrangian = m1/2 D[r1, t].D[r1, t] + m2/2 D[r2, t].D[r2, t] - g {0, 1}.(m1 r1 + m2 r2); eqs = EulerEquations[lagrangian, variables, t];

s1 = 1; s2 = 1; m1 = 1; m2 = 1; g = 9.81; tMax = 30; initial = {[Phi]1[0] == Pi/2, [Phi]2[0] == Pi/2, [Phi]1'[0] == Pi/2, [Phi]2'[0] == 0}; sol = First[NDSolve[Join[eqs, initial], variables, {t, 0, tMax}]]; nFrames = 1000; frames = Table[ Graphics[{Gray, Thick, Line[{{0, 0}, r1, r2}], Darker[Black], Disk[{0, 0}, .1], Darker[Black], Disk[r1, m1/10], Disk[r2, m2/10]} /. sol, PlotRange -> {{-2.5, 2.5}, {-2.5, 2.5}}, Background -> Lighter[White]], {t, tMax/nFrames, tMax, tMax/nFrames}]; ListAnimate[frames]

Attachments:
POSTED BY: Rudin Kraja

You can animate two plots side-by-side for example with Row:

Animate[Row[{Graphics[Point[AngleVector[t]], PlotRange -> 1.1, 
    Frame -> True], 
   Graphics[Point[AngleVector[2 t]], PlotRange -> 1.1, 
    Frame -> True]}], {t, 0, 2 Pi, Pi/100}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract