Legal Notice, Disclaimer, and Book Ordering Information:

(* Legal Notice, Disclaimer, and Book Ordering Information:

Last Modified: FIO January 1, 1995

Mathematica For Physics
Robert L. Zimmerman and Fredrick I. Olness
MathSource Number: 0206-862 

ISBN 0-201-53796-6
For ordering information, call 1-800-822-6339
Addison-Wesley Publishing Company

Communication with the authors:
Fredrick I. Olness:  olness@mail.physics.smu.edu
Robert L. Zimmerman: bob@zim.uoregon.edu

Copyright 1995, Addison-Wesley Publishing Company, Inc. The material in
this file may be distributed freely  so long as the content remains
unchanged, and the copyright and  reference notices are included. The
publisher grants permission for the noncommercial use of these programs
and program segments.  All other uses require the prior written consent
of the publisher.    

All rights are reserved with regard to the  material in the
"Mathematica For Physics" text, and may not be reproduced, stored in a
retrieval system, or transmitted,  in any form or by any means,
electronic, mechanical, photocopying,  recording, or otherwise, without
the prior written permission  of the publisher. 

The programs and applications presented in this book have been included
for  their instructional value. They have been tested with care but are
not  guaranteed for any particular purpose. The publisher does not
offer any  warranties or representations, nor does it accept any
liabilities with  respect to the programs or applications. 

 *)

Chapter 4, Section 3, Problem 3:   
Spherical Pendulum  and Hamilton's Equations

<<mainDir:subDir:ch4init.m  (* Mac  Version *)

<<mainDir/subDir/ch4init.m  (* Unix Version *)

Solution

Clear["Global`*"];

T= m/2 Len^2 ( theta'[t]^2 
              + Sin[theta[t]]^2 phi'[t]^2);
V= m g Len (1 - Cos[theta[t]]);
L= T - V;

{prule,ham,eqMotion}= 
   Hamilton[L,{theta,phi},{ptheta,pphi},t];

eqMotion

eqMotion=eqMotion //.{pphi->(pphi0&)}

eqMotion[[{1,3}]]

pthetaRule= eqMotion[[1]] //ToRules

eq1= ((eqMotion[[3]]  //Map[D[#,t]&,#]&) 
                      //.pthetaRule
                      //ExpandAll
                      //Simplify
                     )

(( eq1 // Map[Series[#,{theta[t],0,1}]&,#]&  
      ) //.{pphi0->0} 
        //Normal
      )

pert= ( diffSeriesOne[eq1,theta,t,6
            ,{theta[0]->theta0,theta'[0]->0}]
        //Simplify
      );

pert + O[t]^3

values={g->1,m->1,Len->1};

initial={theta[0]==Pi/4, theta'[0]==0};

ndsol1= 
NDSolve[Join[{eq1},initial] //.values //.{pphi0->0}
                        ,{theta},{t,0,8}][[1]];
theta1[t_]=theta[t] //.ndsol1;
theta1[3.4]

ndsol2= 
NDSolve[Join[{eq1},initial] //.values //.{pphi0->0.2}
                        ,{theta},{t,0,8}][[1]];
theta2[t_]=theta[t] //.ndsol2;
theta2[3.4]

theta3[t_]= ( pert //.values 
                   //.{theta0->Pi/4, pphi0->0.2} 
                   //N 
                   //Normal
                )

theta4[t_]= theta0 Cos[t] //.{theta0->Pi/4}

Plot[{theta1[t], theta2[t], theta3[t], theta4[t]} //Evaluate
         ,{t,0,8}
         ,PlotStyle->{  
             {Dashing[{1.00,0.00}],Thickness[0.010]}
            ,{Dashing[{0.08,0.01}],Thickness[0.008]}
            ,{Dashing[{0.06,0.02}],Thickness[0.006]}
            ,{Dashing[{1   ,0   }],Thickness[0.002]} }
         ,Frame->True
         ,GridLines->Automatic
         ,PlotRange->{-1, 1}
   ];