1
$\begingroup$

Double pendulum simulation

equations = 
  {x1''[t] = -(alpha'[t])^2*l1*sin[alpha[t]] + alpha''[t]*l1*cos[alpha[t]],
   y1''[t] = (alpha'[t])^2*l1*cos[alpha[t]] + alpha''[t]*l1*sin[alpha[t]],
   x2''[t] = x1''[t] - (beta'[t])^2*l2*sin[beta[t]] + beta''[t]*l2*cos[beta[t]],
   y2''[t] = y1''[t] + (beta'[t])^2*l2*cos[beta[t]] + beta''[t]*l2*sin[beta[t]]};

lcond = 
  {(x1)^2[t] + (y1[t])^2 = l1^2, 
   (x2[t] - x1[t])^2 + (y2[t] - y1[t])^2 = l2^2};
    
begin = 
  {x1[0] == 2, y1[0] == 0, y1'[0] == 0, x2[0] == 2, y2[0] == 2, y2'[0] == 0};

jie = 
  NDSolve[
   {equations, lcond, begin}, 
   {x1[t], y1[t], x2[t], y2[t], alpha[t], beta[t]}, {t, 0, 15}]

NDSolve::deqn: Equation or list of equations expected instead of -3 sin[alpha[t]] (alpha^′)[t]^2+3 cos[alpha[t]] (alpha^′′)[t] in the first argument {{-3 sin[alpha[t]] (alpha^′)[t]^2+3 cos[alpha[t]] (alpha^′′)[t],3 cos[alpha[t]] (alpha^′)[t]^2+3 sin[alpha[t]] (alpha^′′)[t],-3 sin[alpha[t]] (alpha^′)[t]^2-2 sin[beta[t]] (beta^′)[t]^2+3 cos[alpha[t]] (alpha^′′)[t]+2 cos[beta[t]] (beta^′′)[t],3 cos[alpha[t]] (alpha^′)[t]^2+2 cos[beta[t]] (beta^′)[t]^2+3 sin[alpha[t]] (alpha^′′)[t]+2 sin[beta[t]] (beta^′′)[t]},{9,4},{(3 sin alpha[t])[0]==2,(-3 cos alpha[t])[0]==0,((-3 cos alpha[t])^′)[0]==0,(3 sin alpha[t]+2 sin beta[t])[0]==2,(-3 cos alpha[t]-2 cos beta[t])[0]==2,((-3 cos alpha[t]-2 cos beta[t])^′)[0]==0}}.**

$\endgroup$
3
  • 4
    $\begingroup$ All built ins in Mathematica start with a capital letter. So Sin[...] and Cos[...] etc for starters. Then equations are entered with the Equal sign (==, a double equal). The single equal corresponds to assignment. Once you make those changes, quit the kernel and restart it to clear all your mistaken definitions (e.g. Quit[] or ClearAll[“Global`*”]. $\endgroup$ – MarcoB Jan 21 at 13:43
  • 1
    $\begingroup$ Possible duplicates: (40314), (46214). The first is standard answer when deqn comes up in NDSolve or DSolve. In addition to Marco's suggestion, you might need to do Clear[Derivative]. $\endgroup$ – Michael E2 Jan 21 at 14:35
  • 2
    $\begingroup$ If you correct all the syntax errors, you will see, that the second, third and fourth equations are tautologies, that is they give no information. $\endgroup$ – Daniel Huber Jan 21 at 15:12
2
$\begingroup$

A double pendulum is defined as mass: m1 hanging from a cord with length: l1. A second cord of length: l2 with a mass : m2 is attached to m1. The whole arrangement moves under the effect of gravitation.

The equations for the movement may be obtained by the Lagrange formalism. For this, we choose as independent variables the angles ph1 and ph2 between the vertical and l1 and l2.

eq = {

ph1''[t] + g/l1 Sin[ph1[t]] + 
     m2/(m1 + m2) l2/
       l1 (Cos[ph2[t] - ph1[t]] ph2''[t] - 
        Sin[ph2[t] - ph1[t]] ph2'[t]^2) == 0,

   ph2''[t] + g/l2 Sin[ph2[t]] + 
     l2/l1 (Cos[ph2[t] - ph1[t]] ph1''[t] - 
        Sin[ph2[t] - ph1[t]] ph1'[t]^2) == 0

   };

For an example the following parameter and initial values are chosen. Please play with the parameters to investigating interesting behaviors of the double pendulum:

l1 = l2 = 1;
m1 = m2 = 1;
tmax = 10; 
g = 9.81;
ini = {ph1[0] == 0, ph2[0] == Pi/2, ph1'[0] == 0, ph2'[0] == 0};

With this data, the equations are solved and drawn:

{sol1[t_], sol2[t_]} = {ph1[t], ph2[t]} /. 
   NDSolve[{eq, ini}, {ph1, ph2}, {t, 0, tmax}][[1]];

Manipulate[
 p1 = l1 {Sin[sol1[t]], -Cos[sol1[t]]};
 p2 = p1 + l2 {Sin[sol2[t]], -Cos[sol2[t]]};
 Graphics[{
   PointSize[0.05], Point[{p1, p2}],
   Line[{{{0, 0}, p1}, {p1, p2}, {{-l1 - l2, 0}, {l1 + l2, 0}}}]
   }, PlotRange -> {1.1 {-l1 - l2, l1 + l2}, 1.1 {-l1 - l2, 0}}]
 , {t, 0, tmax}, AutorunSequencing -> {1}]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.