Example 11
Symbolic and Numerical Solutions to 
Differential Equations II

Copyright „ 1993 by Bill Titus, Carleton College, 
Department of Physics and Astronomy, Northfield, MN  55057-4025
September 6, 1993

Topics and Skills

1.  Packages:  general information and loading packages with  Needs[].
2.  Manipulating complex exponentials:  ComplexToTrig[]  in the package  "Algebra`Trigonometry`".
3.  ParametricPlot3D[].

Problem

a.  Find the symbolic solution to the DEQ for the simple harmonic oscillator (SHO) with angular frequency  w.  In particular, solve the equation first as a second order DEQ, and then as a set to two, coupled first order DEQs.

b.  Find the solution to the simple harmonic oscillator when there's an additional damping term present that's proportional to the oscillator's velocity.

Solution - Part a

Step 1 - Find the symbolic solution to the DEQ of the SHO without specifying any initial conditions.  Call your result  soln1.

Comment 1

1.  Note that the solution is given in terms of complex exponentials.  Why?

Step 2 - Repeat Step 1, but now specify the initial conditions
x[0] == xo  and  x'[0] == vo  by placing these equations in DSolve[]'s equation list along with the DEQ.  Call the result   soln2.

Comment 2

1.  The results are still in terms of complex exponentials.
2.  Did you line up your equations to make them easier to read?
3.  It would be nice to convert the complex exponentials to trigonometric functions.  You can do that with the command  ComplexToTrig[].  However, this function is not yet loaded.
4.  There are a large number of functions written in MMA's own programming language which extends MMA's default library of functions.  These functions are in packages, where each package is associated with a file having a  .m  extension. 
5.  There is a list of packages in Appendix D of Blachman and more detailed information in the MMA Technical Report, Guide to Standard Mathematica Packages. 
6.  You access these additional functions by first loading specific packages with the MMA function  Needs[], the argument of which is the "context" for the package.  For the function  ComplexToTrig[], the context is  "Algebra`Trigonometry`".  You may want to think of the context as a directory containing the various packages.

Step 3 -  Load the package  "Algebra`Trigonometry`"  by placing this context as the argument in  Needs[].  You'll need to include the double quotes in the argument.  Then find out what you can about the function  ComplexToTrig[].

Comment 3

1.  What problems might have occurred if you had defined your own function ComplexToTrig[]  before loading the one from the package "Algebra`Trigonometry`"?
2.  How could you avoid this problem?  Hint:  remember  Remove[]?

Step 4 - Find out what other functions exist in the package you just loaded by typing in  ?Algebra`Trigonometry`* .

Comment 4

1.  Does the notation for the above help command make sense?

Step 5 - Apply  ComplexToTrig[]  to both  soln1  and   soln2,  and then apply  Simplify[]  to your results to make them look nicer, using postfix notation.  Call your new results  soln3  and  soln4, respectively.

Step 6 - Now solve the SHO as a coupled set of first order DEQ

       dv[t]/dt == -w^2 x[t]
   dx[t]/dt == v[t] 

subject to the initial conditions  x[0] == xo  and  v[0] == vo.  Call the result   soln5.  Then convert your solutions to trig functions, simplify the expressions as much as possible, and call the final result  soln6.

Comment 6

1.  DSolve[] doesn't seen to work with coupled differential equations other than first order.

Step 7 - Using the appropriate parts of  soln6  (like, for example,  soln6[[1,1,2]]), create position and velocity functions that depend on  t,  w,  xo,  and  vo.  Then use  Plot[]  to display  x[t] and  v[t]  as functions of time.  Finally, use  ParametricPlot[]  to draw a phase plot, i.e,  a plot of  x[t]  versus  v[t].   For plotting purposes, assume that  w = 1.0,   xo = 1.0,   vo = 0.0,  and  0.0 < t < 10.0.

Comment 7

1.  If your phase plot doesn't look like a circle, make it so by setting the option  AspectRatio  to  1  or  Automatic.  What do you think is the difference between these two options?

Step 8 - Create an extended phase space plot by including a third axis that corresponds to time.  What command do you think would plot this type of three dimensional, parametric curve?  Find the command and create the plot.  However, to begin with, don't use any plot options.

Comment 8

1.  You may need to resize the plot to make it look nicer.  Do so by disabling the setting  Graph \ Preserve aspect ratio.

Step 9 - Look at the options for  ParametricPlot3D[].  Find the one that will allow you to look at the plot from different view points.

Comment 9

1.  Many of the options should look familiar.  Where have you seen them before?
2.  Not surprisingly, ViewPoint  is the option that affects the view from which the plot is observed.

Step 10 - Find out about  ViewPoint  and use it to look at your plot from different angles.  Also, label your axes using an appropriate plot option.

Comment 11

1.  The  ViewPoint  coordinates are relative to the center of the box, and are scaled so that the longest side of the box corresponds to one unit.
2.  MMA can determine viewpoints automatically for you through its 3D ViewPoint Selector.

Step 12 - Position your curor in your ParametricPlot[]  command just before the final left bracket of the command.  Then select the menu item    Action \ PrepareInput \ 3D ViewPoint Selector   and rotate the 3D box until you get a view of the plot that appeals to you.   Press  Insert  or  Paste  and the corresponding  ViewPoint  option will be inserted into your  ParametricPlot[]  command.  Finally  <Enter>  your results.

Solution - Part b

Step 1 - Solve the damped SHO for the position and velocity as functions of time for initial conditions  x[0] = xo  and  v[0] = vo.  Do this by solving a set of two, first order coupled DEQ.  Call your result  soln7.

Comment 1

1.  Why are the solutions so ugly?  
2.  Can you simplify the solutions?  Would you want to?
3.  For simplification techniques, see Abell and Braselton, Mathematica by Example, pp. 429 - 434.

Step 2 - Solve the DSHO numerically using  NDSolve[].  Assume that  xo = 1.0,  vo = 0.0,  w = 1.0,   b = 0.3,  and  0.0 < t < 20.0.  Call your result  soln8.

Step 3 - Create velocity and position functions and use them to produce the same type of two dimensional plots as you did for the SHO.

Save Your Notebook

Remove any output cells from this notebook and then use  Save As  to store your notebook under the name  myEx11.