(*^ ::[ Information = "This is a Mathematica Notebook file. It contains ASCII text, and can be transferred by email, ftp, or other text-file transfer utility. It should be read or edited using a copy of Mathematica or MathReader. If you received this as email, use your mail application or copy/paste to save everything from the line containing (*^ down to the line containing ^*) into a plain text file. On some systems you may have to give the file a name ending with ".ma" to allow Mathematica to recognize it as a Notebook. The line below identifies what version of Mathematica created this file, but it can be opened using any other version as well."; FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2"; MacintoshStandardFontEncoding; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times"; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times"; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times"; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times"; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times"; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times"; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, ""; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = input, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, 12, "Courier"; fontset = output, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-4, 12, "Courier"; fontset = message, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier"; fontset = print, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier"; fontset = info, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, 12, "Courier"; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakBelow, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier"; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Times"; fontset = header, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, ""; fontset = leftheader, inactive, L2, 12, "Times"; fontset = footer, inactive, nohscroll, noKeepOnOnePage, preserveAspect, center, M7, 12, ""; fontset = leftfooter, inactive, L2, 12, "Times"; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, ""; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Courier"; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 14, "Times"; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, ""; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, ""; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, ""; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, ""; paletteColors = 128; automaticGrouping; currentKernel; ] :[font = title; inactive; preserveAspect; startGroup] Example 11 Symbolic and Numerical Solutions to Differential Equations II :[font = subsubtitle; inactive; preserveAspect] Copyright ã 1993 by Bill Titus, Carleton College, Department of Physics and Astronomy, Northfield, MN 55057-4025 September 6, 1993 ;[s] 3:0,0;10,1;11,0;133,-1; 2:2,16,12,Times,2,14,0,0,0;1,16,12,Symbol,0,14,0,0,0; :[font = section; inactive; preserveAspect; startGroup] Topics and Skills :[font = special1; inactive; preserveAspect; endGroup] 1. Packages: general information and loading packages with Needs[]. 2. Manipulating complex exponentials: ComplexToTrig[] in the package "Algebra`Trigonometry`". 3. ParametricPlot3D[]. ;[s] 9:0,0;62,1;69,0;111,1;126,0;144,1;167,0;173,1;191,0;193,-1; 2:5,16,12,Times,0,14,0,0,0;4,15,11,Courier,0,14,0,0,0; :[font = section; inactive; preserveAspect; startGroup] Problem :[font = special1; inactive; preserveAspect] 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. :[font = special1; inactive; preserveAspect; endGroup] 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. :[font = section; inactive; preserveAspect; startGroup] Solution - Part a :[font = subsection; inactive; preserveAspect] Step 1 - Find the symbolic solution to the DEQ of the SHO without specifying any initial conditions. Call your result soln1. ;[s] 3:0,0;120,1;125,0;127,-1; 2:2,16,12,Times,1,14,0,0,0;1,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 1 :[font = special1; inactive; preserveAspect; endGroup] 1. Note that the solution is given in terms of complex exponentials. Why? :[font = subsection; inactive; preserveAspect] 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. ;[s] 9:0,0;63,1;73,0;80,1;91,0;123,1;131,0;187,1;192,0;195,-1; 2:5,16,12,Times,1,14,0,0,0;4,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 2 :[font = special1; inactive; preserveAspect; endGroup] 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. ;[s] 13:0,0;244,1;259,0;527,1;529,0;660,2;698,0;801,1;808,0;885,1;900,0;918,1;941,0;1029,-1; 3:7,16,12,Times,0,14,0,0,0;5,15,11,Courier,0,14,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = subsection; inactive; preserveAspect] 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[]. ;[s] 7:0,0;28,1;51,0;97,1;104,0;213,1;228,0;230,-1; 2:4,16,12,Times,1,14,0,0,0;3,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 3 :[font = special1; inactive; preserveAspect; endGroup] 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[]? ;[s] 7:0,0;75,1;90,0;132,1;155,0;213,1;221,0;223,-1; 2:4,16,12,Times,0,14,0,0,0;3,15,11,Courier,0,14,0,0,0; :[font = subsection; inactive; preserveAspect] Step 4 - Find out what other functions exist in the package you just loaded by typing in ?Algebra`Trigonometry`* . ;[s] 3:0,0;90,1;113,0;116,-1; 2:2,16,12,Times,1,14,0,0,0;1,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 4 :[font = special1; inactive; preserveAspect; endGroup] 1. Does the notation for the above help command make sense? :[font = subsection; inactive; preserveAspect] 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. ;[s] 13:0,0;16,1;31,0;42,1;47,0;55,1;60,0;79,1;89,0;180,1;185,0;192,1;197,0;214,-1; 2:7,16,12,Times,1,14,0,0,0;6,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect] 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. ;[s] 11:0,0;71,1;114,0;150,1;160,0;167,1;177,0;198,1;203,0;326,1;331,0;333,-1; 2:6,16,12,Times,1,14,0,0,0;5,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 6 :[font = special1; inactive; preserveAspect; endGroup] 1. DSolve[] doesn't seen to work with coupled differential equations other than first order. ;[s] 3:0,0;4,1;13,0;94,-1; 2:2,16,12,Times,0,14,0,0,0;1,15,11,Courier,0,14,0,0,0; :[font = subsection; inactive; preserveAspect; plain] 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. ;[s] 9:0,0;41,1;46,0;69,1;83,0;174,1;180,0;247,1;263,0;417,-1; 2:5,16,12,Times,1,14,0,0,0;4,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 7 :[font = special1; inactive; preserveAspect; endGroup] 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? ;[s] 7:0,0;85,1;96,0;102,1;103,0;109,1;118,0;184,-1; 2:4,16,12,Times,0,14,0,0,0;3,15,11,Courier,0,14,0,0,0; :[font = subsection; inactive; preserveAspect] 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. :[font = subsection; inactive; preserveAspect; startGroup] Comment 8 :[font = special1; inactive; preserveAspect; endGroup] 1. You may need to resize the plot to make it look nicer. Do so by disabling the setting Graph \ Preserve aspect ratio. ;[s] 3:0,0;92,1;121,0;123,-1; 2:2,16,12,Times,0,14,0,0,0;1,15,11,Helvetica,0,14,0,0,0; :[font = subsection; inactive; preserveAspect] Step 9 - Look at the options for ParametricPlot3D[]. Find the one that will allow you to look at the plot from different view points. ;[s] 3:0,0;34,1;52,0;136,-1; 2:2,16,12,Times,1,14,0,0,0;1,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 9 :[font = special1; inactive; preserveAspect; endGroup] 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. ;[s] 3:0,0;102,1;111,0;182,-1; 2:2,16,12,Times,0,14,0,0,0;1,15,11,Courier,0,14,0,0,0; :[font = subsection; inactive; preserveAspect] 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. ;[s] 3:0,0;26,1;35,0;149,-1; 2:2,16,12,Times,1,14,0,0,0;1,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 11 :[font = special1; inactive; preserveAspect; endGroup] 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. ;[s] 3:0,0;9,1;18,0;238,-1; 2:2,16,12,Times,0,14,0,0,0;1,15,11,Courier,0,14,0,0,0; :[font = subsection; inactive; preserveAspect; endGroup] 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 your results. ;[s] 15:0,0;37,1;54,0;145,2;190,0;278,2;284,0;290,2;295,0;320,2;329,0;366,1;382,0;403,2;410,0;426,-1; 3:8,16,12,Times,1,14,0,0,0;2,15,11,Courier,1,14,0,0,0;5,15,11,Helvetica,1,14,0,0,0; :[font = section; inactive; preserveAspect; startGroup] Solution - Part b :[font = subsection; inactive; preserveAspect] 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. ;[s] 3:0,0;210,1;215,0;217,-1; 2:2,16,12,Times,1,14,0,0,0;1,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; startGroup] Comment 1 :[font = special1; inactive; preserveAspect; endGroup] 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. ;[s] 3:0,0;153,1;175,0;192,-1; 2:2,16,12,Times,0,14,0,0,0;1,16,12,Times,2,14,0,0,0; :[font = subsection; inactive; preserveAspect] 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. ;[s] 5:0,0;43,1;52,0;151,1;156,0;158,-1; 2:3,16,12,Times,1,14,0,0,0;2,15,11,Courier,1,14,0,0,0; :[font = subsection; inactive; preserveAspect; endGroup] 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. :[font = section; inactive; preserveAspect; startGroup] Save Your Notebook :[font = special1; inactive; preserveAspect; endGroup; endGroup] Remove any output cells from this notebook and then use Save As to store your notebook under the name myEx11. ;[s] 5:0,0;57,1;64,0;105,1;111,0;113,-1; 2:3,16,12,Times,0,14,0,0,0;2,15,11,Helvetica,0,14,0,0,0; ^*)