Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Line changes length in animation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109333] Line changes length in animation
  • From: Jens-Christian Underberg <mail at example.invalid>
  • Date: Thu, 22 Apr 2010 03:31:05 -0400 (EDT)

Hello,

I have two problems with the attached code simulateing a chaotic pendulum.

The first one seems easy: the replacement by sol doesn't seem to work 
and I cannot see why.

Without the Module I got it working, but another strange problem: In the 
animation, the length of the pendulum changes, although that is not 
explicable by numeric errors, since the Lagrange equations only give 
angles. The length is given bei the constraints ...

Does anyone have any idea?


Best regards
Jens-Christian

Pendel[Theta1_, Theta2_, Theta3_, Theta1p_, Theta2p_, Theta3p_, l1_,
   l2_, l3_, m1_, m2_, m3_, g_, tmax_] :=
  Module[{EQ1, EQ2, EQ3, length, params, x1, x2, x3, z1, z2, z3, L, L2,
     Pendel1, Pendel2, Pendel3},
   L[z1_, z2_, z3_, x1p_, x2p_, x3p_, z1p_, z2p_, z3p_] =
    1/2 m1 (x1p2 + z1p2) + 1/2 m2 (x2p2 + z2p2) +
     1/2*m3*(x3p2 + z3p2) + m1*g*z1 + m2*g*z2 + m2*g*z3;
   x1[t_ ] = l1*Sin[\[Theta]1[t]];
   z1[t_] = l1*Cos[\[Theta]1[t]];
   x2[t_] = x1[t] + l2*Sin[\[Theta]2[t]];
   z2[t_] = z1[t] + l2*Cos[\[Theta]2[t]];
   x3[t_] = x1[t] + x2[t] + l3*Sin[\[Theta]3[t]];
   z3[t_] = z1[t] + z2[t] + l3*Cos[\[Theta]3[t]];
   L2 = L[ z1[t], z2[t], z3[t], x1'[t], x2'[t], x3'[t], z1'[t], z2'[t],
      z3'[t]];
   EQ1 = D[D[L2, \[Theta]1'[t]], t] - D[L2, \[Theta]1[t]] == 0;
   EQ2 = D[D[L2, \[Theta]2'[t]], t] - D[L2, \[Theta]2[t]] == 0;
   EQ3 = D[D[L2, \[Theta]3'[t]], t] - D[L2, \[Theta]3[t]] == 0;
   sol = NDSolve[{\[Theta]1[0] == Theta1, \[Theta]2[0] ==
        Theta2, \[Theta]3[0] == Theta3, \[Theta]1'[0] ==
        Theta1p, \[Theta]2'[0] == Theta2p, \[Theta]3'[0] == Theta3p,
       EQ1, EQ2, EQ3} , {\[Theta]1[t], \[Theta]2[t], \[Theta]3[t]}, {t,
        0, tmax}, MaxSteps -> 109, MaxStepSize -> 0.001]  // Flatten;
   Pendel1[t_] = ({x1[t], -z1[t]} /. sol) ;
   Pendel2[t_] =  ({x2[t], -z2[t]} /. sol) ;
   Pendel3[t_] =  ({x3[t], -z3[t]} /. sol) ;
   length = 2*(l1 + l2 + l3) ;
   Animate[
    Show[ParametricPlot[Pendel3[s], {s, 0, t},
      PlotRange -> {{-length, length}, {-length, length}}],
     Graphics[{Line[{{0, 0}, Pendel1[t], Pendel2[t], Pendel3[t]}],
       Disk[Pendel1[t], Sqrt[m1]/5], Disk[Pendel2[t], Sqrt[m2]/5],
       Disk[Pendel3[t], Sqrt[m3]/5]},
      PlotRange -> {{-length, length}, {-length, length}}]], {t, 0,
     tmax, 0.001}, AnimationRate -> 0.7] ]

Pendel[Pi/2, 0.3, 0.3, 0, 0, 0, 2, 1, 1, 1, 1, 1, 2, 70]


  • Prev by Date: Re: Button Problem
  • Next by Date: NDSolve cannot solve set of ODEs
  • Previous by thread: Re: Download as Live Mathematica from Wolfram|Alpha
  • Next by thread: NDSolve cannot solve set of ODEs