Introduction to MapleFor Physics StudentsMaple 9.5 Ross L. SpencerBrigham Young UniversityCopyright 2004Ross L. Spencer and Brigham Young University<Text-field bookmark="Introduction" layout="_pstyle5" style="_pstyle5">Introduction</Text-field>This course is a laboratory in the use of the Maple computer mathematics program to do physics. With the advent of fast and cheap computers, programs like Maple will replace hand calculators and mathematical handbooks (like integral tables) for most physics students. This was already happening in our department in a somewhat random way, so this course was invented to provide students with a systematic introduction to the use of this powerful program. Once you learn it you will be hooked and you will wonder how you ever got along without it, especially if you have Maple on your own computer. And since Maple is cheap while you are a student, you ought to consider buying your own copy. Here's how the course will run. You and a lab partner will work through the chapters in this notebook at your own speed, assisted by the instructor and the TAs. The assigned problems for each 3-hour laboratory period are given in the last chapter of this book ( Laboratory assignments ). The only lectures will be answers to questions that are a little involved. There are no exams and no written homework. When you have finished an assigned problem, call a TA over and show them what you have done. Then go on to the next one. For Physics 230 there are three term projects required, but they are relatively simple: I want you to work three significant homework problems from math or physics courses that you are taking using a Maple worksheet. It would be a good idea to check with a TA or the instructor ahead of time to see if we think the problem is significant. You will get extra points for degree of difficulty. Special note: do not do your homework in this notebook. Every once in a while I will make changes to this notebook and give you a new copy to use. The new edition will be worthless to you if all of your hard work is in the old version. So do all of your work in another file and leave this one the way you got it. A nice way to handle this is to have both this worksheet and your problem worksheet open simultaneously; then use the Tile, Horizontal, or Vertical option under Window on the toolbar (you get to choose which you like the best). Then you can read this worksheet and your problem worksheet on the same screen. This makes copying with the mouse from here to your assignment especially easy and you can read about what should be happening in the text while seeing what is actually happening in your own work. You will be glad if you save your solutions to the problems in this text. You will find that your worked examples from this course will be of great value when you encounter similar problems in later courses.This is a rather large piece of computer text and it is easy to lose track of things you might see once and want to find later. To help with this problem there is an index of hyperlinks to Maple topics in the next section. In addition you can find specific words or phrases in this text by using the Find selection under the Edit item on the toolbar. And when things go wrong there are two debugging sections in this text. One is in Chapter 1 where debugging is introduced. The second is after Chapter 9 where specific errors and their cures are illustrated and discussed. To help you quickly go to this second debugging section there is a hyperlink to it in almost every subsection of the worksheet. And to help you go back to where you came from there is a set of chapter hyperlinks at the top of the debugging section. So if you need to quickly go to another chapter, first go to the debugging section, then click on the desired chapter hyperlink. Here, I'll show you. Go to the View menu on the tool bar and select Expand All Sections. (This is annoying, but due to a bug in Maple 9.5 hyperlinks in documents containing sections and subsections don't work unless the document is completely expanded. Hopefully this bug will be fixed in a later edition.) Then click here on Debugging to go to the debugging section. Click there on Using hyperlinks to come back to this paragraph.Finally, please contact me about errors in the text or trouble with Maple. The text errors I will fix and the Maple troubles will be added to the Debugging section at the end of the book. My email address is ross_spencer@byu.edu.<Text-field bookmark="Index" layout="_pstyle5" style="_pstyle5">Index</Text-field>This is an index of links to various topics within each Chapter of this text. If you click on anything printed in this color, e.g., Index , you will go to that place in the worksheet, provided that you have expanded all of the sections in the worksheet by going to the View menu on the toolbar and selecting Expand All Sections. This is an inconvenient bug in Maple which will hopefully be fixed in the next version. A further note of warning: when the hyperlink goes to a topic in a closed section of the worksheet it sometimes goes to the top of the section instead of to the requested topic. Just press the down arrow key and it should go to the topic, or go back up to the index and click on the topic again.You can also find specific phrases in this worksheet by using the Find command under Edit on the toolbar. (But be careful--when the Find command encounters what you are looking for in a subsection it sometimes opens the subsection and stops at the top of it. Click on Next to go to the item you are looking for.) And for help on Maple topics in general you can either use Help on the toolbar or ?topic, e.g. ?solve in an execution group.
Chapter 1: Getting startedAlgebra Debugging with assumeDebugging with evalfDebugging with plotDebugging with restartDerivativesDigitsEditing text and Maple commandsExecution groupsExpressions and functionsFloating point numbersGetting a numerical answerGreek lettersInserting textInserting math within textIntegralsLists and setsMatrices and vectorsNaming variablesOnline helpParagraphsPlotsSequencesSolving equationsSolving differential equationsSpecial constantsStringsSumming a seriesTaylor seriesUgly variable namesWorksheet guide= versus :=; and :Chapter 2: PlottingAnimationsBeatsBessel functions: J, Y, I, and KContour plotData: reading and plottingEllipses, hyperbolas, and parabolasElliptic integrals: K(k) and E(k)Error function: erfFourier sumsGamma functionGroup VelocityLegendre polynomialsParametric plotsPhase velocitySeqSinh, cosh, and tanhUncertainty principleWave packetsWave packet spreadingxy plotsVector field plots3d plotChapter 3: CalculusAliasAsymptotic seriesBessel function integralsDerivativesElectric dipoleImplicit differentiationIntegral tablesIntegrals, definiteIntegrals, doubleIntegrals, indefiniteIntegrals, tripleLegendre polynomial integralsLimitsMoment of inertiaOrthogonalityPartial derivativesPendulum periodSeries approximation, generalStudent packageSums, finite and infiniteTaylor's theorem (series)Voltage integralChapter 4: Complex numbers and functionsAdd and subtractBessel functions, complexBranch cutsConjugate, complexCosine and sine, complexElectric fields, cornersElectric fields, line chargesEuler's formulaEvalcExponential function, complexMultiply and dividePhasePolar coordinatesRaising to a power, complexRe and ImWave interferenceChapter 5: Linear algebraAdding matricesAngle between vectorsCurlDeterminantDivergenceEigenvalues and eigenvectorsGradientInvert a matrixLaplacianMaking matricesMaking vectorsMultiplying matrices, vectorsNorm or magnitudeProducts: dot and crossRotation matricesRow and Column CommandsSystem of linear equationsTraceTransposeChapter 6: Solving equationsFsolve, numerical zero finderSolve, symbolic equation solverSystems of nonlinear equationsPlotting results from fsolveZeroes of systems of nonlinear equationsZeroes of polynomialsZeroes of transcendental equationsChapter 7: Ordinary differential equations (odes)Baseball with air frictionDamped harmonic oscillatorDynamical chaosFirst order odeLorentz attractorMeaning of odesNonlinear dynamicsNumerical solution of odes Odeplot and dsolve,numericPlotting results from dsolveRhs command with dsolveSchrodingers equation, harmonic oscillatorSecond order odeShootingSpacecurve commandSystems of odesChapter 8: Programming -- logic, loops, and proceduresCubic b-splineEvalb(evaluate Boolean)If-then-elif-else-fiLogical tests (<,>,etc.)LoopLoop, break outLoop whileOp command with dsolvePiecewiseProceduresTraceChapter 9: Symbolic algebraAlgsubsCollectConfrac(continued fraction)ConvertCopy and pasteExp(exponential form)ExpandFactorMatrices and arrays of expressionsMetric(unit conversion)NormalNumer and denomOp Parfrac(partial fraction)Piecewise(convert functions)Polar(convert to polar form)Ratpoly(convert series to rational function)SimplifySimplify with side-relationsSolveSortSubs(titute)Subscripted variables, avoidingDebugging: DebuggingLaboratory assignments: Laboratory assignments<Text-field bookmark="Getting started (top)" layout="_pstyle5" style="_pstyle5">Chapter 1: Getting started</Text-field>Click on each subsection below, read and execute the Maple commands, and do the problems at the end of each one. There is a hyperlink at the top of each subsection called Debugging that will take you to the section at the end of the worksheet that discusses what errors mean and how to fix them.Before you begin, however, it will be helpful to make sure that Maple's palette menus are showing. Click on View on the toolbar at the top of the page and select Palette. Then select Show All. This will make Maple's 4 palettes show on the left side of the screen: Expression (helps you with command syntax), Symbol (Greek symbols), Matrix (help you build matrices), and Vector (helps make vectors). These palettes (especially the Expression palette) will come in handy as you learn and use Maple.Right Click: Maple's answers to the math problems you will give it will appear in blue on the screen. To see what things Maple might be able to do to this answer (integrate it, differentiate it, etc.) just right click on the blue answer and a menu of possibilities will appear. If you click on these menu items the Maple commands you need will appear in fill-in-the blank style. For example, here is the sine function. Place the cursor on the red sin(x) below and press Enter. Right click on the blue version of sin(x) that appears, select Differentiate, and then x to have Maple take its derivative with respect to x. You will also be able to see the Maple command that does the job, which will help you learn Maple syntax, and you will see that the answer will be assigned to a variable name that starts with R. You will understand this part the of the result better very soon.sin(x);<Text-field bookmark="Execution groups and paragraphs" layout="_pstyle6" style="_pstyle6">Execution groups</Text-field>DebuggingThe first thing you will notice when you turn Maple on is the square bracket on the far left and the > sign just inside it. These two symbols are the most basic parts of Maple's graphical user interface and they will drive you crazy if you don't learn to handle them well right from the start. The window space marked off by the left square bracket is called an execution group and everything happens inside these these groups. Here's what you have to know: everything before the > sign is text (or perhaps a mathematical piece of text); the red stuff on the line with > is a Maple command; and the blue stuff is the Maple result. To see an example put the cursor on the > restart; below and press Enter twice. (You will learn about restart shortly.)restart;Find the sine of NiNJI3BpRzYi divided by 4, or NiMtSSRzaW5HNiI2IyomSSNwaUdGJSIiIiIiJSEiIg==sin(Pi/4);Notice that each Maple command must end with a semicolon (in which case the answer prints in blue) or a colon (in which case the command executes, but the printing of the answer is suppressed). To see how this works, change the semicolon ; in the sin(Pi/4) line above to a colon : and see what happens when you execute the command by putting the cursor on the red command line and pressing Enter.As you can see in this text, a Maple worksheet can contain both commands and text. The purpose of the text portion is to document what you are doing. Please document your code. I will be glad you did, the grader will be glad you did, and six months from now when you remember that you once solved a problem like the one you just got assigned and you go looking for it, you will be glad you did. There are two places where you can put your comments: just before the Maple command and just after it. To place a comment just before the red command sin(x)/(1+x^2) below, put the cursor just after the ; in the line and hold down the keys Shift-Ctrl-k. A little bit of white space will open up above the command into which you can type either text or an equation. As an example, enter the following comment: This is the function NiMqJi1JJHNpbkc2JEkqcHJvdGVjdGVkR0YnSShfc3lzbGliRzYiNiNJInhHRikiIiIsJkYsRiwqJEYrIiIjRiwhIiI= . To obtain the nice fraction with NiMtSSRzaW5HNiRJKnByb3RlY3RlZEdGJkkoX3N5c2xpYkc2IjYjSSJ4R0Yo in the numerator and NiMsJiIiIkYkKiRJInhHNiIiIiNGJA== in the denominator type the text "This is the function" first, then hold down the keys Ctrl-r. A line will appear at the top of the worksheet into which you can type sin(x)/(1+x^2). This puts you into math entry mode and when you press Enter or Ctrl-t you will come back into text mode and your math expression will be nicely formatted in your comment. And if you use Shift-Ctrl-j instead, the white space for entering a comment will be below the Maple command. Try putting comments in the line below until you see how it works.sin(x)/(1+x^2);Now hang in there, you're about to actually do something real. There is an execution group just below this section of text. Put text that says Kindergarten stuff above the > sign in the first one (use Shift-Ctrl-k), hit Enter; then put 1+1 after the > sign and hit Enter again You will find that in addition to seeing the answer in blue, you also got a warning about a semicolon--always remember to end each Maple command with either a semicolon (print the answer) or a colon (don't print the answer).Maple will allow you to do more than one calculation inside an execution group. You can do this in two ways: (i) with several commands on a single line separated by semicolons, or (ii) several commands stacked vertically, each with its own >. To put extra > lines inside a single execution group make a set of separate execution groups (create them either with Ctrl-j or Ctrl-k), then combine them by putting the cursor on the first one in the set and then joining them using F4. And if you have a set of combined execution groups, you can use F3 to split them up again. (These commands are also available under Insert and Edit on the tool bar.) Take a minute now and practice splitting and joining execution groups using F3 and F4 on the combined set below.Oh, and also notice how the # symbol can be used to add brief comment lines in red right on the command line. The rule is that anything after # is a comment1+1;2+2;3+3; # three additions in a row, all on the same line1+1;2+2;3+3;If you need to delete an execution group the command Ctrl-Delete will do the job.OK, hopefully this is enough to get you around on the window. There are a lot of things that won't be mentioned here, but they are all described in online help and you can find most of them on the toolbar. This might be a good time to take a tour of the toolbar to see what's up there. Simply move the cursor across each icon to see what each one is about. And for further information on the the way the window is managed, click on Help and try the New Users tour. Problem 1.1 Make an execution group and document it before the > sign with the comment: Add the integers from 1 to 10. Then build a Maple command line to calculate the answer to 1+2+3+...+10. ------------------------------------------------------------------------------------ Go to top of section<Text-field bookmark="Worksheet guide" layout="_pstyle6" style="_pstyle6">Quick guide to managing the worksheet</Text-field>DebuggingThis is just a collection of recipes for making the worksheet look like you want it to. I have given you several control sequences here; you can also do these things from the Edit and Insert menus.Make an execution group:Ctrl-j makes one after the execution group or paragraph the cursor is in.Ctrl-k makes one before the execution group paragraph the cursor is in.Adding another > to an execution groupUse the arrow keys, or the mouse, to move the cursor just to the left of a > already in the group. Hit Enter and another one will appear just above.Make a paragraph for text inside an execution groupShift-Ctrl-j makes one after the cursor. Shift-Ctrl-k makes one before the cursor.Slip a paragraph of text between two execution groupsThis is a problem. It used to be possible to do this, and you will see lots of examples of it in this book, including right here. Notice that this text you are reading is not part of any execution group. But even though Maple still runs worksheets that have nice book-like white space in them, it seems no longer to be able to produce such space. Hopefully this will be fixed in some future version. Here is the way it used to be done before version 9:Click on the big [ at the left of the group; it will become a double line; then type Shift-Ctrl-k to get one before, Shift-Ctrl-j to get one after.Delete a paragraph or execution groupPut the cursor in the paragraph or execution group to be deleted and type Ctrl-Del. To kill everything in the execution group you may have to do this several times.Enter equations or expressions within textType Ctrl-r then watch the equation being typed in the window on the toolbar. The syntax for entering typeset mathematics is Maple's own syntax. For instance, to display the integral of the sine function from 0 to 1 you would type this: int(sin(x),x=0..1) but with Ctrl-r turned on, like this NiMtJSRpbnRHNiQtJSRzaW5HNiMlInhHL0YpOyIiISIiIg== . (Highlight this integral expression with the mouse and watch it appear as Maple code on the toolbar.) Hit Enter when it is complete, then type Ctrl-t to go back to text mode.Making Maple do it your waySuppose you want the answer to a problem to look a certain way, such as NiMqJiIiIkYkLSUlc3FydEc2IyIiIyEiIg== , for example. But when you do this in Maple it thinks this is a bad idea and does it this way instead:1/sqrt(2);You can bend Maple to your will by putting things inside single quotes, like this'1/sqrt(2)';Maple will still work with such a forced expression in the usual way.Split or join execution groupsSee the Edit menu on the toolbar. Note that F3 splits and F4 joins. You might want to practice with these two shortcuts until you see how they work. These commands are useful if you want to have several execution lines in one paragraph like this:To obtain this set make 3 execution groups using Ctrl-j and then use F4 to join them. To take them apart into separate groups again use F3.Remove all of the blue Maple output from the worksheetSee the Edit menu.Close all of the sections and subsections in a worksheetSee the bottom of the View menu on the toolbar.Removing the output and closing all of the sections fully restores this book to its original condition.Other interesting tricksExplore the toolbar and see what's up there. Of special interest are:(a) Tile in the Window menu allows you to see the worksheet and do your assignment in side-by-side windows. Cascade under Window overlays them.(b) You can get bold, italic, and underlined text with B, I, and u on the toolbar.(c) Use the magnifying glass icons on the toolbar to change the size of the type. I think everything looks better with magnification level 2.(d) Notice the curvy arrow icons on the toolbar--they undo the last operation and redo the last undo.(e) The stop sign will kill a calculation that has gone on so long you can't stand it anymore.Problem 1.2Open a new worksheet. At the top of the worksheet, in the first execution group, open up some white space and put in a bold title that says Problem 1.2. Below this title, in italics, put your name. Then create an execution group that contains four >'s instead of just one and put comment lines that say "Comment 1", "Comment 2", etc, above each of the >'s.Go to top of section<Text-field bookmark=" Online help (top)" layout="_pstyle6" style="_pstyle6">Online help</Text-field>You probably already know how to use online help in programs, so when you click on the Help icon at the top of the page you will be in familiar territory. Also remember that right clicking on blue results can help you know what your possibilities are. But there is a quicker way to get help directly at the Maple prompt: just use the question mark. For example, suppose you are pretty sure that Maple knows how to find the prime factors of big numbers, but you don't know the command. Try this.?factor;When you do you will find that this is the wrong command because it does algebra on polynomials. But if you read a bit, and look at the helpful See Also links at the bottom of the page you will see that the command you want is ifactor, so you either go there or use?ifactor;Now help will tell you that this is just what you want, and you can tryifactor(5040);You can find lots of interesting stuff in Maple this way; happy hunting. Problem 1.3 Use online help to find the Maple commands for integrating a function and for taking a derivative of a function.-----------------------------------------------------------------------Problem 1.4 Use online help to find the Maple command for taking the second derivative of a function.------------------------------------------------------------------------Go to top of section<Text-field bookmark="Special constants (top)" layout="_pstyle6" style="_pstyle6">Special constants</Text-field>DebuggingThere are several constants pre-loaded in Maple that are useful for physics. They are:Pi;I;infinity;Pi is the number NiNJI3BpRzYi to about as many significant figures as you want. To see its digits, use the Maple command evalf to convert a number to floating point formevalf(Pi,100);and you should be impressed. I is the imaginary unit, i.e., NiMvJSJJRy0lJXNxcnRHNiMsJCIiIiEiIg== ; try executingsqrt(-5);Infinity is, of course, not a number, but an idea, and only makes sense in limits. And Maple does the right thing in calculations involving limits, likelimit(exp(-x),x=infinity);orNiMtSSRTdW1HNiI2JComIiIiRigpIiIjSSJuR0YlISIiL0YrO0YoSSlpbmZpbml0eUdJKnByb3RlY3RlZEdGMA== would be evaluated like this: sum('1/2^n','n'=1..infinity);We will do more of this kind of thing in Chapter 4.Problem 1.5 Compare the Maple commands cos(pi) and cos(Pi) by trying them in an execution group. Explain why they don't behave the same way. (This issue will be discussed in more detail in the section on variable names).----------------------------------------------------Problem 1.6 Calculate the complex division problem (3+4i)/(7-6i) in a Maple execution group.----------------------------------------------------Problem 1.7 Calculate the limit, as x approaches infinity, of the expression (3-5x)/(7+3x) using a Maple execution group. ----------------------------------------------------Go to top of section<Text-field bookmark="Variable names (top)" layout="_pstyle6" style="_pstyle6">Variable names</Text-field>DebuggingLike all other modern computer languages, Maple allows you to name a variable just about anything you want, with some exceptions. In C and Fortran, for instance, you can't use "sin" as a variable name because this name is reserved for the sine function. You can probably think of other obvious reserved names like this ("cos", "tan", "log", etc.), but there are only about a hundred of these and you have the whole alphabet at your disposal, so it's not a big problem. In Maple you have to be more careful because there are about 3000 commands whose names are reserved for system use. But Maple will tell you if you have made a bad choice, and the possibilities for naming variables are still nearly endless. Now let me warn you about a bad habit into which this naming freedom seems to have led your generation of computer users. Here is how some students I have worked with would write Newton's law of universal gravitation in a computer code: Newtons_Gravitational_Constant*Mass_1*Mass_2/Distance_Between_The_Masses^2 Here is what this would look like in a Maple execution group: Newtons_Gravitational_Constant*Mass_1*Mass_2/Distance_Between_The_Masses^2; Now look; this form is certainly well documented, but you are going to spend a great deal of your life in programming typing code and reading code that has already been typed. Avoid clutter and carpal tunnel syndrome! Here's how I would suggest you write it in Maple:G*m1*m2/r12^2;I don't know the origin of the current popularity of the underscore character and capitalization in variable names, but if I were you I would use this style very sparingly, if at all. When I program I choose variable names to be as much like the symbols used in physics textbooks and research papers as possible. These would be things like a, m, F, c, q, L, h, etc. But Maple has the ability to go even further toward the standard physics style because it has Greek letters! To get them just write out their names in English, as in the example below.alpha*beta/delta;The capital Greek letters are also available, and even though some of them look like English capital letters, they are not quite the same, as you can see in the example below:Alpha*A;Beta+B;Chi/Gamma;Well, OK; not all of the Greek capital letters are produced this way. Some of them you do this way CHI;You can get all of them by creatively switching between a capital letter first and all capitals. If you persevere you can work in Maple with beautifully typeset equations just like you see in your textbooks. (And if you don't want to memorize their spellings and capitalizations use the Symbol palette on the left side of your screen, or click on View, Palettes, Symbol Palettes and you will have a table of symbols you can get with the mouse.)Note that a few are not available for your use:gamma:=4;Chi:=3;These two, and possibly others, are used by the system. It may be possible to unassign them so that they are available for your own use, but I recommend against it. The more you work strictly within the Maple system the better off you will be; or in the language of Sunday afternoon in America, "take what the defense gives you." Also avoid putting subscripts on variables, even though Maple's typesetting ability will let you do it. For instance you might want to work with the variables NiMmJSJ4RzYjIiIi and NiMmJSJ4RzYjIiIj which you can get by doing this in Maplex[1]:=1;x[2]:=2;They look great, but now watch what happens if you give NiMlInhH a value, then display NiMmJSJ4RzYjIiIix:=3;x[1];I think we can all agree that this is not going to help us do mathematics. So if you want to code NiMmJSJ4RzYjIiIi in Maple, call it x1. And as you choose variables, experiment a little with the names and try for elegance and simplicity.Problem 1.8 Set the variable theta to have the value 5/3 and then coax the Maple command NiMtJSRjb3NHNiMlJnRoZXRhRw== into giving you cos(5/3) as a floating point number.Maple will also let you put special characters in the name of a variable, but you have to use a special syntax. For example, suppose you wanted to define an expression f, then assign its derivative to the symbol f'. You would do it like this:f:=exp(y)*cos(y);`f'`:=diff(f,y);The backward quote marks around f' tell Maple that you are going to use a special character ( ' in this case) in the variable name and instructs Maple to accept this name without complaint.-----------------------------------------------------------Go to top of section<Text-field bookmark="What can a variable represent" layout="_pstyle6" style="_pstyle6">What can a variable represent?</Text-field>DebuggingIn standard computing languages like Fortran, C, and Matlab variables can only represent a limited number of different things, like integers, floating point numbers, complex numbers, and character strings, to name nearly all of them. But in Maple there are over 100 different things a variable can represent. This makes life much more complicated. For instance, in Fortran or Matlab the statement a=5would assign to the variable a the value 5. But in Maple the statementa=5;doesn't do assignment at all. Instead it is just the really stupid equation NiMvJSJhRyIiJg== . Maple is capable of solving this equation and discovering that a is 5, but it is not a statement that assigns a value to the variable a. In order that Maple be able to work directly with equations (expressions containing the symbol =), the assignment statement has been given a different form. To assign to variable NiMlImFH the value 5 the Maple statement would bea:=5;One of the clearest ways of indicating the difference is to note that the following statement in Maple makes sense:Eq:=b=5;This statement means that the variable NiMlI0VxRw== contains the equation NiMvJSJiRyIiJg== . Here's a less dumb example:Eq2:= x^2 + y^2 = R^2;Well, this probably looks a little strange; why is there a 9 instead of an x? Well, maybe there isn't, depending on how you got here, but if you get a 9 in the result of this command when you execute it, here's why. In the last section on variable names x was set to 3, and Maple remembers forever. This will bite you over and over. The quickest way to cure it if you don't care about the calculations you have done before is to just restart Maple, like this:restart;Now use the mouse to move the cursor back up to the Eq2 assignment, click on the red text, and it will execute properly. Note that this works even though the restart is below the Eq2:=... . Maple is not like C or Matlab. Order in the worksheet is not what's important--order in time spent at the keyboard is what matters.So, what are the possible things that a variable can represent? The subsections given below are a partial list of the ones you are most likely to encounter. They are just Maple examples without comment. We will discuss each one in detail sometime during the course. To get a full look at what's possible, use?typeAnd if you are confused about the type of, say, a variable named a, you can use the Maple command whattype(a).Problem 1.9 On a clean worksheet use the Maple command b:=a=5 and then use the type command to check the type of b by using the commands type(b,integer), type(b,float), and type(b,equation). Explain why the results of these three commands make sense to Maple. --------------------------------------------------------------------------------The sections below contain examples of the most important data types we will be using in this book.<Text-field layout="_pstyle10" style="_pstyle10">Complex numbers</Text-field>Note that NiMvJSJJRy0lJXNxcnRHNiMsJCIiIiEiIg== .cn1:=(1+3*I)*(5-2*I);<Text-field layout="_pstyle10" style="_pstyle10">Equations</Text-field>Eq1:=sin(x)=x;<Text-field bookmark="Floating point numbers" layout="_pstyle10" style="_pstyle10">Floating point numbers</Text-field>Maple usually keeps 10 significant figures in floating point (real number) calculations. But you can increase it by changing the value of the Maple constant Digits, like this:f1:=4./3.;Digits:=50;f1:=4./3.;Digits:=10;<Text-field bookmark="Expressions and functions" layout="_pstyle10" style="_pstyle10">Expressions and functions</Text-field>An expression looks like what you would probably call a function, but there is a subtle difference. An expression is a combination of variables and Maple functions like thisFn1:=cosh(x^3)/(1+x^2);The reason it isn't a function is because of what you have to do to evaluate it for a specific value of x: Typing Fn1(x) doesn't work! Instead you have to assign x a value like thisx:=2.;then evaluate Fn1Fn1;A Maple function is defined with this syntaxFn2:=x->cosh(x^3)/(1+x^2);This does behave like a function because you give it an argument and it gives you an answer backFn2(2.);Or you can define a function with multiple arguments like thisFn3:=(x,y,z)->x*y^2*z^3;Fn3(1,2,3);Hence, the -> function notation makes functions like you are used to from math classes. So why would you even want to mess with expressions? Because Maple often has an easier time doing algebra with them, integrating them, differentiating them, plotting them, and using them to build differential equations. So you have to get used to both. I try to remember it this way: a Maple expression looks like a function in a math book; a Maple function is a machine that takes input and gives back output.<Text-field layout="_pstyle10" style="_pstyle10">Integers</Text-field>I1:=12345678987654321;After the blue answer appears, right click on it to see what Maple can do to this number--for instance, select Integer factors and watch what happens.<Text-field layout="_pstyle10" style="_pstyle10">Matrices</Text-field>M1:=matrix([[1,2],[3,4]]);After this matrix appears in blue, right click on it and use the menu to find the eigenvalues of this matrix.<Text-field layout="_pstyle10" style="_pstyle10">Polynomials</Text-field>P1:=y^3+y^2+y-1;<Text-field bookmark="Strings" layout="_pstyle10" style="_pstyle10">Strings</Text-field>S1:="Mary had a little lamb.";<Text-field layout="_pstyle10" style="_pstyle10">Vectors</Text-field>V1:=Vector([1,2,3]);<Text-field layout="_pstyle10" style="_pstyle10">Lists and sets</Text-field>A list is a sequence of numbers, expressions, or any other legal data type enclosed in square brackets. They can be loaded either by hand or by means of the seq command.s1:=[1,2,4,6,8,12];s2:=[seq(2*n^2-3*n+2,n=1..6)];Their elements can be referred to with Maple's square bracket subscript notations1[3];s2[2..5];A set is similar to a list, but not quite. It is enclosed in curly brackets and Maple, instead of you, decides what order the elements should be listed in. The most important difference is that a list may contain repeated elements, but a set may not. Sets are often used in the arguments of Maple commands. In the example below note that the list stays the way it was defined while the set is re-ordered and reduced to unique elements.s1:=[1,3,2,6,4,3,2];s2:={1,3,2,6,4,3,2};Go to top of section<Text-field bookmark="Getting the answer" layout="_pstyle6" style="_pstyle6">Getting the answer</Text-field>DebuggingNow we have come to the second most frustrating thing about Maple: sometimes it doesn't feel like giving you the answer to your problem. Here are some examples.Suppose you want to know the sine of the number 1 (in radians; all calculus is done in radians, so forget about degrees). You might think this would work:restart;sin(1);This is not what we had in mind; we already know we want NiMtJSRzaW5HNiMiIiI= , but what is the answer? Maple is having trouble here because it doesn't think it makes sense to take the sine of an integer constant; it expects floating point numbers. See what happens with the small addition of a decimal pointsin(1.);Difficulties like this are not always so easy to fix, so Maple provides a command to take care of it: evalf. It would be used in this example this way:sin(1);evalf(%);The % sign means "the last result Maple calculated" (like Ans on some calculators). It is NiMtJSRzaW5HNiMiIiI= in this case, and evalf stands for "evaluate as a floating point number". You will be using evalf a lot because Maple will be doing its symbolic thing when you want a numeric result. It's just the price you have to pay to have a calculator that is at home in both the symbolic and numerical worlds. Warning: if you get in the habit of using % routinely, you will routinely make mistakes. Only use it sparingly. Most of the time you should assign results to variable names, then work with these names to avoid confusion, like this:s:=sin(1);evalf(s);Oh; and what's the number one most annoying thing about Maple? It doesn't give you very good error messages when you louse up. It tends either to just parrot back to you the thing you asked it to do, or it gives you gobbledygook like "Can't evaluate Boolean". But be patient; it is a great tool and it is improving all the time. It is definitely worth learning.Go to top of section<Text-field bookmark="Debugging (bad things)" layout="_pstyle6" style="_pstyle6">Debugging (when bad things happen to good programmers)</Text-field>DebuggingEverybody who writes or uses software has something in common--their programs don't work. And when this happens the most important skill you can have is the ability to find out exactly what went wrong. Here are some beginning tips for debugging Maple. More information is in the Debugging section at the end of the worksheet.<Text-field bookmark="evalf (top)" layout="_pstyle10" style="_pstyle10">evalf (look at the numbers)</Text-field>Suppose you wanted to know what the function NiMqJi0lJHNpbkc2IyomJSJhRyIiIyUieEdGKSIiIiokLUYlNiMqJkYoRitGKkYrRikhIiI= looks like. Maple's plot command is a wonderful way to see what functions look like, so you could define the function this way (the restart command is to make sure that this example is starting out with a clean slate)restart: f:=x-> sin(a^2*x^2)/sin(a*2)^2;then useplot(f(x),x=-1..1);The error message tells us that Maple had trouble turning this formula into numerical values, which it needs to make a plot. A way of seeing what's wrong is to use evalf on a function value, like this:evalf(f(1.));This is an error message in disguise. What it means is that Maple tried to give you a number back, but couldn't because you hadn't told it what NiMlImFH was. As soon as you give NiMlImFH a value, the plot will work. (Set a to be 5 in the execution group below and go back up and execute the plot.)Here's another example. Suppose you forgot the value of NiMtJSRzaW5HNiMqJiUjcGlHIiIiIiIjISIi and needed Maple to tell you, so you trys:=sin(pi/2);"No!", you scream, "GIVE ME THE NUMBER!" The Maple command for this would be evalf(s);This, again, is an error message. It says that Maple tried to give you the number, but couldn't because it didn't know what NiMlI3BpRw== is. I have led you into error by using Maple's ability to deal with Greek letters. The symbol pi is just the Greek letter NiMlI3BpRw== ; what you want is the ratio of circle area to the square of circle radius, which is Pi in Maple. When you do it this way it workssin(Pi/2.);When Maple gives you back something unexpected, try to turn it into a number that you can check by using evalf. As you try to get a number out you will probably discover what the problem is. Go to top of section<Text-field layout="_pstyle10" style="_pstyle10">check := vs =</Text-field>You will make this mistake 100 times at least: only use = when you are defining an equation; assignment, i.e., you want a to be 5, is done with a:=5.<Text-field bookmark="plot (make a picture)" layout="_pstyle10" style="_pstyle10">plot (make a picture)</Text-field>Sometimes you will need to look at a lot more than just one number to see what went wrong, and the best way to look at a thousand numbers is to make a picture. For instance, suppose you tried to do the integral restart;int(sin(x)/(1-cos(x)),x=0..Pi);You thought you were going to get a number, but Maple gave you infinity. You could use floating point arguments to check the function like thissin(1.)/(1-cos(1.));but that looks fine. To check a whole bunch of values over the integration range, make a plot using Maple's command plotplot(sin(x)/(1-cos(x)),x=0..Pi);Now you can see that the integrand is singular at x=0, so Maple was right: the answer is infinity. Making plots is a great way to debug. <Text-field layout="_pstyle10" style="_pstyle10">assume (tie Maple down)</Text-field>
Sometimes Maple can't do what you want it to do because you are thinking about a specific problem and Maple is thinking generally. For instance, suppose you wanted to do the integralrestart;int(exp(-a^2*x^2),x=0..infinity);You wanted a formula containing NiMlImFH , but instead you got this mess. This time Maple gives you a helpful error message--since Maple can handle complex numbers, it can't tell whether NiMqJCUiYUciIiM= is positive or negative. It will give you the answer if you give it a little help with assume assume(a,real);int(exp(-a^2*x^2),x=0..infinity);Look the assume command up in online help; it will help you keep Maple under control. Warning: Once you have used assume on a variable, however, you may have trouble having Maple give you numbers. The trouble happens when you assume something about a, use a in an expression and assign it to another variable (say b), then give a a value, and finally try to evaluate b. Observe:restart;assume(a,real);b:=cos(a);a:=2.;evalf(b);Now watch what happens to the same sequence without the assumerestart;b:=cos(a);a:=2.;evalf(b);The lesson here is only to use assume when absolutely necessary.Finally, you may need to assume two conditions on a variable, like both c>0 and c<1. Maple lets you do this in two ways. You can either put both conditions inside a single assume command like thisassume(c>0,c<1);or you can do it in two (or more) steps using the command additionally, like thisassume(c>0);additionally(c<1);The reason you can't just use two assume commands is that whenever you use assume on a variable it erases all previous assumptions set on that variable.<Text-field layout="_pstyle10" style="_pstyle10">restart (time to punt)</Text-field>Sometimes Maple has a hard time giving you what you want because it has become so cluttered with everything you have been doing in a session that things you have forgotten, but that it remembers, interfere with what you are trying to do. I can only give you a simple example here, but this kind of thing happens all the time and it is quite often easier to just start over than to try to figure out what went wrong. Suppose you were exploring the Bessel function NiMtJiUiSkc2IyIiITYjJSJ4Rw== by checking a few values like thisrestart;x:=1.5;BesselJ(0,x);And then after trying a few different values of NiMlInhH , you decided to plot the function like thisplot(BesselJ(0,x),x=0..5);This is a pretty mysterious error message, and you have to know quite a bit about Maple to be able to tell what's wrong. But if you do thisrestart: plot(BesselJ(0,x),x=0..5);all is well. The restart command is the Maple equivalent of rebooting, and you will be using it regularly. (Note: the plot failed because we tried to plot with the variable x, which had been given a value of 1.5 just before the plot. Using an unassigned variable name works just fine:)plot(BesselJ(0,t),t=0..5);Go to top of section<Text-field bookmark="Cool stuff (top)" layout="_pstyle6" style="_pstyle6">Cool stuff you can do right now</Text-field>Even knowing the little bit you have learned right now you can do some rather amazing things. Open each subsection and see what you can do.<Text-field bookmark="Integration (top1)" layout="_pstyle10" style="_pstyle10">Integration</Text-field>DebuggingIntegration is done with the int command.Here's an indefinite integral NiMtJSRpbnRHNiQqJi0lJGV4cEc2IywkJSJ4RyEiIiIiIi0lJHNpbkc2I0YrRi1GKw== :restart;int(exp(-x)*sin(x),x);Or, if you don't know the command to integrate, you could just type the function into an execution group like this, then right click on it and select Integrate.exp(-x)*sin(x);As you use the right-click feature Maple will always assign the result to a variable beginning with R.
The first time you use it the variable will be R; the next time it will be R0, then R1, then R2, etc. Here's a definite integralNiMtJSRpbnRHNiQqJi0lJGV4cEc2IywkJSJ4RyEiIiIiIi0lJHNpbkc2I0YrRi0vRis7IiIhRi0=s1:=int(exp(-x)*sin(x),x=0..1);This is a perfectly valid expression, but perhaps you want a number?evalf(s1);Here's an integral Maple can't dos2:=int(exp(-x^4)*cos(x),x=0..1);so it just prints it nicely and lets you worry about how to get an actual number out. You do this by using evalf to ask Maple to do it numericallyevalf(s2);Problem 1.10 Find the numerical answer to NiMtJSRpbnRHNiQtJSRleHBHNiMtJSVzcXJ0RzYjJSJ4Ry9GLDsiIiEiIiM= . Put a comment on the same line as the command with Maple's # notation.-----------------------------------------------------------Go to top of section<Text-field bookmark="Differentiation (top1)" layout="_pstyle10" style="_pstyle10">Differentiation</Text-field>DebuggingTake the derivative of any function using diffrestart;f:=sin(x)/sqrt(1+x^2);d1:=diff(f,x);(Or use right-click if you don't remember the command)Perhaps you don't like the look of this and would rather have a common denominator. This is called normal form and can be obtained this way (we will do more of this in Chapter 9)normal(d1);You can do second derivatives tood2:=diff(exp(-x)*tan(x),x$2);Maybe you think this could look prettier? Trysimplify(d2);and then put the polynomial in NiMtJSR0YW5HNiMlInhH in the usual order of high powers down to low ones by usingsort(%);And now that we have a nice final answer I will assign it to d2. This is one of the few times that I use the previous answer variable %. It is useful here because if one of the algebra commands I use to get an improved form doesn't work, I haven't messed up what's in d2, so I can just keep trying things until I get what I want.d2:=%;These algebra commands, and more, are discussed in Chapter 9. During the semester you should get used to going to Chapter 9 and looking around whenever you want Maple put an expression in a form you like better.Problem 1.11 Take the first derivative of the function NiMtJSRjb3NHNiMtRiQ2Iy1GJDYjLUYkNiMlInhH . Put a comment about what you are doing in text within the execution group and above the diff command.-----------------------------------------------------------Go to top of section<Text-field layout="_pstyle10" style="_pstyle10">Build a sequence</Text-field>DebuggingIn calculus you studied sequences of numbers that tend to a limit and infinite sums of such sequences. In Maple sequences are built with the seq command. It works this wayrestart;s:=seq((5+n)/(3+n),n=1..50);orevalf(s);which gives us a hint that the sequence is approaching a limit of 1.Or you can build a sequence of expressions, like the terms of a power series. Here are the terms in the series for the exponential functionseq(x^n/n!,n=1..20);Problem 1.12Generate the first 15 terms of the sequence defined by NiMvJiUic0c2IyUibkctJSVkaWZmRzYkKiYtJSRjb3NHNiMlInhHIiIiLCZGMEYwRi9GMCEiIi0lIiRHNiRGL0Yn . Put a comment about what you are doing in text below the seq command, but within the same execution group.-----------------------------------------------------------<Text-field layout="_pstyle10" style="_pstyle10">Sum a series</Text-field>DebuggingFind a formula for the sum of the integers raised to the 6th power using sumrestart;s1:=sum(k^6,k=1..N);simplify(s1);sort(%);Find the result of summing the reciprocals of the integers raised to the 6th power from 1 to NiMlKWluZmluaXR5Rw==s2:=sum(1/n^6,n=1..infinity);then convert this to a numerical valueevalf(s2);Problem 1.13 Find the sum of the reciprocals of the squares of the odd integers from 1 to NiMlKWluZmluaXR5Rw== . Put a comment about what you are doing in a line of text above the execution group containing the sum command.-----------------------------------------------------------<Text-field bookmark="Taylor series (top)" layout="_pstyle10" style="_pstyle10">Taylor series </Text-field>DebuggingOne of the most useful tools used by physicists to get approximate answers to difficult problems is the Taylor series. You have probably forgotten this result, so here it is: any function NiMtJSJmRzYjJSJ4Rw== which is infinitely differentiable can be approximated in the neighborhood of NiMvJSJ4RyUiYUc= by a polynomial in (NiMsJiUieEciIiIlImFHISIi ) which is given by Taylor's famous formula f(x) = f(a) + f'(a)(x-a) + f''(a) (x-a)^2/2! + f'''(a)(x-a)^3/3! + ...This is very useful in getting approximations. For instance, the quantity NiMqJiIiIkYkLSUlc3FydEc2IywmRiRGJComJSJ2RyIiIyokJSJjR0YrISIiRi5GLg== appears all the time in relativity theory. It is sometimes nice to have an approximate form for this formula if NiMqJiUidkciIiIlImNHISIi is small. Use the taylor command to find it. restart;taylor(1/sqrt(1-x^2),x,5);where the 5 means get terms up through NiMqJCUieEciIiY= in the expansion. The term NiMtJSJPRzYjKiQlInhHIiIn in the answer means that the error in this expansion is of order NiMqJCUieEciIic= . And if you want to work with this polynomial approximation? You can convert this series to a polynomial with the command convert(...,polynom), like this:convert(%,polynom);Problem 1.14 Find an approximate formula for the function NiMtJSRleHBHNiMtJSRjb3NHNiMlInhH including terms up through NiMqJCUieEciIzU= . Display the coefficients of the series in both rational and floating point form. Put a comment about what you are doing in a text paragraph just below the taylor command.-----------------------------------------------------------Go to top of section<Text-field layout="_pstyle10" style="_pstyle10">Plot functions</Text-field>DebuggingIf you want to quickly find out what some function that you have run across looks like, use plot restart;plot(exp(sin(x)),x=0..50);Problem 1.15 Make a plot of the function NiMqJi0lJGV4cEc2IywkKiYlInhHIiIiIiNEISIiRixGKi0lJGNvc0c2I0YpRio= from NiMvJSJ4RyIiIQ== to NiMvJSJ4RyIkKyI= . Then put a comment about what you are doing in a paragraph just above the plot command.Problem 1.16 A charged disk of radius NiNJImFHNiI= having uniform charge density NiNJJnNpZ21hRzYi produces an electric field NiMmSSJFRzYiNiNJInpHRiU= along the z-axis (where the z-axis is the line perpendicular to the disk through its center) given by the integral expressionNiMvLSZJIkVHNiI2I0kiekdGJ0YoKixJJnNpZ21hR0YnIiIiRilGLCIiIyEiIiZJKGVwc2lsb25HRic2IyIiIUYuLUkkaW50R0YnNiQqJkkickdGJ0YsKSwmKiRGN0YtRiwqJEYpRi1GLComIiIkRixGLUYuRi4vRjc7RjJJImFHRidGLA== .Find a simple algebraic expression for NiMtJkkiRUc2IjYjSSJ6R0YmRic= , then use NiMvSSZzaWdtYUc2IikiIzU8IywkIiInISIiNiMqJkkiQ0c2IiIiIiokSSJtR0YlIiIjISIi , NiMvJkkoZXBzaWxvbkc2IjYjIiIhKiwtSSZGbG9hdEdJKnByb3RlY3RlZEdGLDYkIiVhKSkhIiQiIiIpIiM1PCMsJCIjNyEiIkYwSSJOR0YmRjBJIm1HRiYiIiNJIkNHRiZGNg== , and NiMvSSJhRzYiKiYtSSZGbG9hdEdJKnByb3RlY3RlZEdGKTYkIiIiISIiRitJI2NtR0YlRis= to make a plot of NiMmSSJFRzYiNiNJInpHRiU= from NiMvSSJ6RzYiLCQqJiIiJiIiIkkiYUdGJUYpISIi to NiMvSSJ6RzYiKiYiIiYiIiJJImFHRiVGKA== .-----------------------------------------------------------<Text-field layout="_pstyle10" style="_pstyle10">Solve hard equations</Text-field>DebuggingSuppose you need a solution of NiMvLSUkZXhwRzYjLCQlInhHISIiRig= . Use solve on the equationrestart;sol:=solve(exp(-x)=x,x);Well, this is an answer in terms of some function you have never heard of when what you really wanted was just a number. No problem; just useevalf(sol);Or if you already know that there isn't going to be a symbolic solution and you just want a number, you could tell Maple to just numerically solve this equation with Maple's numerical equation solver fsolve, telling Maple to start looking for a solution near x=1:fsolve(exp(-x)=x,x=1);If you don't give it a good guess it may take longer to get the answer or it may get lost and go to infinity instead of finding the answer.Problem 1.17 Find the solution of the equation NiMvLSUkY29zRzYjJSJ4R0Yn . Put a comment about what you are doing in a paragraph within the execution group just above the command. Within this paragraph of text use Maple's math mode (use Ctrl-r) to include the equation NiMvLSUkY29zRzYjJSJ4R0Yn .Maple will also solve equations (even systems of equations) for you symbolically. For example, here is how Maple solves the quadratic equation symbolically:Q:=a*x^2+b*x+c=0;solve(Q,x);And here's the symbolic solution of the general problem of two equations in two unknowns, with NiMlInhH and NiMlInlH unknown and NiMlImFH through NiMlImZH as the coefficients:E1:=a*x+b*y=e;E2:=c*x+d*y=f;solve({E1,E2},{x,y});You may find this an easier way of handling simultaneous equations than using Maple's linear algebra package.Problem 1.18In the calculation of the way a Venturi tube works (see Serway, Example 15.13) Bernoulli's equationNiMvLCYmSSJQRzYiNiMiIiJGKSooSSRyaG9HRidGKSokJkkidkdGJ0YoIiIjRilGLyEiIkYpLCYmRiY2I0YvRikqKEYrRikqJCZGLkYzRi9GKUYvRjBGKQ==and the equation of continuityNiMvKiYmSSJBRzYiNiMiIiJGKSZJInZHRidGKEYpKiYmRiY2IyIiI0YpJkYrRi5GKQ==are to be solved simultaneously to obtain the following formula for NiMmSSJ2RzYiNiMiIiM= :NiMvJkkidkc2IjYjIiIjKiYmSSJBR0YmNiMiIiJGLS1JJXNxcnRHRiY2IyooRihGLSwmJkkiUEdGJkYsRi0mRjRGJyEiIkYtKiZJJHJob0dGJkYtLCYqJEYqRihGLSokJkYrRidGKEY2Ri1GNkYt .Use Maple to obtain this result.-----------------------------------------------------------<Text-field layout="_pstyle10" style="_pstyle10">Solve differential equations</Text-field>DebuggingSuppose you need the two fundamental solutions of the second order differential equation f'' + xf' +f = 0 where ' denotes differentiation by x; use Maple's differential equation solving command dsolverestart;dsolve(diff(f(x),x$2)+x*diff(f(x),x)+f(x)=0);The variable NiMlJF9DMUc= is the arbitrary multiplier of the first fundamental solution and NiMlJF9DMkc= is the multiplier of the second. It involves a function NiMtJSRlcmZHNiMlInhH that you haven't encountered yet, but you will. Solving differential equations is a big subject and we will devote all of Chapter 7 to it.Problem 1.19 Find the solution of the differential equation NiMvLSUlZGlmZkc2JC0lInlHNiMlInhHRiosJkYqIiIiRidGLA== . After Maple finds the general solution, find the value of the arbitrary constant from the condition y(0)=1 by replacing NiMlInhH in the solution with 0, replacing NiMlInlH with 1, then solving the resulting equation for the unknown constant NiMlJF9DMUc= . Put a comment about what you are doing in a paragraph of text below and inside the execution group.-----------------------------------------------------------In the previous problem you had to work a little to get the initial conditions right. Maple can do this work for you, like this: ( using NiMvLSUiZkc2IyIiISIiIg== and NiMvLS0lJWRpZmZHNiQlImZHJSJ4RzYjIiIhIiIj in the differential equation NiMvLCgtJSVkaWZmRzYkLSUiZkc2IyUieEctJSIkRzYkRisiIiMiIiIqJkYrRjAtRiY2JEYoRitGMEYwRihGMCIiIQ== )Eq:=diff(f(x),x$2)+x*diff(f(x),x)+f(x)=0;dsolve({Eq,f(0)=1,D(f)(0)=2},f(x));There will be lots more on this subject in Chapter 7.<Text-field layout="_pstyle10" style="_pstyle10">Handle matrices and solve systems of equations</Text-field>DebuggingThere is an entire package in Maple devoted to matrices, vectors, and linear algebra. We will spend Chapter 5 on this subject, but here is an example of what can be done. Let's solve the linear system of equations x + 2y + 3z = 6 4x + 5y + 6z = 15 7x + 8y + 10z = 25which has been carefully built so that its solution is [x,y,z] = [1,1,1]. Maple would solve this system this way. First bring in the linear algebra package by using the command with(LinearAlgebra). Then load the matrix with the Matrix command, load the right-hand side vector with the Vector command, and finally solve the system with the LinearSolve command. restart;with(LinearAlgebra);(If you don't want to see all of this stuff that printed because we pulled in Maple's linear algebra package, put a colon at the end instead of a semicolon.)A:=Matrix([[1,2,3],[4,5,6],[7,8,10]]);b:=Vector([6,15,25]);c:=LinearSolve(A,b);Problem 1.20Jack is twice as old as Jill. Jill's age added to Jack's age is the same as Joan's age. The sum of their three ages is 48. How old is each person? Solve this problem by copying and modifying the above example. Put a comment about what you are doing between the Vector and LinearSolve commands. If your copy of the code above doesn't have these in separate execution groups, split them by looking in the edit menu.-----------------------------------------------------------<Text-field bookmark="Do algebra (top)" layout="_pstyle10" style="_pstyle10">Do algebra</Text-field>DebuggingThis is a very big topic and one of the main things Maple was designed to do. Chapter 9 has a description of common algebra commands that you will be using throughout this course. You can use Chapter 9 as a reference whenever Maple gives you an answer whose form doesn't impress you. Take a few minutes now and skim through Chapter 9, down to the section on algebra with matrices. Don't try to understand in detail everything that you read; just become familiar with what's available in Chapter 9 so you know where to look when problems come up later. Then come back here and do the problem below. (Don't do the problems at the end of Chapter 9.) Chapter 9Problem 1.21 Use Maple commands to put the expression NiMsKComIiIiRiUlInhHISIiRiUqJkYmRiUsJkYmRiVGJUYnRidGJyomRiZGJSwmRiZGJUYlRiVGJ0Yl into a simpler form. Put a comment about what you are doing in text above and outside the first execution group.-----------------------------------------------------------Go to top of sectionGo to top of sectionGo to top of chapter<Text-field bookmark="Plotting (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 2: Plotting </Text-field>Maple is a great tool for making plots. In this chapter we will learn how to make plots and then use them to review some important mathematical ideas that are important in physics.<Text-field bookmark="Making x-y plots (top)" layout="_pstyle6" style="_pstyle6">Making x-y plots</Text-field>DebuggingThe simplest kind of plot is the 2-d, or x-y, plot and Maple does them with ease. Maple will plot both functions and expressions, but the syntax is different for each of these two data types. Here's a plot of the rational expression NiMqJiwmJSJ4RyIiIkYmRiZGJiwmRiVGJkYmISIiRig= from NiMvJSJ4RywkIiImISIi to NiMvJSJ4RyIiIQ== . First we assign the rational expression to the variable g, then plot g. Note that g is an expression, not a function, so you can't use the notation g(x) to plot it.restart;g:=(x+1)/(x-1);plot(g,x=-5..0);This same plot can be obtained using Maple's function notation, like this (I have purposely made the function have two arguments so you can see how to plot such a function)f:=(x,y)->(x+y)/(x-y);To make a plot in x just give y a value through the argument list (NiMvJSJ5RyIiIg== reproduces the previous plot) and plot in xplot(f(x,1),x=-5..0);OK, now let's plot this same function over a larger range. Notice that you can just put the expression in the plot command line and skip the assignment of it to a variable if you want. plot((x+1)/(x-1),x=-5..5);Well, it's a plot, but perhaps not the one we wanted. The problem is that our function is singular at NiMvJSJ4RyIiIg== , so Maple tried to give us its huge vertical range. We would probably rather not try to visualize infinity, so we would like to limit the vertical range. This is easy too.plot((x+1)/(x-1),x=-5..5,-5..5);Now this looks better, but the funny-looking vertical line at NiMvJSJ4RyIiIg== looks wrong, and it is. Maple just connected the dots, including the jump from NiMsJCUpaW5maW5pdHlHISIi to NiMlKWluZmluaXR5Rw== . To clean this up we have to work a little harder and give the plot command some options. There are many options you can specify and to become an expert plotter you have to be able to look them up and use them. You can find them by using?plot[options]and the one we need to make the plot above look better is the discont=true option, which tells Maple to look for discontinuities in our function and turn off dot-to-dot plotting.plot((x+1)/(x-1),x=-5..5,-5..5,discont=true);Now let's try something a little fancier; let's put two plots on the same frame and specify the two different colors we want to use to tell them apart. You can see what colors are available by using?plot[color]Let's use the school colors of Brigham Young University, as far as they are translated correctly by Maple, and we will also thicken the lines to make the colors stand out. (You might want to use thicker lines like this on a plot so that it would be of publication quality.)plot([(x+1)/(x-1),cos(x)],x=-5..5,-5..5,discont=true,color=[navy,tan],thickness=2);As you can see, the two functions are placed in a Maple list, which is a list of things separated by commas and contained within square brackets. Any options that apply separately to each plot are also specified in lists, as you can see in the color option. Warning: Maple does not always respect your color order. If you have lots of plots and lots of colors, Maple sometimes mixes the colors up.I'll give you one more sample plot and then you will be off to the exercises. Suppose you wanted to make a plot of the motion of a damped harmonic oscillator, given by the formula NiMqJi0lJGV4cEc2IywkKiYlInRHIiIiIiQrIiEiIkYsRiotJSRjb3NHNiNGKUYq from NiMvJSJ0RyIiIQ== to NiMvJSJ0RyIkKyc= . Since you now know how to plot you would just useplot(exp(-t/100)*cos(t),t=0..600);and you would be pretty sure that something had gone wrong. What went wrong is that Maple can't tell, on its own, how many points to plot; so when a function is wiggling like crazy, like this one is, it needs some help from you. You can fix it by using the numpoints option to increase the plot resolution, like thisplot(exp(-t/100)*cos(t),t=0..600,numpoints=400);One last, but very important, thing; you will often want to define your own expressions to plot using Maple's assign command (:=), like this:F:=cos(omega*t)^3;Since it clearly depends on NiMlInRH we should be able to plot itplot(F,t=0..20);but it doesn't work. This blank plot is actually a Maple error message. The problem is that NiMlJm9tZWdhRw== doesn't have a value yet, so there is no way Maple could plot it. But how are you supposed to know this? The best thing to do when this happens is to try giving NiMlInRH a value and then evaluate F.t:=7.;F;The NiMlJm9tZWdhRw== still sitting there is your clue; it needs a value. So let's assign it a value and try again.omega:=1.;plot(F,t=0..20);What now!! The problem is subtle, and it will bite you often when you debug plots this way. Remember that we gave NiMlInRH a value of 7 so we could see what's wrong? Maple remembers this assignment and won't let us use NiMlInRH as a running variable in the plot. To fix it we have to undo the setting of NiMlInRH to 7 with the unassign command with 't' as its argument, then try it again. unassign('t');omega:=1;plot(F,t=0..20);or you could use the shorthand version of the unassign command like thist:='t';omega:=1;plot(F,t=0..20);The way to read this is "assign t to its own name, erasing any previous assignments." An even cleaner way to this is not to use assignment with := at all, but to use Maple's substitution command subs instead, like this:restart;F:=cos(omega*t)^3;plot(F,t=0..20);subs(t=7.,F);plot(subs(omega=1,F),t=0..20);The commands t=7 and omega=1 only apply inside the subs command--t and omega are still unassigned variables after all of this:t;omega;Before we leave the introduction let's look at one more thing you will want to know so that you can make your plots look nice: lettering. To put labels on the axes of a plot you can use the labels option, like this: labels=["x","y"]. To put a title on use title="This is the title". And if you want to put text in the figure somewhere, look up textplot in online help. Here's a plot illustrating these options.plot(sin(x^2),x=0..2*Pi,labels=["x","y(x)"],title="sin(x^2) function");Notice that sin(x^2) didn't print in Maple's pretty math mode. I wish I knew how to make this happen in plots. But Greek letters are available, in a sort of limited form, by changing either the labelfont or the titlefont to SYMBOL, like this (I have purposely dumped the entire greek alphabet on the plot so you can see how they are coded)plot(exp(x/6),x=0..2*Pi,labels=["abcdefghijklmnopqrstuvwxyz","y(x)"],title="ABCDEFGHIJKLMNOPQRSTUVWXYZ",labelfont=[SYMBOL],titlefont=[SYMBOL]);Unfortunately, I can't tell you how to put labels and titles on that are mixtures of Roman and Greek letters. What Maple really needs is a text production capability like LaTex where full typesetting of text and equations is possible. Perhaps in a later version.Ok, off to the exercises in the subsections below. Along the way you will learn some more plotting tricks.Go to top of section<Text-field bookmark="Basic function review (top)" layout="_pstyle6" style="_pstyle6">Basic function review </Text-field>DebuggingIn this section we will review the basic functions of mathematical physics by making plots.Problem 2.1 Using a horizontal range of NiMsJComIiIjIiIiJSNQaUdGJiEiIg== to NiMqJiIiIyIiIiUjUGlHRiU= and a vertical range of -2 to 2, plot the functions NiMtJSRzaW5HNiMlInhH , NiMtJSRjb3NHNiMlInhH , and NiMtJSR0YW5HNiMlInhH . Plot all three on the same plot by putting these three expressions in a list in the plot command line. Choose special colors for each one.------------------------------------------------------------------------Problem 2.2 Using a horizontal range of -3 to 3 and a vertical range of -3 to 3, plot the functions NiMtJSVzaW5oRzYjJSJ4Rw== , NiMqJi0lJGV4cEc2IyUieEciIiIiIiMhIiI= , and NiMsJComLSUkZXhwRzYjLCQlInhHISIiIiIiIiIjRipGKg== . Choose special colors for each one and study the plot carefully so that you can remember how they relate. Now on another picture plot the functions NiMqJi0lJGV4cEc2IyUieEciIiIiIiMhIiI= and NiMqJi0lJGV4cEc2IywkJSJ4RyEiIiIiIiIiI0Yp together with NiMtJSVjb3NoRzYjJSJ4Rw== . Finally, plot the functions NiMtJSVzaW5oRzYjJSJ4Rw== , NiMtJSVjb3NoRzYjJSJ4Rw== , and NiMtJSV0YW5oRzYjJSJ4Rw== on the same picture and stare at them until you are sure you will remember what they look like.------------------------------------------------------------------------Problem 2.3 Verify by drawing the appropriate graphs that the following identities are true. (This is not the same as a proof, of course, but if you are a person who thinks visually, a graph is worth a thousand lemmas.)NiMvKiYtJSRleHBHNiMlInhHIiIiLUYmNiMqJiIiI0YpRihGKUYpLUYmNiMqJiIiJEYpRihGKQ== ; NiMvLCYtJSNsbkc2IyUieEciIiItRiY2IyomIiIjRilGKEYpRiktRiY2IyomRi1GKSokRihGLUYp ; NiMvKiYiIiYiIiItJSNsbkc2IyUieEdGJi1GKDYjKiRGKkYl . To avoid taking the logarithm of negative numbers make the plot only over positive values of NiMlInhH . Note: it will be easier to see that the two expressions are graphically equivalent if you plot them with different colors and thicknesses by using this option line in your plot command: color=[red,green],thickness=[2,10]------------------------------------------------------------------------Problem 2.4 Show by doing graphical experiments that the exponential function grows faster than any power of x and that the natural log function grows more slowly than any fractional power of x. Do this by choosing several fixed powers of x and then making plots over appropriately sized windows. Recall that if you leave the vertical scale out of the plot command, Maple will choose it appropriately. Note: when you do the exponential function you will probably run into a floating point error because you are trying to plot numbers that are too big. The standard way to avoid this problem is to plot the log of the functions instead. It is easier to tell how big the numbers are if you use the function log10(x). Second note: when you do the fractional power comparison you will have to use such big values of x that Maple will complain. So in place of x use log10(x), i.e., use x=10^t and make the plots versus t instead of x.------------------------------------------------------------------------Problem 2.5 Graphically verify the following trigonometric identities. Instead of overlaying two plots, plot the left-hand side minus the right-hand side. Comment on why you don't really get zero.NiMvLSUkc2luRzYjKiYiIiMiIiIlInhHRikqKEYoRiktRiU2I0YqRiktJSRjb3NHRi1GKQ== ; NiMvLSUkY29zRzYjKiYiIiMiIiIlInhHRiksJiokLUYlNiNGKkYoRikqJC0lJHNpbkdGLkYoISIi .NiMvKiQtJSRzaW5HNiMqJiUieEciIiIiIiMhIiJGKyomLCZGKkYqLSUkY29zRzYjRilGLEYqRitGLA== ; NiMvKiQtJSRjb3NHNiMqJiUieEciIiIiIiMhIiJGKyomLCZGKkYqLUYmNiNGKUYqRipGK0Ys------------------------------------------------------------------------Problem 2.6 Show graphically that when you add NiMtJSRzaW5HNiMlInhH and NiMtJSRjb3NHNiMlInhH together you just get another sinusoidal function with a new amplitude and phase shift. Make the plot by assigning the sum of these two functions to a Maple function F and then plotting F(x). From your graph find the new amplitude and the phase shift relative to the cosine function, i.e., find a formula for the addition of sine and cosine in the form NiMqJiUiQUciIiItJSRjb3NHNiMsJiUieEdGJSUkcGhpRyEiIkYl .------------------------------------------------------------------------Go to top of section<Text-field bookmark="Fourier analysis (top)" layout="_pstyle6" style="_pstyle6">Fourier analysis</Text-field>DebuggingLater on you will learn some powerful techniques for solving partial differential equations using a technique called Fourier analysis, which is based on this powerful idea: you can make complicated functions by using infinite sums of simple ones. In the previous section you saw an example of this when you added cosine and sine to get a phase-shifted cosine. Here's another simple example that is important in physics. Add two cosine functions, but with different frequencies:restart;f:=t-> cos(t)+cos(1.1*t);plot(f(t),t=0..200*Pi,numpoints=1000);You have probably experienced this plot. Remember what the trumpets in junior high band sounded like: wah-wah-wah-wah. The annoying flutter of two inexperienced musicians trying to play the same note, but not quite succeeding, is called beats, and they are clearly illustrated by the plot above. The rapid oscillation is the note and the successive amplitude changes are the flutter.Problem 2.7 Play with the graph of beats above and find the relation of the difference between the two angular frequencies (NiMvJiUmb21lZ2FHNiMiIiJGJw== and NiMvJiUmb21lZ2FHNiMiIiMtJSZGbG9hdEc2JCIjNiEiIg== in the example above) to the wah-wah angular frequency, defined by NiMvJSZvbWVnYUcqKCIiIyIiIiUjcGlHRiclJlRiZWF0RyEiIg== , where NiMlJlRiZWF0Rw== is the time between successive loud portions of the sound.------------------------------------------------------------------------Now let's illustrate Fourier's theorem. He showed that any periodic function could be represented by an infinite sum of sines and cosines having the same period as the function. In these sums the sine and cosine functions are multiplied by coefficients that usually get small as the sum index gets big. For instance, here's a sum of cosine functions with coefficients that fall off like NiMqJiIiIkYkJSJuRyEiIg== coded using Maple's sum command.g:=x-> sum(cos(n*x)/n,n=1..100);There isn't any way you can get any insight into what this function looks like by staring at this sum, but Maple's plotting capability can show you exactly what is going onplot(g(x),x=0..6*Pi);Notice (i) that the function is periodic and (ii) that you probably couldn't have guessed that it was going to look like this. You can do some more examples in the problem below.Problem 2.8 Consider the Fourier sum NiMtJSRzdW1HNiQqKCksJCIiIiEiIiUibkdGKS0lJGNvc0c2IyomLCYqJiIiI0YpRitGKUYpRilGKkYpJSJ0R0YpRilGMEYqL0YrO0YpIiQrIg== . Plot it from NiMvJSJ0RyIiIQ== to NiMvJSJ0RyomIiIjIiIiJSNwaUdGJw== by assigning this sum to a Maple function. Now modify the sum so the factor in the denominator is squared, switch cosine to sine, and plot it again. Then change the factor in the denominator to be cubed and plot again. Then switch to the 4th power and plot again. This sequence illustrates a property of Fourier series which isn't in most math books. Functions which are discontinuous have Fourier series in which the terms go to zero like NiMqJiIiIkYkJSJuRyEiIg== . (And at the discontinuities they have nasty wiggly features called the Gibbs phenomenon, which has someone's name attached to it because it had to be discovered the hard way, Maple plots having not yet been invented.) Functions which have discontinuous first derivatives fall off like NiMqJiIiIkYkKiQlIm5HIiIjISIi . Functions which have discontinuous second derivatives fall off like NiMqJiIiIkYkKiQlIm5HIiIkISIi , etc. And functions which have no discontinuities or discontinuous derivatives of any order have to fall off faster than any power of NiMqJiIiIkYkJSJuRyEiIg== , which means they have to fall off exponentially in NiMlIm5H , like NiMtJSRleHBHNiMsJCUibkchIiI= , NiMqJiIiIkYkLSUlY29zaEc2IyUibkchIiI= , etc. You will see Fourier series that fall off like this in junior-level electromagnetism.------------------------------------------------------------------------Advanced topic: wave packetsFinally, we can use the idea of Fourier analysis to build wave packets and to examine the uncertainty principle. You probably think of the uncertainty principle only in terms of quantum mechanics, but it is really a result of Fourier analysis. But since Fourier analysis underlies all of quantum mechanics, it should be no surprise that this important physical principle turns out to be a mathematical result. To build a wave packet we sum a whole bunch of cosines or sines with frequencies closely spaced around some central frequency. The result is a wave at the central frequency but it lives inside an envelope caused by the destructive interference of the neighboring waves. Here, I'll show you.restart;A:=w-> exp(-(w-4)^2*20);Let's plot it so you can see the distribution of frequenciesplot(A(w),w=0..5,labels=['w','A']);It is important to have a way of describing how wide this distribution is. A common term that you may have learned before is the Full Width at Half Maximum, or FWHM for short. This is the width in NiMlJm9tZWdhRw== between the two points in the distribution NiMtJSJBRzYjJSZvbWVnYUc= where NiMlIkFH is one-half of its maximum. Look at the graph and roughly verify that the FWHM is given by NiMvKiZJJkRlbHRhRzYiIiIiSSZvbWVnYUdGJkYnLUkmRmxvYXRHSSpwcm90ZWN0ZWRHRis2JCIjUCEiIw== . Then do a little math and see that the exact value is NiMvKiZJJkRlbHRhRzYiIiIiSSZvbWVnYUdGJkYnLUklc3FydEdGJjYjKiYtSSRsb2dHRiY2IyIiI0YnIiImISIi .Now we will build a function of time which is made up of a superposition of 100 waves with frequencies between NiMvJSZvbWVnYUctJSZGbG9hdEc2JCIjTiEiIg== and NiMvJSZvbWVnYUctJSZGbG9hdEc2JCIjWCEiIg== (frequencies outside of this range don't have enough amplitude to matter very much, according to the graph above).f:=t-> sum(cos((3.5+n/100)*t)*A(3.5+n/100),n=0..100);Note that as NiMlIm5H ranges from 0 to 100, the quantity NiMsJi0lJkZsb2F0RzYkIiNOISIiIiIiKiYlIm5HRikiJCsiRihGKQ== ranges from 3.5 to 4.5, just as desired for NiMlJm9tZWdhRw== . Now we can plot the time signal and see what time function NiMtJSJmRzYjJSJ0Rw== is produced by this superposition using the frequency function NiMtJSJBRzYjJSZvbWVnYUc= .plot(f(t),t=-50..50);So we see that a finite-width distribution of amplitudes in frequency space (NiMlJm9tZWdhRw== ) makes a finite-width distribution in time, which is exactly what a wave packet is. Now comes the uncertainty principle. This theorem says that the product of the width of the amplitude function NiMtJSJBRzYjJSZvbWVnYUc=, which we call NiMqJiUmRGVsdGFHIiIiJSZvbWVnYUdGJQ== , and the width of the time signal NiMqJiUmRGVsdGFHIiIiJSJ0R0Yl (the width of the wave packet plotted above) is no smaller than a number of order unity. In practice it is usually about equal to 6 if we measure the widths using the full-width at half-maximum. Or in symbolsNiMxIiInKipJJkRlbHRhRzYiIiIiSSZvbWVnYUdGJ0YoRiZGKEkidEdGJ0Yo .Note that the number 6 in this formula is not precise. In fact, with the widths defined by full-width at half-maximum there is no precise form for the uncertainty principle. Only if the statistical standard-deviation form of the width is used does the uncertainty principle become precise. And if the idea that uncertainty can be described with precision seems strange to you, welcome to quantum mechanics.Problem 2.9 Verify the uncertainty principle given above for the graphs displayed. Then change the width of the amplitude function A(w) by changing the parameter 20 in the definition of A(w) to something else and making a new set of plots. Verify that the uncertainty relation holds for the new plots.Go to top of section<Text-field bookmark="Plotting data (top)" layout="_pstyle6" style="_pstyle6">Plotting data</Text-field>DebuggingMaple is not really a very good way to do data analysis. You have learned, or will learn, some powerful ways to do data analysis when you study Labview in your physics lab courses or when you study Matlab in Physics 330. But you might want to import some data into Maple sometime and compare it with a formula that you have coded in Maple, so here's what you need to know.Maple stores and plots data in matrix form. The way to read data in is to use readdata, like thisd:=readdata("datafile",2);where the 2 means that there are 2 columns of data in the file. If you execute this command you will get an error because you don't have a file called datafile in the directory you are working in. To fix this problem use Window's notepad editor to create a file called datafile that looks like this: (note that you can copy and paste this data into notepad)0 1.01 1.52 1.93 2.64 3.75 5.46 7.37 10.48 14.29 20.010 29.0
After you have made this file and have properly saved it in the directory you are working in, try executing the command again......did it fail? If so, it may be because Notepad insists on putting a .txt extension on all of its files. So the readdata command may need to be changed tod:=readdata("datafile.txt",2);This still might not work if you are on a windows system. The problem now is that Maple is not looking for your file in the right directory. To fix this use the currentdir command: currentdir("directory name"), e.g., currentdir("c:\\Physics 230");Note that you can use this command in this form to find out what the current directory iscurrentdir();Or if you are running off the a: drive you would usecurrentdir("a:");(Note that this change-directory command has the annoying feature in Windows that instead of echoing the new directory it echos the old one, or perhaps it doesn't echo anything. To make sure you are where you want to be check it with currentdir().) Once you get this straight one of the two read commands above should work.Now that the data is stored as a matrix Maple can plot it using the pointplot command, as shown below. But if you try to execute the pointplot command it will just print a pretty blue version of the command and ignore you. The problem is that the package that contains pointplot is so big that Maple doesn't load it unless it is needed, so you have to tell it that it's needed by using with(plots)with(plots):pointplot(d);Notice that the with(plots) command was terminated with a : instead of a ;. The : means to execute the command just like ; but to shut up about it. Try doing with(plots); and you will see what I mean. Whenever you want to execute a command and you are so confident that it will work that you don't need to see the output, use : . (You should rarely be this confident. Only use : after you have tested the command with ; first.) Now suppose we want to see how well this data is fit by the formula NiMtJSRleHBHNiMqJiUieEciIiIiIiQhIiI= . We simply assign the point plot to one variable name and the formula plot to another, then display them together, like this (notice the colons at the end of the assign statements--it's better to have Maple shut up about what it is doing here.)p1:=pointplot(d):p2:=plot(exp(x/3),x=0..10):display({p1,p2});Maple's stats package does similar things, and will even do some fitting.Go to top of section<Text-field bookmark="Parametric plots (top)" layout="_pstyle6" style="_pstyle6">Parametric plots</Text-field>DebuggingOne of the best ways to make complicated plots is with a parametric representation. Consider, for example, the humble circle. The formula for it that you remember best is probably this oneNiMvLCYqJCUieEciIiMiIiIqJCUieUdGJ0YoKiQlIlJHRic= ,but if you try to graph a circle with this formula you have to do it this wayNiMvLSUieUc2IyUieEctJSVzcXJ0RzYjLCYqJCUiUkciIiMiIiIqJEYnRi4hIiI= and NiMvLSUieUc2IyUieEcsJC0lJXNxcnRHNiMsJiokJSJSRyIiIyIiIiokRidGLyEiIkYy . This requires two separate plots and the functions have infinite derivatives at NiMvJSJ4RyUiUkc= and NiMvJSJ4RywkJSJSRyEiIg== ; it's just messy. But look how pretty the formulas for NiMlInhH and NiMlInlH on a circle look if you use a parametric representation:NiMvLSUieEc2IyUic0cqJiUiUkciIiItJSRjb3NHRiZGKg== ; NiMvLSUieUc2IyUic0cqJiUiUkciIiItJSRzaW5HRiZGKg== ; NiMvJSJzRzsiIiEqJiIiIyIiIiUjcGlHRik= .Here are the Maple plot commands to do the plot of a circle both the NiMtJSJ5RzYjJSJ4Rw== way and the parametric way, with the parametric one at a smaller radius so you can see them both.with(plots):p1:=plot([sqrt(1-x^2),-sqrt(1-x^2)],x=-1..1):p2:=plot([ .8*cos(s),.8*sin(s),s=0..2*Pi]):display({p1,p2});Ok--they both look the same, but perhaps neither one looks like a circle (depending on which version of Maple you are running.). This is a common plotting problem in all computer programs: circles look like ellipses if the x and y axes have different scales. Maple has a particularly easy fix for this problem, which is that you just tell the plot command that you want the x and y axes contrained to be the same scale, like thisdisplay({p1,p2},scaling=constrained);You can explore some more ways of doing parametric plots in the problems below.Problem 2.10 The classic conic sections all have parametric forms. Use the parametric plot command to sketch each of these curves using constrained scaling. Ellipse: NiMvLSUieEc2IyUic0cqJiIiJCIiIi0lJGNvc0dGJkYq ; NiMvLSUieUc2IyUic0cqJi0lJkZsb2F0RzYkIiM4ISIiIiIiLSUkc2luR0YmRi4= ; NiMvJSJzRzsiIiEqJiIiIyIiIiUjcGlHRik= . Hyperbola: NiMvLSUieEc2IyUic0cqJiIiJCIiIi0lJWNvc2hHRiZGKg== ; NiMvLSUieUc2IyUic0cqJi0lJkZsb2F0RzYkIiM4ISIiIiIiLSUlc2luaEdGJkYu ; NiMvJSJzRzssJC0lJkZsb2F0RzYkIiM6ISIiRitGJw== (Once you draw this, figure out how to get the missing half of the picture.) Parabola (rotated): NiMvLSUieEc2IyUic0csJiomRiciIiItJSRjb3NHNiMlJHBoaUdGKkYqKiZGJyIiIy0lJHNpbkdGLUYqISIi ; NiMvLSUieUc2IyUic0csJiomRiciIiMtJSRjb3NHNiMlJHBoaUciIiJGLyomRidGLy0lJHNpbkdGLUYvRi8=NiMvJSJzRzssJCIiJCEiIkYn . Try plotting this for several different angles. If you want to go a little crazy, try drawing a rotated parabola using the y(x) form.---------------------------------------------------------------------Problem 2.11 It is also possible to draw curves in polar coordinates. A simple example is the ellipse again, but this time with the origin at one focus of the ellipse. To make sense of this we need some relations from ellipse geometry. Suppose that the (x,y) form of the ellipse is as given above,NiMvLSUieEc2IyUic0cqJiUiYUciIiItJSRjb3NHRiZGKg== ; NiMvLSUieUc2IyUic0cqJiUiYkciIiItJSRzaW5HRiZGKg== with NiMyJSJiRyUiYUc= . Then the distance NiMlImFH is called the semi-major axis and the distance NiMlImJH is called the semi-minor axis. The eccentricity of the ellipse is defined to be NiMvJSJlRy0lJXNxcnRHNiMsJiIiIkYpKiYlImJHIiIjKiQlImFHRiwhIiJGLw== . It is zero for a circle and as it gets smaller the ellipse gets more and more squashed. The ellipse has two foci, one focus to the left of center along the long (semi-major) axis and the other to the right of center. The distance from the center of the ellipse to either focus is NiMvJSJmRyomJSJlRyIiIiUiYUdGJw== . (Wait a sec--how come I am dragging you through this? What has this got to do with physics? Well, this is the language you will use in Physics 321 to describe the motion of planets around the sun, so stay with me, this is important.) Draw an ellipse using an (x,y) parametrization which has the origin of coordinates at the right focus of the ellipse with NiMvJSJhRyIiIw== and NiMvJSJiRyIiIg== . (Use the standard parametrization given above, but subtract NiMlImZH from NiMtJSJ4RzYjJSJzRw== to shift it over.Now, here's the point of this exercise. The parametric form of an ellipse with the origin of coordinates at the right focus in cylindrical coordinates (like you will use in Physics 321) is given byNiMvLSUickc2IyUkcGhpRyomLSUiYUc2IywmIiIiRi0qJCUiZUciIiMhIiJGLSwmRi1GLSomRi9GLS0lJGNvc0dGJkYtRi1GMQ== . Lay this cylindrical coordinate graph on top of the xy graph of the ellipse you just did and verify that they match. The form of a Maple parametric plot in cylindrical coordinates is plot([r(s),phi(s),s=s1..s2],coords=polar,options) . For example, to make a spiral you could useplot([s/10,s,s=0..16*Pi],coords=polar,scaling=constrained);Once you get the plots to agree you are finished; but try to remember that the form for an ellipse with long dimension NiMqJiIiIyIiIiUiYUdGJQ== , eccentricity NiMlImVH , and with the origin at one focus in cylindrical coordinates isNiMvLSUickc2IyUkcGhpRyooJSJhRyIiIiwmRipGKiokJSJlRyIiIyEiIkYqLCZGKkYqKiZGLUYqLSUkY29zR0YmRipGKkYvOk-you won't remember this. But remember that you can come back here as a review when you get to planetary motion in Physics 321.------------------------------------------------------------------------Problem 2.12 Well, that was pretty bad. Here's one that's just for fun. In the polar plot command given below treat two numbers as adjustable, j and k, and just see what kinds of different pictures you can make. Fractional values of j are interesting if you use large values of k.j:=3;k:=2;plot([cos(j*s),s,s=0..k*Pi],coords=polar,scaling=constrained,axes=none);Go to top of section<Text-field bookmark="Special functions (top)" layout="_pstyle6" style="_pstyle6">Special functions</Text-field>There are a bunch of functions you haven't encountered yet that are called special functions, meaning they are not like the simple sines, cosines, exponentials, logs, powers, and hyperbolic functions you can find on hand calculators. These are functions that arise in more advanced work in mathematical physics and you will work with them in Physics 318, 321, 441, 442, 451, and 452. You can see which functions Maple knows about by using ?inifcns. Let's get a head start on these functions by using Maple graphs to at least see what they look like. Each problem below introduces you to a different special function and asks you to get a feel for its properties by making graphs.<Text-field bookmark="Legendre polynomials (top)" layout="_pstyle10" style="_pstyle10">Problem 2.13: Legendre polynomials</Text-field>DebuggingThese functions show up when we do electrical and quantum mechanical problems in spherical coordinates. Their symbol is NiMtJiUiUEc2IyUibkc2IyUieEc= and they are simply polynomials in NiMlInhH . But they have very special properties on the interval [-1,1]. (i) For odd values of the integer index NiMlIm5H they are odd and for even NiMlIm5H they are even. (ii) NiMvLSYlIlBHNiMlIm5HNiMiIiJGKg== and NiMvLSYlIlBHNiMlIm5HNiMsJCIiIiEiIilGKkYo . (iii) They wiggle a lot, more and more as NiMlIm5H gets bigger and bigger, but their magnitudes are always smaller than 1 inside the interval (-1,1). I have given you below a plot command that plots the first two on top of each other. Modify this command so that it plots the first 8 Legendre polynomials on top of each other. You could type all 8 of them in, or you could use Maple's sequence command seq which works like this. Suppose you wanted to generate a sequence of the functions NiMpJSJ4RyUibkc= from n=1..8. You would do thisseq(x^n,n=1..8);You can do this same kind of thing with P(n,x) in the plot command below.with(orthopoly);seq(P(n,x),n=0..8);Put this sequence command properly into the following plot command so that a plot of all of these functions from NiMvJSJuRyIiIQ== to NiMvJSJuRyIiKQ== appears. plot(................,x=-1..1);Go to top of section<Text-field bookmark="Bessel functions (top)" layout="_pstyle10" style="_pstyle10">Problem 2.14: Bessel functions</Text-field>DebuggingThese functions show up when we do electricity and thermal conduction problems in cylindrical geometry. There are 4 of them that are mostly commonly used: NiMtJiUiSkc2IyUibkc2IyUieEc= , NiMtJiUiWUc2IyUibkc2IyUieEc= , NiMtJiUiSUc2IyUibkc2IyUieEc= , and NiMtJiUiS0c2IyUibkc2IyUieEc= and the Maple commands for them are BesselJ(n,x), BesselY(n,x), BesselI(n,x), and BesselK(n,x). The J's and Y's are sort of like cylindrical sines and cosines while the I's and K's are like cylindrical growing and dying exponentials. You also need to know that the Y's and the K's are singular at NiMvJSJ4RyIiIQ== so you have to be careful when making plots of them. You can control singularities by choosing the vertical range of the plot to be finite. The Maple command below plots the first two J's. I want you make the following plots: (a) Plot NiMtJiUiSkc2IyIiITYjJSJ4Rw== and NiMtJiUiWUc2IyIiITYjJSJ4Rw== on one plot frame from NiMvJSJ4RyIiIQ== to NiMvJSJ4RyIjSQ== . Set numpoints large enough that you can see the logarithmic singularity of NiMtJiUiWUc2IyIiITYjJSJ4Rw== near NiMvJSJ4RyIiIQ== . (b) Plot NiMtJiUiSkc2IyUibkc2IyUieEc= and NiMtJiUiWUc2IyUibkc2IyUieEc= for NiMvJSJuRzsiIiIiIiU= with the J's on one plot frame and the Y's on another. Plot them from NiMvJSJ4RyIiIQ== to NiMvJSJ4RyIjSQ== . The sequence command seq will help you here. (c) Plot NiMtJiUiSUc2IyUibkc2IyUieEc= for NiMvJSJuRzsiIiIiIiU= all on one plot frame. Do it from NiMvJSJ4RyIiIQ== to NiMvJSJ4RyIjNQ== . (d) Plot NiMtJiUiS0c2IyUibkc2IyUieEc= from NiMvJSJuRzsiIiIiIiU= , all on one plot frame. Do it from NiMvJSJ4RyIiIQ== to NiMvJSJ4RyIjNQ== . Take a good look at these functions; they will show up later.plot([BesselJ(0,x),BesselJ(1,x)],x=0..50);Now use your graphs to answer the following questions.1. (a) The J- and Y-Bessel functions look like sines and cosines after about x=10; what is the period of these almost periodic functions? (b) You will notice that their amplitudes are falling off at large x. The fall off factor is a power law, i.e., NiMqJiUiQUciIiIpJSJ4RyUicEchIiI= . Find the value of NiMlInBH by plotting NiMtJiUiSkc2IyIiITYjJSJ4Rw== and NiMqJiUiQUciIiIpJSJ4RyUicEchIiI= on the same plot and by adjusting NiMlIkFH and NiMlInBH until the second function lines up with the top of the Bessel function wiggles.2. The I- and K-Bessel functions look like exponentials (NiMtJSRleHBHNiMqJiUiYUciIiIlInhHRig= ) after about x=10. Find the approximate exponential function that fits them out there. You will have trouble doing this because in addition to the NiMtJSRleHBHNiMqJiUiYUciIiIlInhHRig= -behavior these functions also have the same power-law drop-off factor NiMqJiUiQUciIiIpJSJ4RyUicEchIiI= as the J's and Y's. So when you look for the exponential function that comes close to describing what they do, make your comparison plots between exponentials and NiMqJi0mJSJJRzYjJSJuRzYjJSJ4RyIiIilGKiUicEdGKw== and NiMqJi0mJSJLRzYjJSJuRzYjJSJ4RyIiIilGKiUicEdGKw== . You will also find it helpful to plot the logarithms of these functions instead of the functions themselves to handle their huge variation in magnitude. All you want to see is that the logarithms of the NiMqJi0mJSJJRzYjJSJuRzYjJSJ4RyIiIilGKiUicEdGKw== functions are parallel to each other and also parallel to the line NiMvJSJ5RyomJSJhRyIiIiUieEdGJw== for the appropriate choice of NiMlImFH ; then do the same thing for the functions NiMqJi0mJSJLRzYjJSJuRzYjJSJ4RyIiIilGKiUicEdGKw== .Go to top of section<Text-field bookmark="Gamma function (top)" layout="_pstyle10" style="_pstyle10">Problem 2.15: The Gamma function</Text-field>DebuggingThe Gamma function is the analytic continuation onto the real number line of the factorial function for integers. The connection isNiMvLSUmR2FtbWFHNiMsJiUibkciIiJGKUYpLSUqZmFjdG9yaWFsRzYjRig= .This function shows up in all kinds of places and it has rather surprising properties for negative values of its argument. All I want you to do is to plot it from -5..5 and verify that it has the correct values at positive integers, and then to marvel that a function that seems so simple on the positive half of the number line could be so messed up on the negative side. Maple's name for it is GAMMA(x);<Text-field layout="_pstyle10" style="_pstyle10">Problem 2.16: Complete elliptic integrals</Text-field>DebuggingThe complete elliptic integral functions NiMtJSJLRzYjJSJrRw== and NiMtJSJFRzYjJSJrRw== are defined by the definite integralsNiMvLSUiS0c2IyUia0ctJSRpbnRHNiQqJiIiIkYsLSUlc3FydEc2IywmRixGLComRiciIiMtJSRzaW5HNiMlJHBoaUdGMiEiIkY3L0Y2OyIiISomJSNQaUdGLEYyRjc= ; NiMvLSUiRUc2IyUia0ctJSRpbnRHNiQtJSVzcXJ0RzYjLCYiIiJGLyomRiciIiMtJSRzaW5HNiMlJHBoaUdGMSEiIi9GNTsiIiEqJiUjUGlHRi9GMUY2The Maple names for these functions are EllipticK(k) and EllipticE(k). These functions are usually used with NiMlImtH in the range 0..1, but they can be analytically continued into the entire complex plane. Both K(k) and E(k) are NiMlI3BpRw== /2 for k=0. At the other end, k=1, K(k) is logarithmically singular and E(k) is 1. Plot both functions on the same plot over this range using numpoints=200 and 1000; I want you to see how weak a logarithmic singularity is. You should find that almost nothing happens as numpoints is changed, except that the vertical plotting range changes a little. To see why this plot behavior indicates a weak singularity, here's what such a pair of plots looks like for a strong singularity (pay attention to the sizes of the numbers on the y-axis):plot(1/(1-x),x=0..1,numpoints=200);plot(1/(1-x),x=0..1,numpoints=1000);<Text-field layout="_pstyle10" style="_pstyle10">Problem 2.17: The error function</Text-field>DebuggingThe error function NiMtJSRlcmZHNiMlInhH shows up all the time in probability theory and Maple calls it erf(x). If you have a Gaussian probability distribution, proportional to NiMtJSRleHBHNiMsJCokJSJ4RyIiIyEiIg== , then the probability that the variable NiMlInhH lies between NiMsJCUpaW5maW5pdHlHISIi and NiMlInpH is proportional toNiMtJSRpbnRHNiQtJSRleHBHNiMsJCokJSJ4RyIiIyEiIi9GKzssJCUpaW5maW5pdHlHRi0lInpH , which is just what the error function erf(z) involves. But for some reason a long time ago someone decided that the basic function erf should be defined as an integral starting at 0 instead of at NiMsJCUpaW5maW5pdHlHISIi , so they defined it this way:NiMvLSUkZXJmRzYjJSJ6RyooIiIjIiIiLSUkaW50RzYkLSUkZXhwRzYjLCQqJCUieEdGKSEiIi9GMzsiIiFGJ0YqLSUlc3FydEc2IyUjcGlHRjQ= . The probability that a Gaussian variable lies between NiMsJCUpaW5maW5pdHlHISIi and NiMlInpH is given by NiMqJiwmIiIiRiUtJSRlcmZHNiMlInpHRiVGJSIiIyEiIg== . Plot both erf(x) and (1+erf(x))/2 in the range -3..3.Go to top of section<Text-field bookmark="Animations (top)" layout="_pstyle6" style="_pstyle6">Animations</Text-field>DebuggingPerhaps the coolest plots Maple can make are animations. Let's start with two simple wave examples. The formula for a traveling wave is NiMvLSUieUc2JCUieEclInRHKiYlIkFHIiIiLSUkc2luRzYjLCYqJiUia0dGK0YnRitGKyomJSZvbWVnYUdGK0YoRishIiJGKw== . Maple can show you that this formula travels with the animate command. First we will give NiMlIkFH , NiMlImtH , and NiMlJm9tZWdhRw== numerical values, then animate the function by plotting many plots in NiMlInhH at successive times, just like a movie. WARNING: when you execute this group of commands you will see a plot, but it will not be animated; it will just sit there. To make it move you have to click on it and then run it with the player controls that appear on the toolbar. When they come up, take a minute and check out what each one does.restart:with(plots):A:=1.5;k:=3*Pi/2.;omega:=Pi/2.;animate(A*cos(k*x-omega*t),x=0..20,t=0..20,numpoints=50,frames=10);Problem 2.18Modify the animate command above so that the function is smoother in x and so that it runs smoother in time as well by experimenting with the numpoints and frames settings. Show, using your animation, that the velocity at which the wavetops move (this velocity is called the phase velocity) is given by NiMvJiUidkc2IyUkcGhpRyomJSZvbWVnYUciIiIlImtHISIi . Also show that changing the sign of NiMlImtH changes the direction the wave moves.--------------------------------------------------------------------------------Problem 2.19Modify the animation above so that it plots a standing wave instead: NiMvLSUieUc2JCUieEclInRHKiglIkFHIiIiLSUkc2luRzYjKiYlImtHRitGJ0YrRistRi02IyomJSZvbWVnYUdGK0YoRitGKw== . Use a range in NiMlInhH so that the standing wave has 3 zeros between the endpoints and fixed ends as well.--------------------------------------------------------------------------------Problem 2.20Show by making an animation that the sum of two waves of equal amplitude traveling in opposite directions is a standing wave.--------------------------------------------------------------------------------Advanced topic: wave packetsIn addition to elementary wave properties, animation can also illustrate the more complex behavior of wave packets, including the concepts of group velocity and wave packet diffusion. The way to make a wave packet is to take a whole bunch of waves of the form NiMqJiUiQUciIiItJSRzaW5HNiMsJiomJSJrR0YlJSJ4R0YlRiUqJiUmb21lZ2FHRiUlInRHRiUhIiJGJQ== with different NiMlImtH 's and add them together, as we did in the section of Fourier analysis when we discussed the uncertainty principle. We can do exactly the same thing here with NiMlImtH , using an amplitude function NiMtJSJBRzYjJSJrRw== centered at NiMmJSJrRzYjIiIh with width NiMqJiUmRGVsdGFHIiIiJSJrR0Yl to make a wave packet in space with wavelength NiMqKCIiIyIiIiUjUGlHRiUmJSJrRzYjIiIhISIi and width NiMqJiUmRGVsdGFHIiIiJSJ4R0Yl . But the new feature is that this packet moves, and in weird and strange ways. Its behavior is determined by the dispersion relation NiMvJSZvbWVnYUctRiQ2IyUia0c= of the waves that are being added together. We will start with the simplest case and work our way up to some strange ones that are more than just mathematical curiosities. Every effect that will be shown in this section is physically realized in some kind of electromagnetic wave found in the plasmas that surround the sun and the planets of our solar system. Suppose the dispersion relation is just the standard non-dispersive one that governs light and sound: NiMvJSZvbWVnYUcqJiUia0ciIiIlInZHRic= , where NiMlInZH is the phase velocity of the waves. In this case every wave of the superposition moves at exactly the same speed, so every part of the wave packet moves at speed NiMlInZH , as shown in the example below.Define the dispersion relationv:=1;w:=k->k*v;ko:=1;A:=k-> exp(-(k-ko)^2*40);Now we will look at the wave packet at time t=0.f:=(x,t)-> sum(sin((ko-.5+n/40)*x-w(ko-.5+n/40)*t)*A(ko-.5+n/40),n=0..40);with(plots):plot(f(x,0),x=-60..60);Now we are ready to make it move by using Maple's animation command.animate(f(x,t),x=-60..60,t=0..180,frames=80,numpoints=400,color=navy);Problem 2.21 If the dispersion relation is not just the linear function NiMvJSZvbWVnYUcqJiUia0ciIiIlInZHRic= , then more interesting things can happen. The first of these is that the waves in the packet and the packet as a whole no longer move at the same velocity. Let's try a new dispersion relation using the formNiMvJSZvbWVnYUcqJiUja3ZHIiIiLCZGJ0YnKiglImFHRiclImtHRicmRis2IyIiISEiIkYnRic= . When you study Fourier analysis in more detail you will learn how to show that while the wave crests move at the phase velocity given by NiMvJiUidkc2IyUmcGhhc2VHKiYlJm9tZWdhRyIiIiUia0chIiI= , the packet as a whole moves at the group velocity given by NiMvJiUidkc2IyUmZ3JvdXBHKiglImRHIiIiJSZvbWVnYUdGKiUjZGtHISIi . (a) Find the phase and group velocities for the dispersion relation given in the introduction to this problem (Maple can help). Choose NiMvJSJrRyZGJDYjIiIh and obtain NiMmJSJ2RzYjJSRwaGlH and NiMmJSJ2RzYjJSJnRw== (the standard phase and group velocity notations) as functions of the parameter NiMlImFH . Modify the dispersion relation in the Maple execution groups given in the first part of the problem and run it again with NiMvJSJhRyIiIg== . Try to see the wave crests moving slower than the wave packet as a whole (you will see wavecrests moving backwards through the packet because the group velocity is bigger than the phase velocity). To see this you will have to slow the animation down using the controls on the toolbar. You may also want to put it into continuous play mode and adjust the simulation time so that it runs just long enough that the group velocity covers the distance from x=0 to x=60. Warning: this takes a while, so be patient. (b) Now for something really weird; choose NiMlImFH so that the group velocity is zero and run the animation again. The packet should sit still while the wave crests move through it. -------------------------------------------------------------------------------- Problem 2.22You may have noticed in part (b) of Problem 2.21 that although the packet didn't move much, it did change shape a little. The reason for this is that wave packets can also broaden in time via diffusion, just like a tiny hot spot in a piece of metal spreads out through thermal diffusion. The diffusion coefficient for wave packet broadening is proportional to the magnitude of the second derivative of the dispersion relation (with respect to NiMlImtH ). This means that if the dispersion relation has a non-zero second derivative, then the wave packet will spread in time. But to really see it you will need to run the simulation long enough that the effect starts to really matter. This run time is on the order of a few times the absolute value of 1/(w''NiMlJkRlbHRhRw== k^2) in this problem, where NiMqJiUmRGVsdGFHIiIiJSJrR0Yl is the width of NiMtJSJBRzYjJSJrRw== (use FWHM). Calculate w'' and verify that it is non-zero, then run the simulation for Problem 2.21 long enough that you can see the spreading.--------------------------------------------------------------------------------Problem 2.23 Invent a dispersion relation that has a positive phase velocity and a negative group velocity and verify that it works by modifying and running an animation.Go to top of section<Text-field bookmark="Visualizing vector fields (top)" layout="_pstyle6" style="_pstyle6">Visualizing vector fields</Text-field>DebuggingMaple's fieldplot command allows you to visualize vector fields in two dimensions. Suppose, for instance, that you have a magnetic field given by the formulas NiMvJiUiQkc2IyUieEcqKCZGJTYjIiIhIiIiJSJ5R0YsJSJhRyEiIg== and NiMvJkkiQkc2IjYjSSJ5R0YmLCQqKCZGJTYjIiIhIiIiSSJ4R0YmRi5JImFHRiYhIiJGMQ== . To visualize the field lines we would do this (setting NiMvJiUiQkc2IyIiISIiIg== and NiMvJSJhRyIiIg== to make the numbers easy)restart;with(plots):fieldplot([y,-x],x=-1..1,y=-1..1,grid=[20,20],color=red,arrows=SLIM);Note that the field components go between the first square brackets in the command in the order [Bx,By]. There is also a fieldplot3d command which works similarly in three dimensions; you can find out how it works with ?fieldplot3d. Problem 2.24(a) Use fieldplot to visualize the electric field of a line charge, given by NiMvJSJFRyooJSdsYW1iZGFHIiIiLCYqJiUieEdGJyUiaUdGJ0YnKiYlInlHRiclImpHRidGJ0YnKigiIiNGJyUjUGlHRicsJiokRipGMEYnKiRGLUYwRidGJyEiIg== where i and j are the x and y unit vectors. (b) Use fieldplot to visualize the magnetic field of a long wire, given by NiMvJSJCRyoqJiUjbXVHNiMiIiEiIiIlIklHRiosJiomJSJ5R0YqJSJpR0YqISIiKiYlInhHRiolImpHRipGKkYqKigiIiNGKiUjUGlHRiosJiokRjJGNUYqKiRGLkY1RipGKkYw . Experiment with different grid settings and choices for the arrows option (see ?fieldplot). Note: don't use big numbers in the grid command. If you do, Maple will take forever and when it finishes you will be looking at a solid wall of color without any discernible arrows. I don't usually go above 30x30, and often 16x16 is about right. (Don't use odd numbers in the grid option because this will put a grid point right at the origin where the fields in this example are infinite.)Go to top of section<Text-field bookmark="3d plots (top)" layout="_pstyle6" style="_pstyle6">3D-surface plots and contour plots</Text-field>DebuggingTo visualize 2-dimensional data in the form of a function f(x,y) Maple gives you two choices: (1) plot the function values as the height of a surface above the xy plane or (2) draw contours of constant f(x,y) in the xy plane. Which does a better job depends on the problem and on your tastes. Here is an example done both ways. Consider the function NiMvLSUiZkc2JCUieEclInlHKigtJSRleHBHNiMsJC0lJGFic0c2IywmRiciIiItJSRzaW5HNiNGKCEiIkY2RjIsJkYyRjIqJi0lJkZsb2F0RzYkIiIjRjZGMi0lJGNvc0c2IyomRidGMkY8RjZGMkYyRjIsJkYyRjIqJi1GOjYkIiIlRjZGMiwmLUY6NiQiIiRGNkYyKiRGKEY8RjJGNkYyRjI= , the "mountain range" function. (Don't worry about where this function came from. I just made it up because it looks cool, like a mountain range.) A three-dimensional surface plot is done with plot3d like thisrestart;f:=exp(-abs(x-sin(y)))*(1+.2*cos(x/2))*(1 + .4/(.3+y^2));plot3d(f,x=-6..6,y=-6..6);This looks rather interesting, but the detail is too crude to really see what is going on, and we might want to use a different viewing angle too. These things are controlled with options which you can read about in ?plot3d[option] or you can just click on the figure and move the cursor while holding the left button down to cause the view to rotate. If you go into the Options menu on the toolbar and change the plot display from inline to window you will get a figure with its own set of tools that will let you change lots of things about the way it looks. Here is an improved plot using options in the command line:plot3d(f,x=-6..6,y=-6..6,grid=[60,60],labels=["x","y","f"],orientation=[45,30],axes=boxed,shading=xy,view=0..3);As you can see the surface grid is controlled by the grid=[m,n] option, the labels on the axes are controlled by the labels option, and the viewing angle is controlled by orientation. A word of warning: the mathematicians who wrote Maple are used to having NiMlJHBoaUc= be the angle in spherical coordinates that comes down from the z-axis and NiMlJnRoZXRhRw== be the azimuthal angle that winds around the z-axis in the xy plane. This is exactly backwards from the way we do it in physics. So to be consistent with the way we do spherical coordinates in physics, the form of the orientation option is orientation=[NiQlJHBoaUclJnRoZXRhRw== ] which is exactly backwards from what you will read in online help. In addition, the angle NiMlJHBoaUc= indicates the direction along which the viewer is sighting rather than the angular position of the viewer. This is weird enough that you will just have to experiment until you get what you want. The vertical size of the plotting box is controlled by the view=zmin..zmax option. Finally, the appearance of the plot is altered by the shading command which can be shading=z, shading=xy, shading=xyz, or a few other things found under ?plot3d. Experiment and see what looks best, and also try clicking on the various options that appear on the toolbar after you click on the plot.You can look at the same mountain with a contour, or topographic map, view like this (note that to use this command you have to to with(plots) first) restart;with(plots):f:=exp(-abs(x-sin(y)))*(1+.2*cos(x/2))*(1 + .4/(.3+y^2));contourplot(f,x=-6..6,y=-6..6,contours=40,grid=[30,30],coloring=[green,blue]);Note that the coloring=[green,blue] plots the low values of the function in green, the high values in blue, and in-between values in colors between green and blue. You can use any two Maple colors you want in this option (see ?plot[color])?plot[color]Go to top of sectionGo to top of chapter<Text-field bookmark="Calculus (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 3: Calculus</Text-field>One of the things Maple can help you with the most is calculus. It can take derivatives, do integrals, make series expansions, do infinite sums, and a whole lot more. In this chapter we will concentrate just on the basics.<Text-field bookmark="Limits (top)" layout="_pstyle6" style="_pstyle6">Limits</Text-field>DebuggingThe most basic idea in calculus is that of a limit, and Maple knows how to do them. For example, to find the value of the limit NiMtJSZsaW1pdEc2JComLSUkc2luRzYjKiYiIiQiIiIlInhHRixGLEYtISIiL0YtIiIh , just use the Maple command limit on the expression like thisrestart;limit(sin(3*x)/x,x=0);You can also do it with a Maple functiony:=x->sin(3*x)/x;limit(y(x),x=0);You can use ?limit to see some details about how this command works, but this is about all there is to it. Problem 3.1 Try this one just for practice NiMtJSZsaW1pdEc2JComLCYtJSRjb3NHNiMlInhHIiIiRiwhIiJGLCokRisiIiNGLS9GKyIiIQ== .Go to top of section<Text-field bookmark="Differentiation (top)" layout="_pstyle6" style="_pstyle6">Differentiation</Text-field>DebuggingDerivatives are relatively simple, so this section is simple. Maple can take derivatives of elementary functions and special functions with equal ease, so there is almost nothing to do in this section except show you Maple's two differentiation commands, one for expressions and one for functions.First let's do expressions. I suggest you use the following forms for taking the 1st, 2nd, and third derivatives, as illustrated below using the tangent function. You can either use diff, which gives you the derivative directly, or Diff and value, which display the derivative to be taken, then evaluate it. Diff is actually more useful than you might think because it gives you a chance to see if the derivative you have asked Maple to take is the one you really want. Note that in the example below backward quotes are used to assign the derivatives to f', f'', and f'''.restart;f:=tan(x);`f'`:=diff(f,x);`f''`:=diff(tan(x),x$2);`f'''`:=Diff(f,x$3);`f'''`:=value(`f'''`);`f'''`:=simplify(`f'''`);Now let's see how to do functions.f:=x->tan(x)/x;Diff doesn't work on functions; instead we have to use Maple's D command. This is a very powerful command in spite of its small size. It can take multiple derivatives of multiple functions (to see how to use all of its features type ?D) but we will only be taking first derivatives of a single function. The first derivative is easy (sometimes I don't want to bother with the backward quotes and just use fp for f', fpp for f'', etc.)fp:=D(f); Note that assigning the result of D(f) to fp produces the function fp(x). There is more than one way to take higher derivatives, but here is the most general one.fpp:=D[1$2](f);In the square brackets in the D command the 1 means differentiate with respect to the first (in this case the only) variable in the argument list and $2 means do it twice, just as in diff.Well, that's about it. Here are some exercises to practice on.Problem 3.2Take the indicated derivatives of the functions listed below. Use expression form on most of them but use function form on (a) and (d). When you get a mess try using simplify to clean it up. You will discover that simplify doesn't work on functions; to make the result look nice use the mouse to copy the mess you want to simplify to the clipboard, assign it to a new variable, cut off the extraneous junk, execute the command, then rebuild the derivative function using cut and paste again. This combination of Maple and editing is a good way to do mistake-free algebra.(a) NiMtJSVEaWZmRzYkLSUlc3FydEc2IywmIiIiRioqJCUieEciIiRGKi0lIiRHNiRGLEYt (b) NiMtJSVEaWZmRzYkLSYlIkpHNiMiIiE2IyUieEdGLA== (c) NiMtJSVEaWZmRzYkLSYlIklHNiMiIiI2IyUieEdGLA== (d) NiMtJSVEaWZmRzYkLSUkZXhwRzYjLSUkdGFuRzYjJSJ4Ry0lIiRHNiRGLCIiIw== (e) NiMtJSVkaWZmRzYkLSUmR0FNTUFHNiMlInhHRik=(f) NiMtJSVkaWZmRzYkLSUkZXJmRzYjJSJ4R0Yp (g) NiMtJSVkaWZmRzYkLSUiS0c2IyUia0dGKQ== (this is the complete elliptic integral of the first kind, Maple's EllipticK.) -------------------------------------------------------------------Problem 3.3Here's a find-the-maxima-and minima problem like ones you used to do in high school. Consider the function NiMqJi0lI2xuRzYjJSJ4RyIiIi0mJSJKRzYjIiIhRiZGKA== . (Note: I am using the word function in the mathematical sense, not in the Maple sense. This problem is easier if you just use a Maple expression to define the function above.) (a) First plot this function on the interval [0,10]. (b) Look at the graph and find, approximately, the values of NiMlInhH where the function has maxima and minima. Then take the derivative of the function and use the fsolve command to find these values of NiMlInhH precisely. If your expression for the derivative is called NiMlImZH , and if you wanted to find a zero of it near 1.1, you would do this: fsolve(f,x=1.1);-------------------------------------------------------------------Problem 3.4In quantum mechanics you will encounter a close relative of the Legendre functions NiMtJiUiUEc2IyUibkc2IyUieEc= that we have seen already. These new functions are called the Associated Legendre functions NiMpJiUiUEc2IyUibkclIm1H . For each integer NiMlIm5H these functions are defined for values of NiMlIm1H in the interval NiM3IzsiIiElIm5H , with the NiMvJSJtRyIiIQ== function being plain old NiMtJiUiUEc2IyUibkc2IyUieEc= . These functions are defined in terms of derivatives of the Legendre functions:NiMvKSYlIlBHNiMlIm5HJSJtRyooKSwkIiIiISIiRilGLSksJkYtRi0qJCUieEciIiNGLiomRilGLUYzRi5GLS0lJWRpZmZHNiQtRiU2I0YyLSUiJEc2JEYyRilGLQ== . This definition is too cumbersome for most computer languages, but Maple handles it with ease because it thinks symbolically instead of numerically. Here is a function that evaluates itrestart;with(orthopoly);Pnm:=(n,m,x)-> (-1)^m*(1-x^2)^(m/2)*diff(P(n,x),x$m);Before we do anything fancy with it we ought to test it, so let's put in numbers for NiMlIm5H , NiMlIm1H , and NiMlInhH .Pnm(3,1,.5);Well, we're in trouble again. The problem is with what P(n,x) returns. As we saw in the section in Chapter 2 on this function, it doesn't return a number; it returns a polynomial. When we put in 0.5 for x it goes into our Pnm function, defined above, in place of x, and then diff tries to take a derivative with respect to 0.5, which makes no sense. Watch what happens when we put in a variable in place of x instead of a numberPnm(3,1,t);If you want a numerical result you could use the subs command (substitute) like this:subs(t=.5,%);or you could just give NiMlInRH a value (which then wrecks it as a variable) like this:a:=Pnm(3,1,t);t:=0.5;a;This is a little annoying, but on the other hand, just think about it; why do you need a number in Maple anyway? You want to plot the function, differentiate it, integrate it, use it in differential equations, etc. What could be better than having an explicit expression for the thing? So Maple doesn't think this is a problem; it's a feature! And this feature is shared by all of the orthogonal functions you get when you use with(orthopoly).There is one other annoying thing about the function Pnm. Watch what happens when we try to evaluate it with m=0Pnm(5,0,x);With m=0 it is supposed to give us Pn(x) back, but it doesn't. The reason it doesn't is that we just asked it to take the 0th derivative of a function, which Maple's diff command can't handle. Later when we study procedures we will come back to this problem and fix it so it works with m=0.Ok, I have shown you how this can be done. Now I want you to make a plot of the 5 associated Legendre functions that go with P(5,x), i.e., n=5 and m=1,2,3,4,5. Plot them from x=-1..1. Put all five plots on one set of axes with different colors so you can see what happens as m ranges from 1 up to n=5. After you look at the picture you will probably want to rescale the functions so they all look about the same size. In the upcoming section on integration we will redo this plot and learn a natural way to make the functions nearer to the same size. ------------------------------------------------------------------Problem 3.5 Here is an electricity problem borrowed from the integration section that follows this one. The potential function for a charged hemisphere of radius R with surface charge density NiMlJnNpZ21hRw== as a function of z , where z goes up the symmetry axis of the hemisphere, is given by the expressionV:=-1/2*sigma*R*(-sqrt(R^2+z^2)+sqrt((z-R)^2))/(z*e0);where e0 is shorthand for the electrical constant NiMmJShlcHNpbG9uRzYjIiIh .The electric field component NiMmJSJFRzYjJSJ6Rw== can be obtained from the potential V by differentiating: NiMvJiUiRUc2IyUiekcsJC0lJWRpZmZHNiQlIlZHRichIiI= . Use Maple to take this derivative and obtain an (ugly) expression for NiMmJSJFRzYjJSJ6Rw== . Simplify it. You will see an unfamiliar function called csgn; look this function up with ?csgn and make sure you understand what it does. Then set NiMvJSZzaWdtYUciIiI= , NiMvJSJSRyIiIg== , and NiMvJSNlMEciIiI= and plot both V and NiMmJSJFRzYjJSJ6Rw== from NiMvJSJ6RywkIiIlISIi to NiMvJSJ6RyIiJQ== . It is a theorem in electromagnetism that when you cross surface charge density, the electric field jumps up by NiMqJiUmc2lnbWFHIiIiJiUoZXBzaWxvbkc2IyIiISEiIg== . (You will notice that in the definition of V above I used e0 in place of NiMmJShlcHNpbG9uRzYjIiIh . This was intentional. Avoid subscripted variables whenever possible because subscripts in Maple reference array elements.) Verify on your plot that the correct jump is obtained. On your graph negative z is below the circular rim of the hemisphere; positive z from 0 to R is inside the hemisphere; and positive z from R to infinity is above the dome. Interpret your graph physically and convince yourself that it makes sense.------------------------------------------------------------------Problem 3.6Here is a fancy kind of differentiation called implicit differentiation that Maple knows how to do. Suppose that you have an equation involving both NiMlInhH and NiMlInlH , like this one NiMvLCYqJCUieEciIiMiIiIqJCUieUciIiRGKEYr . You would like to find NiMqJiUjZHlHIiIiJSNkeEchIiI= without solving for NiMtJSJ5RzYjJSJ4Rw== . The way to do this is to differentiate this equation implicitly to get NiMvLCYqJiIiIyIiIiUieEdGJ0YnKigiIiRGJyokJSJ5R0YmRictJSVkaWZmRzYkRixGKEYnRiciIiE= , then solve for NiMqJiUjZHlHIiIiJSNkeEchIiI= . Maple knows how to do it, provided that you tell it that NiMlInlH depends on NiMlInhH , like this. restart;eq:=x^2 + y(x)^3 = 3;deq:=diff(eq,x);dydx:=solve(deq,diff(y(x),x));If you don't want to type y(x) all of the time, you can use Maple's alias command to tell it to turn y into y(x) (only in Maple's internal processing) whenever it is encountered.restart;Allow us to use y in place of y(x)alias(y=y(x));eq:=x^2 + y^3 = 3;deq:=diff(eq,x);dydx:=solve(deq,diff(y,x));Here's an example where this shows up in physics. The dispersion relation for electromagnetic waves in a plasma is NiMvKiQlJm9tZWdhRyIiIywmKiQlI3dwR0YmIiIiKiYlImtHRiYlImNHRiZGKg== , where NiMlI3dwRw== is a frequency called the plasma frequency. The phase velocity of these waves is given by NiMqJiUmb21lZ2FHIiIiJSJrRyEiIg== while the group velocity is given by NiMqKCUiZEciIiIlJm9tZWdhR0YlKiZGJEYlJSJrR0YlISIi . First use Maple to find formulas for both the phase and group velocities in terms of NiMlI3dwRw== , NiMlImtH , and NiMlImNH by solving for NiMtJSZvbWVnYUc2IyUia0c= and differentiating. Then use implicit differentiation to get the group velocity in terms of NiMlImtH , NiMlImNH , and NiMlJm9tZWdhRw== .---------------------------------------------------------------------Finally, Maple also knows how to take partial derivatives. Consider the function of x and y NiMvLSUiZkc2JCUieEclInlHKiYtJSRjb3NHNiMqJkYnIiIiRihGLkYuRighIiI= . Here are its derivatives with respect to x, y, and both x and y, using the expression formrestart;f:=cos(x*y)/y;diff(f,x);diff(f,y);diff(f,x,y);And here is the same thing using Maple function notationrestart;f:=(x,y)->cos(x*y)/y;D[1](f);D[2](f);D[1,2](f);In the first example [1] means differentiate with respect to the first variable in the argument list (x,y), which is x; [2] means differentiate with respect to the second argument, y; and [1,2] means differentiate with respect to both of them.------------------------------------------------------------------ Problem 3.7Find the two first derivatives and all three second derivatives (double x, double y, and mixed xy) of the following functionNiMtJSJLRzYjLSUlc3FydEc2IyoqIiIlIiIiJSJ4R0YrJSJ5R0YrKiQsJkYsRitGLUYrIiIjISIi , where K is the complete elliptic integral EllipticK. Use expression notation with diff. Try using expand and simplify to clean up the messes that result.Go to top of section<Text-field bookmark="Integration (top)" layout="_pstyle6" style="_pstyle6">Integration</Text-field>The single thing you will use Maple for the most is integration. In fact, many of you don't have any more idea of what an integral table is than you have about slide rules. Mostly this is OK because Maple is easily available to you and is pretty good. But it doesn't know how to do everything (as you will see in the some of the examples in this section), so you need to know where to go when Maple fails. The best place to go is a math reference book called A Table of Series and Integrals by Gradshteyn and Ryzhik. You can find it in the math reference section of the library. <Text-field bookmark="Elementary integrals (top)" layout="_pstyle10" style="_pstyle10">Elementary integrals</Text-field>DebuggingMaple knows how to do all of the integration problems you encountered in your first calculus course. The command to do this is int, and with expressions you use it like thisrestart;int(sin(x),x);orf:=sin(x)*x;int(f,x);Note: do not use f(x) as the argument if f is an expression. With functions the integration command works like thisg:=(x,y)->sin(x*y)*x;int(g(x,y),x);There is also an inert form of int, namely Int, which is used to display integrals. You would use this form for documenting a worksheet. Try this:s1:=Int(exp(x),x);But be warned: Int only displays, it doesn't do math. "But if it doesn't do anything, why would I want to use it?", you ask? Because it will help you see if you have entered the integral properly, which makes Int a very valuable debugging tool. After you have seen that it looks right in displayed form, use value(s1) to get the answer. So the right way to do the simple integral above and get an answer is thiss1:=Int(exp(x),x);s1:=value(s1);I suggest that you always do integrals this way, combining Int and value. It is one of those habits that will decrease the number of hours you will spend looking for stupid mistakes.And you can do definite integrals too, like thiss2:=Int(tan(x),x=0..1);s2:=value(s2);And if you need a number there is alwaysevalf(s2);Oh, and if you just want to get a numerical answer without going through evalf, just give int floating point limits and you will get it right away.s2:=Int(tan(x),x=0..1.);value(s2);You should also know that Maple can do integrals where the limits are infinite, but you may need to give it some guidance by using the assume command. Well, that's about all you have to know if Maple can do the integral. Try ?int to see some of the extra integration options Maple has available. Now let's do some exercises.Problem 3.8Do the following integrals with Maple using expression notation for (a)-(d) and function notation for (e)-(g). Obtain numerical values for (e) and (f). You will have trouble with (g), and even when you get it to work the answer will look ugly. Try simplifying it with simplify.(a) NiMtJSRJbnRHNiQtJSNsbkc2IyUieEdGKQ== (b) NiMtJSRJbnRHNiQtJSVzcXJ0RzYjLCYiIiJGKiokJSJ4RyIiIyEiIkYs (c) NiMtJSRJbnRHNiQqJiUieEciIiIsJkYoRigqJEYnIiIkRighIiJGJw== (d) NiMtJSRJbnRHNiQtJSVjb3NoRzYjJSJ4R0Yp(e) NiMtJSRJbnRHNiQtJSVzcXJ0RzYjKiYsJiIiIkYrJSJ4R0YrRissJkYrRitGLCEiIkYuL0YsOyIiIUYr (f) NiMtJSRJbnRHNiQqJiUieEciIiIsJiokRiciIiRGKEYoISIiRiwvRic7IiIhKiZGKEYoIiIjRiw= (try using both 1/2 and 1./2. as the upper limit) (g) NiMtJSRJbnRHNiQqJi0lJGV4cEc2IywkKiYlImFHIiIiJSJ4R0YtISIiRi0tJSRjb3NHNiNGLkYtL0YuOyIiISUpaW5maW5pdHlH (Don't know how to handle NiMlKWluZmluaXR5Rw== ? Use online help.)------------------------------------------------------------------Problem 3.9A common way that integrals show up in physics problems is in calculating voltages and electric fields (remember sophomore electricity and magnetism?) Here is one that you might encounter in Physics 441 that Maple knows how to do. Consider a hemisphere described in spherical coordinates by NiMvJSJyRyUiUkc= and NiMvJSZ0aGV0YUc7IiIhKiYlI3BpRyIiIiIiIyEiIg== . Let it have surface charge density NiMlJnNpZ21hRw== . You are to find the electrostatic potential (voltage) NiMtJSJWRzYjJSJ6Rw== along the NiMlInpH -axis.I will get you started. The vector distance to the observation point on the NiMlInpH -axis is r=z k, where k is the unit vector in the NiMlInpH -direction. The vector distance to a little bit of charge NiMvJSNkcUcqMCUmc2lnbWFHIiIiKiQlIlJHIiIjRictJSRzaW5HNiMlJnRoZXRhR0YnJSJkR0YnRi5GJ0YvRiclJHBoaUdGJw== is r'=Rr' where r' is a unit vector pointing from the origin to the little bit of charge. Using the law of cosines we can then writeNiMvLSUiVkc2IyUiekcqJi0lJEludEc2JC1GKjYkKiolJnNpZ21hRyIiIiokJSJSRyIiI0YwLSUkc2luRzYjJSZ0aGV0YUdGMC0lJXNxcnRHNiMsKEYxRjAqJEYnRjNGMCoqRjNGMEYyRjBGJ0YwLSUkY29zR0Y2RjAhIiJGQEY3JSRwaGlHRjAqKCIiJUYwJSNwaUdGMCYlKGVwc2lsb25HNiMiIiFGMEZAwhere the integral sign here means integrate over both NiMlJnRoZXRhRw== and NiMlJHBoaUc= . The NiMlJHBoaUc= integral just gives NiMqJiIiIyIiIiUjcGlHRiU= and we are left withNiMvLSUiVkc2IyUiekcqJi0lJGludEc2JCoqJSZzaWdtYUciIiIqJCUiUkciIiNGLi0lJHNpbkc2IyUmdGhldGFHRi4tJSVzcXJ0RzYjLChGL0YuKiRGJ0YxRi4qKkYxRi5GMEYuRidGLi0lJGNvc0dGNEYuISIiRj4vRjU7IiIhKiYlI3BpR0YuRjFGPkYuKiZGMUYuJiUoZXBzaWxvbkc2I0ZBRi5GPg==Use Maple's int command to build a function V(z) that we can use later. The syntax for function building is this (setting V(z) to the dying exponential function).V:=z->exp(-z);Note: recall that you had better not use the symbol V(z); Maple interprets this literally, i.e., V(z) is the name of the function you are defining, requiring you to use the awkward syntax V(z)(z) when using it. As defined above you type V(z) when you use it. You can do the same thing with int, like this V:=z-> int(....). In place of the symbol NiMmJShlcHNpbG9uRzYjIiIh use e0, and define the constants so Maple can plot numbers. Here, I'll get you started; you fill in what goes in (...)restart:e0:=8.854e-12;sigma:=1e-10;R:=0.5;V:=z->int(....)/(2*e0); You will notice that Maple doesn't give you a formula for the answer this time; it just displays the integral. I don't know why. But now that it is a function you can plot it as a function of z. Do so, from z=-5 to z=5. Now calculate the total charge on the hemisphere and overlay plots of the true potential and the corresponding point charge potential. The two plots should agree for |z|>>R. You can get a better fit by putting the point charge somewhere other than at the origin; can you graphically find about the best value of z at which to put the point charge? Recall that the formula for the potential of a point charge is NiMvLSUiVkc2IyUickcqJiUicUciIiIqKiIiJUYqJSNwaUdGKiYlKGVwc2lsb25HNiMiIiFGKkYnRiohIiI= .------------------------------------------------------------------Problem 3.10Another place integrals show up is in classical mechanics. Consider the equation of motion of a pendulum:where NiMlJk9tZWdhRw== is the small-oscillation frequency of the pendulum. If we multiply this equation by NiMqKCUiZEciIiIlJnRoZXRhR0YlJSNkdEchIiI= and integrate once with respect to time, we get the conservation of energy theorem for this problem:NiMvKiYqKCUiZEciIiIlJnRoZXRhR0YnJSNkdEchIiIiIiNGK0YqLCYqJiUmT21lZ2FHRistJSRjb3NHNiNGKEYnRicqJkYuRistRjA2IyZGKDYjIiIhRidGKg==where NiMmJSZ0aGV0YUc2IyIiIQ== is the initial angular position of the pendulum before we release it from rest. We would like to know how long it takes the pendulum to get from its initial angle down to NiMvJSZ0aGV0YUciIiE= because this time is NiMqJiUiVEciIiIiIiUhIiI= , one-quarter of the period of a pendulum with initial amplitude NiMmJSZ0aGV0YUc2IyIiIQ== . (a) Show that the energy equation above can be rewritten in the formNiMvKiglImRHIiIiJSZ0aGV0YUdGJiomJSZPbWVnYUdGJi0lJXNxcnRHNiMqJiIiI0YmLCYtJSRjb3NHNiNGJ0YmLUYxNiMmRic2IyIiISEiIkYmRiZGOCUjZHRH . This means that the quarter period of the motion is given by the integralNiMvLSUkSW50RzYkKiYiIiJGKComJSZPbWVnYUdGKC0lJXNxcnRHNiMqJiIiI0YoLCYtJSRjb3NHNiMlJnRoZXRhR0YoLUYyNiMmRjQ2IyIiISEiIkYoRihGOi9GNDtGOUY3KiYlIlRHRigiIiVGOg== .(b) Have Maple do this integral in an attempt to get a formula for the period T of a pendulum, using s and s0 instead of NiMlJnRoZXRhRw== and NiMmJSZ0aGV0YUc2IyIiIQ== . Once you try it you will probably be unimpressed with the beauty of the result. Part of the problem is that Maple doesn't know what you are going to use for NiMmJSZ0aGV0YUc2IyIiIQ== , so it gives you something incredibly general (as far as it knows, you might even want NiMmJSZ0aGV0YUc2IyIiIQ== to be complex). To tie Maple down a little, use the assume command, like thisassume(theta0,real,0<theta0,theta0<Pi);(Note: when you see these variables again they will have little ~ signs attached to them. This is Maple's way of showing that they have been restricted in meaning by an assume command.) Now you can try integrating again; it will look a little better, but it is still ugly. You can often help Maple out by using integration tricks, like u-substitutions. Try this integral again, but use the identity NiMvLSUkY29zRzYjJSZ0aGV0YUcsJiIiIkYpKiYiIiNGKSokLSUkc2luRzYjKiZGJ0YpRishIiJGK0YpRjE= to change the functions inside the square root. You and Maple are a team; don't be afraid to use what you have learned in your math classes.(c) Plot the period T as function of initial angle NiMmJSZ0aGV0YUc2IyIiIQ== from 0 to NiMlI3BpRw== . Does your plot make physical sense? Check the plot for NiMmJSZ0aGV0YUc2IyIiIQ== both small and near NiMlI3BpRw== . ------------------------------------------------------------------Problem 3.11Integrals also show up in physics when calculating the moments of inertia of spinning objects. The moment of inertia is defined by the integral NiMtJSRpbnRHNiQqJiUic0ciIiMlJHJob0ciIiIlIlZH where NiMlInNH is the perpendicular distance from the spin axis to a point in the object, where NiMlJHJob0c= is the mass density, and where NiMlI2RWRw== is the differential volume element, e.g., NiMqKCUjZHhHIiIiJSNkeUdGJSUjZHpHRiU= in Cartesian coordinates. (a) Use Maple to find the moment of inertia of a sphere of radius NiMlIlJH about an axis through its center. This is most easily done in spherical coordinates in which NiMvJSNkVkcqMCUickciIiMtJSRzaW5HNiMlJnRoZXRhRyIiIiUjZHJHRiwlImRHRixGK0YsRi5GLCUkcGhpR0Ys . If we use the NiMlInpH axis as the spin axis, then NiMvJSJzRyomJSJyRyIiIi0lJHNpbkc2IyUmdGhldGFHRic= (draw a picture and convince yourself that this is true). Assume that the mass density is constant so that NiMvJSRyaG9HKiYlIk1HIiIiKioiIiVGJyUjcGlHRiclIlJHIiIkRiwhIiJGLQ== . The answer is NiMqKiIiIyIiIiUiTUdGJSUiUkdGJCIiJiEiIg== . (b) Use Maple to find the moment of inertia of a cone of height NiMlIkxH and base radius NiMlIlJH about the symmetry axis of the cone (the axis from the sharp tip to the center of the bottom). This is most easily done in cylindrical coordinates in which NiMvJSNkVkcqLCUickciIiIlI2RyR0YnJSJkR0YnJSRwaGlHRiclI2R6R0Yn and NiMvJSJzRyUickc= . Assume again that the mass density is constant so that NiMvJSRyaG9HKiYlIk1HIiIiKiolI3BpR0YnKiQlIlJHIiIjRiclIkxHRiciIiQhIiJGLw== . Go to top of section<Text-field bookmark="Integrating special functions (top)" layout="_pstyle10" style="_pstyle10">Integrating special functions</Text-field>DebuggingMaple can also do integrals of special functions like Bessel functions, Legendre functions, etc. Sometimes it will give you a nice answer and sometimes it will either just give you the integral back (meaning it doesn't know how to do it) or give you an answer so ugly it makes your eyeballs bleed. When either of these bad things happens, don't give up. Sometimes if you play with the integral a little you can get a better answer. And if all you need is a number, then Maple can always give you one via evalf. For instance, suppose you needed to do this Bessel function integralNiMtJSRJbnRHNiQtJiUiSkc2IyIiITYjJSJ4Ry9GLDtGKiIiIg==You might first try thisrestart;s1:=Int(BesselJ(0,x),x=0..1);value(s1);and be annoyed because you haven't ever heard of Struve functions. What you really want is just a number, which you can get via evalf (Maple knows all about Struve functions even if you don't) or by the following subtle change in the command (watch the decimal points).s1:=Int(BesselJ(0,x),x=0..1.);value(s1);That little decimal point on the 1. makes all the difference. Ok, here are some exercises for you to practice on.Problem 3.12Try doing the following Bessel function integrals both as indefinite integrals and as definite integrals on the interval [1.0..2.0].(a) NiMtJSRpbnRHNiQtJiUiSkc2IyIiITYjJSJ4R0Ys (b) NiMtJSRpbnRHNiQqJi0mJSJKRzYjIiIhNiMlInhHIiIiRi1GLkYt (c) NiMtJSRpbnRHNiQtJiUiS0c2IyIiITYjJSJ4R0Ys (d) NiMtJSRpbnRHNiQtJiUiSUc2IyIiIjYjJSJ4R0Ys(Note that you get these functions with BesselJ(0,x), BesselK(0,x), and BesselI(1,x).------------------------------------------------------------------Problem 3.13Try doing the following Legendre polynomial integrals both as indefinite integrals and as definite integrals on the interval [-1.0..1.0].(a) NiMtJSRpbnRHNiQqJi0mJSJQRzYjIiIjNiMlInhHIiIiKiRGLUYrRi5GLQ== (b) NiMtJSRpbnRHNiQqJi0mJSJQRzYjIiIkNiMlInhHIiIiLSZGKTYjIiImRixGLkYt (Note: to get these functions you have to use the command with(orthopoly) first, then P(3,x), etc.)------------------------------------------------------------------Problem 3.14You might have been surprised at the answer to part (b) of the previous problem when you did it as a definite integral. This is not just a surprise, it is a miracle, and it goes by the name of orthogonality. You will study this idea in detail in Mathematical Physics, but this seems like a nice place to give you an introduction to it. If I were to ask you to check whether two vectors were orthogonal, you would know just what to do. You would take their dot product, and if it turned out to be zero, then you would know that they are orthogonal. And how would you take the dot product? You would multiply the like components of the two vectors together and add them up, e.g., [1,2,3] dot [4,5,6] = 4 + 10 + 18 = 32Well, an integral like this NiMtJSRpbnRHNiQqJi0mJSJQRzYjIiIkNiMlInhHIiIiLSZGKTYjIiImRixGLi9GLTssJEYuISIiRi4= is really just the same thing. At each value of NiMlInhH the two function values are multiplied together and the integral adds them all up. So it makes sense to say that two functions are orthogonal. It turns out that many functions have nice orthogonality properties, and in this exercise you will use Maple to see what they are like.(a) Show, using Maple, that the functions NiMtJSRzaW5HNiMqJiUibUciIiIlInhHRig= and NiMtJSRjb3NHNiMqJiUibUciIiIlInhHRig= are orthogonal to each other when integrated over the interval NiM3JCIiISomIiIjIiIiJSNQaUdGJw== by finding the values of the following integrals both with NiMlIm1H and NiMlIm5H unequal and with NiMvJSJtRyUibkc= .NiMtJSRpbnRHNiQqJi0lJGNvc0c2IyomJSJtRyIiIiUieEdGLEYsLUYoNiMqJiUibkdGLEYtRixGLC9GLTsiIiEqJiIiI0YsJSNQaUdGLA==NiMtJSRpbnRHNiQqJi0lJHNpbkc2IyomJSJtRyIiIiUieEdGLEYsLUYoNiMqJiUibkdGLEYtRixGLC9GLTsiIiEqJiIiI0YsJSNQaUdGLA==NiMtJSRpbnRHNiQqJi0lJGNvc0c2IyomJSJtRyIiIiUieEdGLEYsLSUkc2luRzYjKiYlIm5HRixGLUYsRiwvRi07IiIhKiYiIiNGLCUjUGlHRiw=(Hint: you will get a mess unless you use assume to tell Maple that NiMlIm1H and NiMlIm5H are integers. Apparently Maple assumes more than that they are integers; it also assumes that they are different integers, so you will have to do the NiMvJSJtRyUibkc= case by using the command m:=n.)(b) Show, using Maple (this problem is an extension of Problem 3.13 above), that the Legendre functions NiMtJiUiUEc2IyUibkc2IyUieEc= are orthogonal to each other when two functions with different NiMlIm5H -values are integrated over the interval [-1.0..1.0]. Also find the value of NiMtJSRpbnRHNiQqJC0mJSJQRzYjJSJuRzYjJSJ4RyIiIy9GLTssJCIiIiEiIkYy . You will need to use the with(orthopoly) command to tell Maple you are going to use these functions. And when you try to find the value of the integral of NiMqJC0mJSJQRzYjJSJuRzYjJSJ4RyIiIw== , you will probably need to try several different values of NiMlIm5H and see if you can find the general formula empirically. This will be easier if you don't force floating point answers by using decimal points on the limits, i.e., use 1 and -1 instead of -1. and 1..(c) Show, using Maple, that the Bessel functions NiMtJiUiSkc2IyIiITYjKiYmJSZhbHBoYUc2IyUibkciIiIlInhHRi4= are orthogonal to each other with respect to the integral NiMtJSRpbnRHNiQqKC0mJSJKRzYjIiIhNiMqJiYlJmFscGhhRzYjJSJwRyIiIiUieEdGMkYyLUYoNiMqJiZGLzYjJSJxR0YyRjNGMkYyRjNGMi9GMztGK0Yy , where the numbers NiMmJSZhbHBoYUc2IyUicEc= and NiMmJSZhbHBoYUc2IyUicUc= are the zeros of NiMtJiUiSkc2IyIiITYjJSJ4Rw== . These zeros are available from the Maple function BesselJZeros(n,m), where NiMlIm5H is the order of the Bessel function, i.e., NiMvJSJuRyIiIQ== for NiMmJSJKRzYjIiIh , NiMvJSJuRyIiIg== for NiMmJSJKRzYjIiIi , etc, and where NiMlIm1H counts the zeros (NiMlInBH and NiMlInFH are NiMlIm1H -values), starting with the first one. (For example BesselJZeros(0.,1) gives 2.404825558; notice the decimal point--it is important.) Then see if you can find a formula for this integral when NiMvJSJwRyUicUc= . (Hint: when you set NiMvJSJwRyUicUc= you will just get meaningless numbers because BesselJZeros gives you floating point numbers back. You can do better than this. Replace BesselJZeros(0.,n) with BesselJZeros(0,n) (no decimal point) and let Maple try to do the integral symbolically. You will get a simple answer.------------------------------------------------------------------Problem 3.15Let's go back to the associated Legendre functions and plot them so that they all have about the same size. We could scale them by their maximum values, but then we would have to find the zeros of large polynomials, which is hard. It is actually easier to "calculate their magnitudes" in the same function-dot-product sense used in Problem 3.14. To find the magnitude of a vector we square the components, add the squares up, then take the square root. The corresponding operation for functions is: square the function, integrate it over the relevant interval, then take the square root. Here is the associated Legendre function definition again from Problem 3.4Pnm:=(n,m,x)-> (-1)^m*sqrt(1-x^2)^m*diff(P(n,x),x$m);The magnitude of this function is obtained from NiMvLSUkYWJzRzYjJiUiUEc2IyUjbm1HLSUlc3FydEc2Iy0lJGludEc2JCokLUYnNiMlInhHIiIjL0Y0OywkIiIiISIiRjk= . Redo the plots in Problem 3.4, but divide each of the plotted functions by this magnitude and check to see that they all have about the same size on the new plot.---------------------------------------------------------------------------------Problem 3.16Finally, let's see what Maple does with the integrals of a few miscellaneous functions. Try to get Maple to do (a-c) both as indefinite integrals and as definite integrals between .5 and 1. Do (d) only as a definite integral.(a) NiMtJSRpbnRHNiQtJSZHQU1NQUc2IyUieEdGKQ==(b) NiMtJSRpbnRHNiQtJSRlcmZHNiMlInhHRik=(c) NiMtJSRpbnRHNiQtJSJLRzYjJSJ4R0Yp (Maple's EllipticK)(d) NiMtJSRpbnRHNiQtJSRleHBHNiMsJCklInhHLSUmRmxvYXRHNiQiI0IhIiJGMC9GKzsiIiEiIiI= (Note: try this integral with both integer 1 and floating point 1. as the upper limit.)This should teach you that sometimes Maple can't do indefinite integrals, that it can give you a floating point number for a definite integral but you might have to insist on it by using evalf, and that sometimes it will give you the wrong answer (Maple 7 and 8) or just take forever (Maple 9). (Plot NiMtJSRleHBHNiMsJCklInhHLSUmRmxvYXRHNiQiI0IhIiJGLQ== between 0 and 1 to figure out which of the two answers Maple 7 and 8 gave you for (d) is wrong. In Maple 9 notice how quickly the numerical answer comes back when you use decimal points on your limits.) Maple doesn't make many mistakes, but occasionally it louses up. This means that you have to be very careful and not trust Maple, or any other computer program, too much. Indeed, a good rule to follow upon receiving an answer from any computer program is to quietly mutter under your breath, "Well, that's probably wrong."Go to top of section<Text-field bookmark="Multiple integrals (top)" layout="_pstyle10" style="_pstyle10">Multiple Integrals</Text-field>DebuggingMultiple integrals show up all the time in physics problems, things like NiMtJSRJbnRHNiQtRiQ2JC0lJGVyZkc2IyomJSJ4RyIiIi0lJHNpbkc2IyUieUdGLS9GLDsiIiFGLS9GMUYz . A double integral like this can be done in Maple with nested int commands, like thisrestart;s1:=Int(Int(erf(x*sin(y)),x=0..1),y=0..1);s1:=value(s1);As usual, if Maple just gives it back to you as a displayed integral it means it can't do it, but if you want a number you can use evalf evalf(s1);Or, if you just wanted a number in the first place, you can tell Maple to do the integral numerically using this commandevalf(Int(Int(erf(x*sin(y)),x=0..1.),y=0..1.));A variation on this command tells Maple to only compute the integral numerically accurate to 6 (or any other number) of significant figures (the ,6 after the integration range specifies the number of digits.)evalf(Int(Int(erf(x*sin(y)),x=0..1.,6),y=0..1.,6));You might want to use this if Maple is taking forever to give you the answer--it will go faster if you ask for fewer significant figures. ------------------------------------------------------------------Problem 3.17Get the numerical answer to this double integral NiMtJSRJbnRHNiQtRiQ2JC0mJSJKRzYjIiIhNiMtJSVzcXJ0RzYjKiYlInhHIiIiJSJ5R0YzL0YyO0YzIiIjL0Y0RjY= .------------------------------------------------------------------Triple integrals:It also often happens that you want to do triple integrals, perhaps like NiMtJSRJbnRHNiQtRiQ2JC1GJDYkLSUkZXJmRzYjKiYlInhHIiIiLSUkc2luRzYjKiYlInlHRi8lInpHRi9GLy9GLjsiIiFGLy9GNEY3L0Y1Rjc= . The straightforward Maple command to do this isrestart;s1:=Int(Int(Int(cos(x)*erf(x*sin(y*z)),x=0..1),y=0..1),z=0..1);value(s1);And when Maple gives it back unevaluated (or takes forever thinking about how to do it), you can get the numerical answer with evalf. evalf(s1);Problem 3.18Use the triple integral method defined above to get the numerical value of the following triple integral in spherical coordinatesNiMtJSRJbnRHNiQtRiQ2JC1GJDYkKiolInJHIiInLSUkc2luRzYjJSZ0aGV0YUciIiQtJSRjb3NHNiMqKEYrIiIiRjBGNiUkcGhpR0Y2IiIjLCZGNkY2KiRGLUY4RjZGNi9GKzsiIiFGOC9GMDtGPSUjUGlHL0Y3O0Y9KiZGOEY2RkBGNg== .Make sure your answer is accurate to 4 significant figures. Even this level of accuracy will take some time to achieve. It would be worth your while to try to find a way to do one of these integrals analytically so that you only have to do a double integral instead of a triple one. Another way to do double, and even triple, integrals is with the routines in the student package. These are a collection of routines written to support a calculus course and you can gain access to them with the commandwith(student);To see what these routines do and how to use them use?studentGo to top of sectionGo to top of section<Text-field bookmark="Series expansions (top)" layout="_pstyle6" style="_pstyle6">Series expansions</Text-field>DebuggingOne of the most important mathematical ideas in all of physics is the idea of a series solution to a problem. This is so useful in physics because we usually are not interested in the most exact solution to a problem, but rather in the most illuminating solution to a problem. Consider, for example, the function NiMtJSVzZWNoRzYjJSJ4Rw== . This is a function you should know, and even learned about once, but have since forgotten. And even if you happen to remember that it is the reciprocal of the hyperbolic cosine function, this probably doesn't help you to visualize it very well. But what if I were to tell you that near zero this function is approximated by the simple function NiMsJiIiIkYkKiYlInhHIiIjRichIiJGKA== ? Now you can see that it is 1 at NiMvJSJ4RyIiIQ== and that it falls off like a parabola in both directions from NiMvJSJ4RyIiIQ== . And then what if I told you that for NiMtJSRhYnNHNiMlInhH very large the function is approximated by the function NiMqJiIiIyIiIiklImVHLCQtJSRhYnNHNiMlInhHISIiRiU= ? Now you can see that it falls to zero exponentially away from NiMvJSJ4RyIiIQ== , so the function just looks like a haystack. Maple knows how to find approximations like this to most of the functions it deals with. The commands that find these approximations are taylor, series, and asympt; we will see how they work in this section. Taylor's theorem is: that if a function NiMtJSJmRzYjJSJ4Rw== has well-behaved derivatives at the point NiMvJSJ4RyUiYUc= , then for NiMlInhH near NiMlImFH the function can be approximated by the seriesNiMvLSUiZkc2IyUieEcsKi1GJTYjJSJhRyIiIiomLSUlZGlmZkc2JEYpRidGLCwmRidGLEYrISIiRixGLCooLUYvNiRGKS0lIiRHNiRGJyIiI0YsKiRGMUY5RiwtJSpmYWN0b3JpYWxHNiNGOUYyRiwqKC1GLzYkRiktRjc2JEYnIiIkRiwqJEYxRkNGLC1GPDYjRkNGMkYs + . . .Maple knows this theorem and can use it to generate all kinds of series with the command taylor. For instance, here is the one for the NiMlJXNlY2hH function discussed abovetaylor(sech(x),x=0,20);The x=0 option tells Maple to take the expansion about 0 and the 20 tells it to include terms until the error term is of order NiMqJCUieEciIz8= .Problem 3.19Find the Taylor expansions of the following functions about NiMvJSJ4RyIiIQ== and keeping terms out to NiMqJCUieEciIzU= .(a) NiMtJSRzaW5HNiMlInhH (b) NiMtJSRjb3NHNiMlInhH (c) NiMtJSdhcmN0YW5HNiMlInhH (d) NiMtJSRleHBHNiMlInhH (e) NiMtJSNsbkc2IywmIiIiRiclInhHRic= (f) NiMpLCYiIiJGJSUieEdGJSUicEc=Your answers will look pretty impressive, but you will find that in most physics problems where expansions are important, we only keep the first two terms, so you can often get what you want without all of the clutter by using taylor(f(x),x=0,3), which just goes through NiMqJCUieEciIiM= . ------------------------------------------------------------------Once you find the expansion you need you probably want to use it as a Maple expression to get on with the problem at hand. Maple has a nice command to convert the series created by taylor into a polynomial: convert(series,polynom), where series is the Taylor series. For example,f:=taylor((1+x^2)^(3/2),x=0,5);f:=convert(f,polynom);Problem 3.20Maple can also do Taylor expansions of special functions. Find the expansions of (a) NiMtJiUiSkc2IyIiITYjJSJ4Rw== , (b) NiMtJiUiSUc2IyIiIzYjJSJ4Rw== , (c) NiMtJSJLRzYjJSJ4Rw== (complete elliptic integral EllipticK), and (d) NiMtJSZHQU1NQUc2IyUieEc= . Do (a)-(c) about NiMvJSJ4RyIiIQ== and (d) about NiMvJSJ4RyIiIg== .Do each one through NiMqJCUieEciIzU= . The answer to (d) is pretty awful--see if you can get something more reasonable by using evalf, or by telling Maple to expand about x=1.0 (decimal point again).------------------------------------------------------------------Problem 3.21Now try expanding the Bessel function NiMtJiUiS0c2IyIiITYjJSJ4Rw== about NiMvJSJ4RyIiIQ== . Maple will fail, but it will make a suggestion, and it is a good one. If the function in question has a singularity of some kind at the expansion point, then either the function or some of its derivatives do not exist at that point and a Taylor series is not possible. But there are other kinds of series that can approximate functions, and Maple's series command, which works almost like taylor (but is more general) can give them to you. Try series(BesselK(0,x),x=0,3); and see what happens. Notice that by ignoring most of this mess and concentrating just on the leading term you can tell that NiMtJiUiS0c2IyIiITYjJSJ4Rw== is logarithmically singular. (Notice also that Euler's constant NiMlJmdhbW1hRw== appears in this expansion. To learn a little about it use ?gamma .) When you get this to work, try the same thing on the following functions:(a) NiMtJSRjb3RHNiMlInhH (b) NiMqJiIiIkYkLSUldGFuaEc2IyUieEchIiI= (c) NiMqJi0lJXNxcnRHNiMlInhHIiIiLSUkc2luRzYjKiRGJyIiIyEiIg== .Try different numbers in place of the 3 in the series command above and see if you can tell precisely what it means.------------------------------------------------------------------Problem 3.22There is another kind of expansion that is very useful in mathematical physics: the asymptotic expansion. It is an expansion about NiMlKWluZmluaXR5Rw== , which seems odd, but all it means is that we want to know how a function behaves when its argument is really big. The Maple command that does this is asympt(f,x,2) (or series(f,x=infinity,2)) where f is a Maple expression. Try this on the following functions using series on (a)-(b) and asympt on (c)-(d). Only keep 2 terms, as indicated in the sample commands just above. (a) NiMtJiUiSkc2IyIiITYjJSJ4Rw== (b) NiMtJiUiSUc2IyIiIjYjJSJ4Rw== (c) NiMtJiUiS0c2IyIiITYjJSJ4Rw== (d) NiMtJSZHQU1NQUc2IyUieEc= .I have suggested that you only put a 2 in the last slot because usually all we care about in an asymptotic expansion is the leading term because it answers the most important questions: (1) does the function blow up or die? and (2) in what way does it do it?------------------------------------------------------------------Problem 3.23Here's an example of how we use this idea to solve physics problems. The equation of motion of a pendulum isNiMvLSUlZGlmZkc2JCUmdGhldGFHLSUiJEc2JCUidEciIiMsJCooJSJnRyIiIi0lJHNpbkc2I0YnRjAlIkxHISIiRjU=where the angle NiMlJnRoZXRhRw== is zero if the pendulum hangs straight down and is NiMlI3BpRw== if the pendulum is balancing straight up (think a rod pendulum, not a string one).Maple can solve this equation, but the answer looks both ugly and unfamiliar. So what we would like to do is look at this equation near some special values of NiMlJnRoZXRhRw== (like straight down: NiMvJSZ0aGV0YUciIiE= and straight up: NiMvJSZ0aGV0YUclI3BpRw== ) and see if we can change this hard differential equation into an approximate easier one. (Note the rest of this problem will only make sense if you know what the solutions of these two differential equations look like: (i) NiMvLSUlZGlmZkc2JCUieEctJSIkRzYkJSJ0RyIiIywkKiYlJm9tZWdhR0YsRiciIiIhIiI= and (ii) NiMvLSUlZGlmZkc2JCUieEctJSIkRzYkJSJ0RyIiIyomJSZvbWVnYUdGLEYnIiIi .The first one is the simple harmonic oscillator whose solutions just wiggle up and down sinusoidally at frequency NiMlJm9tZWdhRw== like this: NiMtJSRjb3NHNiMqJiUmb21lZ2FHIiIiJSJ0R0Yo or NiMtJSRzaW5HNiMqJiUmb21lZ2FHIiIiJSJ0R0Yo ; the second one has a growing exponential NiMtJSRleHBHNiMqJiUmb21lZ2FHIiIiJSJ0R0Yo for one of its solutions, so it represents unstable motion. Remember these two forms, one with a positive coefficient on the right and one with a negative one as you continue with this problem.) The pendulum equation with NiMtJSRzaW5HNiMlJnRoZXRhRw== in it can be made to look like these simpler equations by using a series expansion. (a) Expand the right-hand side of the pendulum equation about the downward equilibrium position at NiMvJSZ0aGV0YUciIiE= and by comparing it to (i) and (ii) show that simple harmonic oscillation results. (b) Expand the right-hand side of the pendulum equation about the vertical equilibrium position at NiMvJSZ0aGV0YUclI1BpRw== . After you expand make the u-substitution NiMvJSZ0aGV0YUcsJiUkcGhpRyIiIiUjcGlHRic= in the pendulum equationNiMvLSUlZGlmZkc2JCUmdGhldGFHLSUiJEc2JCUidEciIiMsJCooJSJnRyIiIi0lJHNpbkc2I0YnRjAlIkxHISIiRjU=to get a differential equation in NiMlJHBoaUc= . Compare the resulting equation with (i) and (ii) to show that this new equation has unstable solutions. (This is really just a fancy mathematical way of saying something you already know: if you hang a yardstick straight down and wiggle it a little, it just swings back and forth; if you balance a yardstick straight up and wiggle it a little it falls over.)------------------------------------------------------------------Problem 3.24In Einstein's theory of relativity the energy of an object of mass NiMlIm1H moving at speed NiMlInZH is given by the famous formula NiMvJSJFRyooJSJtRyIiIiokJSJjRyIiI0YnLSUlc3FydEc2IywmRidGJyomJSJ2R0YqRighIiJGMUYx . An interesting question is: what happened to good old kinetic energy NiMvJSJLRyooJSJtRyIiIiokJSJ2RyIiI0YnRiohIiI= from freshman physics? The answer is obtained by means of a Taylor expansion. Assume that the object is moving at much less than the speed of light and make a series expansion of Einstein's formula in NiMlInZH , keeping two terms. One of them will be your old friend and the other is Einstein's idea of rest energy: objects with mass have energy.------------------------------------------------------------------Problem 3.25The formula from freshman electricity and magnetism for the potential (voltage) of a point charge isNiMvLSUiVkc2IyUickcqJiUicUciIiIqKiIiJUYqJSNwaUdGKiYlKGVwc2lsb25HNiMiIiFGKkYnRiohIiI= . The formula for the potential of a dipole is usually not introduced until later, but Maple can help you find it. A dipole is a pair of point charges, one with charge NiMlInFH and the other with charge NiMsJCUicUchIiI= , separated by distance NiMlImRH . Their dipole moment is denoted by the symbol NiMlInBH with magnitude NiMvJSJwRyUjcWRH . Let's place the positive charge on the z-axis at NiMqJiUiZEciIiIiIiMhIiI= and the negative charge on the z-axis at NiMsJComJSJkRyIiIiIiIyEiIkYo . If we do this and use spherical coordinates then the potential as a function of distance NiMlInJH from the origin and polar angle NiMlJnRoZXRhRw== isNiMvLSUiVkc2JCUickclJnRoZXRhRyooJSJxRyIiIiwmKiZGK0YrLSUlc3FydEc2IywoKiRGJyIiI0YrKiYlImRHRjMiIiUhIiJGKyooRidGK0Y1RistJSRjb3NHNiNGKEYrRjdGN0YrKiZGK0YrLUYvNiMsKEYyRitGNEYrRjhGK0Y3RjdGKyooRjZGKyUjcGlHRismJShlcHNpbG9uRzYjIiIhRitGNw==Make a series expansion of this formula in small separation distance NiMlImRH and just keep the leading term to find the formula for the potential of a dipole in spherical coordinates. Help Maple out by using assume(r>0). You may have to experiment with the order of the expansion--1 won't get the job done. You may also find it helpful to use the 'leadterm' form of the series command. Look it up in online help using ?series[leadterm].Go to top of section<Text-field bookmark="Sums (top)" layout="_pstyle6" style="_pstyle6">Sums</Text-field>DebuggingYour calculus class was also where you got introduced to the idea of infinite sums. Maple knows all about them and can do some pretty amazing things. Consider my personal favorite NiMtJSRzdW1HNiQqJiIiIkYnKiQlIm5HIiIjISIiL0YpO0YnJSlpbmZpbml0eUc= . The Maple command that does this is sum and its syntax is about the same as int's syntax: (Note: Sum is the inert form.) Tryrestart;sum(1/'n'^2,'n'=1..infinity);a lovely and unexpected result. In this form the first argument of sum is an expression. Note a peculiarity of Maple in this command: the index n is in single quotes. You don't always have to do this, but if you don't then Maple will fail you at some point in your computational life, so you ought to at least know about this use of single quotes. (The single quotes tell Maple to use NiMlIm5H as a dummy variable in this command ignoring any possible previous assignments of something to the variable NiMlIm5H .) Having made you aware of this feature, I'm going to ignore it because typing quotes is awkward.The sum command, and its inert form Sum, also work with functions.fn:=n->1/n^2;s1:=Sum(fn(n),n=1..infinity);value(s1);To see what the possibilites are for doing sums are in Maple are, take a minute and look at ?sum. Here are some exercises for practice.Problem 3.26Find each of these sums using expression form for (a)-(c) and function form for (d)-(f).(a) NiMtJSRzdW1HNiQqJCUibkciIiQvRic7IiIiJSJORw== (b) NiMtJSRzdW1HNiQqJiksJCIiIiEiIiUibkdGKSokRisiIiNGKi9GKztGKSUpaW5maW5pdHlH (c) NiMtJSRzdW1HNiQqJiwmKiYiIiMiIiIlIm5HRipGKiIiJEYqRioqKCwmRitGKkYqRipGKiwmRitGKkYpRipGKiwmRitGKkYsRipGKiEiIi9GKztGKiUpaW5maW5pdHlH(d) NiMtJSZsaW1pdEc2JCwmLSUkc3VtRzYkKiYiIiJGKyUibkchIiIvRiw7RislIk5HRistJSNsbkc2I0YwRi0vRjAlKWluZmluaXR5Rw== . Note: NiMlIk5H goes to infinity in both terms, not just in the sum. The funny little symbol you will get is not a mistake, but a very famous number denoted by the symbol NiMlJmdhbW1hRw== (gamma). It is called Euler's constant. Check how big it is with evalf.(e) NiMtJSRzdW1HNiQqJiklInhHJSJuRyIiIkYpISIiL0YpO0YqJSlpbmZpbml0eUc= (f) NiMtJSRzdW1HNiQqJiklInhHJSJuRyIiIiomRilGKiwmRilGKkYqRipGKiEiIi9GKTtGKiUpaW5maW5pdHlHGo to top of sectionGo to top of chapter<Text-field bookmark="Complex stuff (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 4: Complex numbers and functions</Text-field>You first learned about complex numbers when an algebra teacher tried to convince you that NiMtJSVzcXJ0RzYjLCQiIiIhIiI= made sense. It doesn't just make sense; it is a powerful way to model the real world we live in, in spite of i being a so-called "imaginary number". Maple knows all about the complex plane, starting with a special variable to represent NiMtJSVzcXJ0RzYjLCQiIiIhIiI= : Maple calls it NiMlIklH ; yes, capital I. So in Maple the complex number 5 + 3i would be written this wayrestart;z1:=5 + 3*I;You need to be careful with this syntax because Maple will allow you to use i, like this:z2:=5+3*i;This looks fine, but when you do arithmetic with "i" it won't work right because i is just another variable that doesn't have a value yet. Only I is the real thing. (Actually, you can redefine I to be i if you want by using the interface command, but I suggest you don't.)In this chapter we will review the various things you can do in the complex plane, including arithmetic, calculus, and even special functions like NiMtJiUiSkc2IyIiITYjJSJ6Rw== and NiMtJSZHYW1tYUc2IyUiekc= . Note: in this chapter whenever you encounter a variable with a name like z, or z1, or z2, etc, it is a complex variable of the form NiMvJSJ6RywmJSJ4RyIiIiomJSJJR0YnJSJ5R0YnRic= .<Text-field bookmark="Complex arithmetic (top)" layout="_pstyle6" style="_pstyle6">Complex arithmetic</Text-field>DebuggingLet's review what you can do with complex numbers. First, there is simple addition and subtraction. And since the rule is that real parts add and imaginary parts add, if you think about the real numbers being the x-axis and the imaginary numbers being the y-axis, together forming the complex xy-plane, then it is not too hard to see that complex addition and subtraction are just addition and subtraction of vectors in this 2-dimensional plane. And Maple knows how to do it:z1:=5+3*I;z2:=1-6*I;z3:=z2+z1;Just for fun, here's how this addition problem looks using arrows in the complex plane. (Note: I am showing you some of Maple's tools for drawing pictures in the commands below, so there is more useful information here than just the discussion of complex arithmetic). In the pictures z1 is green, z2 is blue, and z3 is red.with(plottools):
L1 := arrow([0,0], [5,3], .2, .5, .1, color=green):
L2 := arrow([0,0], [1,-6], .2, .5, .1, color=blue):
L3 := arrow([0,0], [6,-3],.2,.5,.1,color=red):plots[display](L1,L2,L3, axes=normal,view=[-10..10,-10..10]);
OK: addition and subtraction are easy. Multiplication and division, however, are not anything like the vector products you know about from your physics classes. The complex multiplication rule is simple enough: just treat the real and imaginary parts like variables in algebra and multiply everything out, remembering that NiMvKiQlIklHIiIjLCQiIiIhIiI= . Here, for example is a multiplication:(5+3I)*(1-6I) = (5 + 3I -30I + 18) = 23-27I . You just use the distributive law and work it out. And Maple knows how to do it:z1*z2;Division is a little trickier because I appears in the denominator. We take care of this problem with the idea of the complex conjugate. The complex conjugate of z1 is almost the same as z1, except that the sign of the imaginary part of z1 has its sign changed, like this:conjugate(6+4*I);The conjugate is useful because of what the product of a complex number and its conjugate turn out to be:conjugate(6+4*I)*(6+4*I);assume(x,real);assume(y,real);conjugate(x+y*I)*(x+y*I);expand(%);Their product is just a real number, equal to the square of the magnitude of the complex number, treated as a vector in the usual Pythagorean way: square the components and add. The answer is NiMvLCYqJCIiJyIiIyIiIiokIiIlRidGKCIjXw== . This is useful for doing division because if you multiply the top and bottom of a complex fraction by the conjugate of the bottom, the bottom becomes real and you don't have to worry about I in the denominator anymore. Just multiply the numerator out using the distributive law and divide both real and imaginary parts by the real number in the bottom.Problem 4.1Work out by hand the complex division problem NiMqJiwmIiIkIiIiKiYiIiVGJiUiSUdGJkYmRiYsJiIiI0YmKiYiIiZGJkYpRiYhIiJGLg== , then do it with Maple and show that the answers agree.---------------------------------------------------------------------------------------------Ok, this is simple enough to do, but what does it mean? Is there a picture in the complex plane that allows us to visualize what multiplication and division mean? Well, there is; but to understand it we need to have another way of thinking about complex numbers. When we write 5+4I we are using Cartesian coordinates in the complex plane. But it is useful to use polar coordinates in the complex plane as well. In polar coordinates the number 5+4I would be represented by a radius of magnitude NiMvLSUlc3FydEc2IywmKiQiIiYiIiMiIiIqJCIiJUYqRistRiU2IyIjVA== , and an angle NiMlJnRoZXRhRw== measured counterclockwise from the real axis, with NiMvJSZ0aGV0YUctJSdhcmN0YW5HNiMqJiIiJSIiIiIiJiEiIg== , like thiswith(plottools):
L1 := arrow([0,0], [5,4], .2, .5, .1, color=green):
L2 := arc([0,0],4,0..arctan(.8),color=red):plots[display](L1,L2, axes=normal,view=[-5..5,-5..5],scaling=constrained);
Polar coordinates give us a wonderful way to visualize complex numbers. The connection between the complex number represented by x + iy and the polar form (NiQlInJHJSZ0aGV0YUc= ) is just a simple exercise in trigonometry: NiMvJSJ4RyooJSJyRyIiIiUkY29zR0YnJSZ0aGV0YUdGJw== and NiMvJSJ5RyomJSJyRyIiIi0lJHNpbkc2IyUmdGhldGFHRic= . The Swiss mathematician Leonhard Euler discovered that the exponential function applied to a purely imaginary number gives the remarkable result NiMvKSUiZUcqJiUiaUciIiIlJnRoZXRhR0YoLCYtJSRjb3NHNiNGKUYoKiZGJ0YoLSUkc2luR0YtRihGKA== . This means that the connection between the Cartesian and polar forms of complex numbers can be written in this compact form: NiMvLCYlInhHIiIiKiYlImlHRiYlInlHRiZGJiomJSJyR0YmKSUiZUcqJkYoRiYlJnRoZXRhR0YmRiY= . And this form, combined with the properties of the exponential function under multiplication and division, allows us to interpret what complex multiplication and division mean. Let's look at multiplication first. Writing NiMvJiUiekc2IyIiIiomJiUickdGJkYnKSUiZUcqJiUiaUdGJyYlJnRoZXRhR0YmRidGJw== and NiMvJiUiekc2IyIiIyomJiUickdGJiIiIiklImVHKiYlImlHRismJSZ0aGV0YUdGJkYrRis= allows us to see that their product can be written as NiMvKiYmJSJ6RzYjIiIiRigmRiY2IyIiI0YoKigmJSJyR0YnRigmRi5GKkYoKSUiZUcqJiUiaUdGKCwmJiUmdGhldGFHRidGKCZGNkYqRihGKEYo . So this is what multiplication means: the product has a magnitude which is the product of the magnitudes of NiMmJSJ6RzYjIiIi and NiMmJSJ6RzYjIiIj and an angle which is the sum of the angles of NiMmJSJ6RzYjIiIi and NiMmJSJ6RzYjIiIj , as shown in the picture below. The two complex numbers NiMmJSJ6RzYjIiIi and NiMmJSJ6RzYjIiIj are in green and their product is in red.with(plottools):
L1 := arrow([0,0], [1,2], .1, .3, .1, color=green):
L1a := arc([0,0],1.5,0..arctan(2),color=green):L2 := arrow([0,0], [1,.8], .1, .3, .1, color=green):
L2a := arc([0,0],.75,0..arctan(.8),color=green):L3 := arrow([0,0], [-.6,2.8], .1, .3, .1, color=red):
L3a := arc([0,0],2.5,0..arctan(2.8,-.6),color=red):plots[display](L1,L2,L3,L1a,L2a,L3a, axes=normal,view=[-3..3,-3..3],scaling=constrained);
Division works similarly, but with the two magnitudes being divided and the two angles subtracting: NiMvKiYmJSJ6RzYjIiIiRigmRiY2IyIiIyEiIiooJiUickdGJ0YoKSUiZUcqJiUiaUdGKCwmJiUmdGhldGFHRidGKCZGNkYqRixGKEYoJkYvRipGLA== . Well, that's about it for the simple arithmetic. But before proceeding onto more interesting stuff I should mention that Maple has some commands that come in handy when working with complex numbers. Re(z) picks off the real part of z, Im(z) gives you the imaginary part, abs(z) gives you the polar magnitude, and arctan(Im(z),Re(z)) gives you the angle, like thisz:=5-3*I;Re(z);Im(z);abs(z);arctan(Im(z),Re(z));Maple also has a command that converts z in Cartesian form into polar form, but I find it hard to use its results in subsequent calculations, so I usually just use the arctan form given above. But here it is anyway.readlib(polar):polar(z);And finally, remember that Maple will take the complex conjugate for you.conjugate(3+4*I);Problem 4.2Do the operations indicated below on the complex numbers NiMmJSJ6RzYjIiIi and NiMmJSJ6RzYjIiIj and express your answers in both Cartesian (x+iy) form and polar form (readlib(polar): and the polar command make this problem easy).Here are the definitions of z1 and z2 that you are supposed to use in this problem:z1:=3-5*I;z2:=-2+3*I;(a) NiMsJiYlInpHNiMiIiJGJyZGJTYjIiIjRic= (b) NiMsJiYlInpHNiMiIiJGJyZGJTYjIiIjISIi (c) NiMqJiYlInpHNiMiIiJGJyZGJTYjIiIjRic= (d) NiMqJiYlInpHNiMiIiJGJyZGJTYjIiIjISIi----------------------------------------------------------------------------------------------Problem 4.3Show graphically, by making a Maple arrow plot like the one shown above, that rotating a complex number through angle NiMlJnRoZXRhRw== in the complex plane is easily accomplished by multiplying by the factor NiMpJSJlRyomJSJpRyIiIiUmdGhldGFHRic= . Do this by defining a complex number z1 and plotting it as an arrow, then multiplying z1 by NiMtJSRleHBHNiMqJiUiSUciIiIlJnRoZXRhR0Yo for some angle NiMlJnRoZXRhRw== that you choose, and then by plotting this new complex number as an arrow. As you do this you need to be careful to only use floating point numbers in the arguments of the arrow command. Maple will probably give you answers back that have square roots of integers in them and if you just copy these numbers into the arrow command no arrow will appear. Our old friend evalf will help you here, as will this syntax for putting the real and imaginary parts of a complex number into the arrow command: [Re(z),Im(z)].Go to top of section<Text-field bookmark="Elementary complex functions (top)" layout="_pstyle6" style="_pstyle6">Elementary complex functions</Text-field>DebuggingAll of the functions you have ever heard of make sense for complex numbers as well as for real numbers. And in fact, the complex plane can give a more unified picture of these functions than is possible when we are confined only to the real axis. We will begin with the exponential function. Euler's formula NiMvKSUiZUcqJiUiaUciIiIlJnRoZXRhR0YoLCYtJSRjb3NHNiNGKUYoKiZGJ0YoLSUkc2luR0YtRihGKA== and the properties of the exponential function allow us to write for NiMpJSJlRyUiekc= (with NiMvJSJ6RywmJSJ4RyIiIiomJSJpR0YnJSJ5R0YnRic= ), NiMvKSUiZUcsJiUieEciIiIqJiUiaUdGKCUieUdGKEYoKiYpRiVGJ0YoLCYtJSRjb3NHNiNGK0YoKiZGKkYoLSUkc2luR0YxRihGKEYo . You may not be able to visualize what this function looks like just by staring at this formula, so to see the behavior of this function over the entire complex plane, let's make a 3-D surface plot of its real part and its imaginary part using Maple's plot3d command (see 3d plot).restart;plot3d(Re(exp(x+I*y)),x=-6..6,y=-6..6,shading=z,axes=framed,labels=["x","y","Re(f)"],orientation=[-60,60],title="Real Part");plot3d(Im(exp(x+I*y)),x=-6..6,y=-6..6,shading=z,axes=framed,labels=["x","y","Im(f)"],orientation=[-60,60],title="Imaginary Part");Notice that at negative x it is very small and for positive x it is very big--this is the behavior of NiMpJSJlRyUieEc= . In y, the functions just oscillate like cosines and sines, which is, of course, exactly what they are.This mixing together of the exponential function and sines and cosines gives rise to several interesting formulas which you are to verify in the next problem.Problem 4.4Use Maple to verify the following functional identities. Do this problem by going to ?evalc, reading it over and looking at the examples, and then using this command to check these identities.(a) NiMvLSUkY29zRzYjJSJ4RyomLCYpJSJlRyomJSJpRyIiIkYnRi5GLilGKywkRiwhIiJGLkYuIiIjRjE= (b) NiMvLSUkc2luRzYjJSJ4RyomLCYpJSJlRyomJSJpRyIiIkYnRi5GLilGKywkRiwhIiJGMUYuKiYiIiNGLkYtRi5GMQ== (c) NiMvLSUkY29zRzYjKiYlImlHIiIiJSJ4R0YpLSUlY29zaEc2I0Yq (d) NiMvLSUkc2luRzYjKiYlImlHIiIiJSJ4R0YpKiZGKEYpLSUlc2luaEc2I0YqRik=-----------------------------------------------------------------------------------------------------Problem 4.5Make 3-D surface plots over the complex plane of the real parts of NiMtJSRjb3NHNiMlInpH and NiMtJSRzaW5HNiMlInpH , and of the imaginary part of NiMtJSR0YW5HNiMlInpH , where NiMvJSJ6RywmJSJ4RyIiIiomJSJpR0YnJSJ5R0YnRic= . Use x in the range -9..9 and y in the range -5..5 for sin and cos; use -5..5 and -3..3 for tan. Stare at them until they make sense. When you do the tangent function you will have to deal with its singularities. Do this by using the view option in the plot, in the form view=-5..5. This vertical size control keeps Maple from trying to plot infinity. It may also help to have a finer grid, which you can get with grid=[30,30]. To make sense of it you will also have to remember what the tanh function looks like.-----------------------------------------------------------------------------------------------------Now let's move on to power-law functions, i.e., we want to study the behavior of NiMpJSJ6RyUicEc= in the complex plane. It is easier to see what this function does if we use the polar representation: NiMvKSUiekclInBHKiYpJSJyR0YmIiIiKSUiZUcqKCUiaUdGKkYmRiolJnRoZXRhR0YqRio= . This behavior is not too hard to visualize for integer powers NiMlInBH . The magnitude is just raised to the NiMlInBH power and the imaginary exponential just wiggles faster as we go around in polar angle.Problem 4.6Make a 3-D plot of the real parts of the functions NiMqJCUiekciIiM= and NiMqJCUiekciIiY= using the range -3..3 in both x and y for NiMqJCUiekciIiM= and a smaller range for NiMqJCUiekciIiY= . ----------------------------------------------------------------------------------------------------For non-integer powers things get a lot more complicated. To see why, let's consider the square root function, NiMvJSJwRyomIiIiRiYiIiMhIiI= . Below I have coded three 3-D plots of this function. The first is of its magnitude, and it just looks like the normal square root function rotated about the z-axis, so this looks like we expected. But there is something funny going on along the negative x-axis in the real part plot, and it gets worse in the imaginary part plot.plot3d(abs((x+I*y)^(1/2)),x=-1..1,y=-1..1,shading=z,axes=framed,labels=["x","y","|f|"],orientation=[-60,45],title="Magnitude",grid=[40,40]);plot3d(Re((x+I*y)^(1/2)),x=-1..1,y=-1..1,shading=z,axes=framed,labels=["x","y","Re(f)"],orientation=[-60,35],title="Real Part",grid=[40,40]);plot3d(Im((x+I*y)^(1/2)),x=-1..1,y=-1..1,shading=z,axes=framed,labels=["x","y","Im(f)"],orientation=[-60,35],title="Imaginary Part",grid=[40,40]);Surely ordinary functions can't behave this way!? Well, they can in the complex plane. Here's the problem. Maple defines its polar angle NiMlJnRoZXRhRw== to be in the range NiM7LCQlI1BpRyEiIkYl . Let's see what the square root function does to these two different values of z: NiMvJiUiekc2IyIiIiklImVHKiYlImlHRiclI3BpR0Yn and NiMvJiUiekc2IyIiIyklImVHLCQqJiUiaUciIiIlI3BpR0YtISIi . The first thing to notice is that NiMmJSJ6RzYjIiIi and NiMmJSJ6RzYjIiIj are exactly the same number, namely -1. The second thing to notice is that the square root function turns the first one into i and the second one into -i ! So the square root of -1 has different answers depending on what angle we use to get to -1 in the complex plane. This is the origin of the cliff face in the imaginary part plot, and the line in the complex plane where the cliff occurs is called a branch cut. Branch cuts are wonderful, and you will study them in more detail when you take a course in complex analysis. All fractional powers have this problem, as does the plain old ordinary log function, ln(z), as you will soon discover.Problem 4.7Do the same thing to the function ln(z) that we just did to square root. Locate the branch cut and explain why it's there by looking at the same problem discussed in the paragraph above. Note: be sure to use the function NiMtJSNsbkc2IywmJSJ4RyIiIiomJSJJR0YoJSJ5R0YoRig= in your plot commands.------------------------------------------------------------------------------------------------------Problem 4.8Finally, do a set of 3-D surface plots of this rather ordinary looking and perfectly well-behaved-along-the-real-axis function NiMvLSUiZkc2IyUiekcqJkYnIiIjLCYiIiJGKyokRidGKUYrISIi (remember that NiMvJSJ6RywmJSJ4RyIiIiomJSJJR0YnJSJ5R0YnRic= ) . First make a plot of f(x) along the real axis so you know what it looks like there. Use the x-range -4..4. Then make surface plots of the real part, the imaginary part, and the magnitude (use abs), again using -4..4 in both dimensions. Also use the option view=-3..3. Hopefully this will give you a sense of the surprise and beauty of the complex plane.Go to top of section<Text-field bookmark="Special complex functions" layout="_pstyle6" style="_pstyle6">Special complex functions</Text-field>DebuggingIt will probably come as no surprise that the more advanced functions of mathematical physics do the same kinds of things in the complex plane that the elementary ones do. Rather than talking about it I'll let you discover a few of the interesting things that happen through these exercises.Problem 4.9Use Maple to show that the Bessel functions NiMtJiUiSkc2IyIiITYjJSJ6Rw== and NiMtJiUiSUc2IyIiITYjJSJ6Rw== are related in the complex plane by asking Maple to evaluate NiMtJiUiSkc2IyIiITYjKiYlImlHIiIiJSJ4R0Yr and NiMtJiUiSUc2IyIiITYjKiYlImlHIiIiJSJ4R0Yr . Also do it for a few more orders of Bessel functions, say n=1,2,3. Then try the same thing for the Bessel function NiMmJSJZRzYjIiIh . In this second case Maple will not tell you anything interesting, even though there is something interesting to be told. It would be nice if it would tell you that NiMvLSYlIllHNiMiIiE2IyomJSJpRyIiIiUieEdGLCwmKiZGK0YsLSYlIklHRic2I0YtRixGLCooIiIjRiwtJiUiS0dGJ0YzRiwlI1BpRyEiIkY6 , but I don't know how to get it to do it. Just as a check, at least, try verifying this identity numerically to see if Maple knows what it's doing. Use NiMvJSJ6RyomJSJJRyIiIiUieEdGJw== for a few real values of x.-----------------------------------------------------------------------------------------------------Problem 4.10Do a 3-D plotting exploration of the behavior of the elliptic integral K(z) in the complex plane. This function is obtained with the Maple command EllipticK(z). Look at its real part and imaginary part with both x and y in the range -2..2.Go to top of section<Text-field bookmark="Wave interference (top)" layout="_pstyle6" style="_pstyle6">Wave interference</Text-field>DebuggingThere are many ways that the complex plane helps us to do physics; perhaps the most important is in the study of phase shifts and interference patterns. This is probably a good time to give you a simple definition of the technical term phase. Phase is anything that appears as the argument of a sine or cosine function. For instance, if an oscillation in time is described by the function NiMtJSRjb3NHNiMqJiUmb21lZ2FHIiIiJSJ0R0Yo , then we say that the phase of the oscillation is changing linearly in time and is simply given by NiMqJiUmb21lZ2FHIiIiJSJ0R0Yl . If the oscillation is shifted in time so that it is given instead by NiMtJSRjb3NHNiMsJiomJSZvbWVnYUciIiIlInRHRilGKSUkcGhpR0Yp , then the new phase of the oscillation is NiMsJiomJSZvbWVnYUciIiIlInRHRiZGJiUkcGhpR0Ym , and we say that relative to the previous oscillation, this one has a phase shift NiMlJHBoaUc= . Phase shifts can be a real pain to handle because they are stuck inside cosines and sines and you have to know lots of trig identities to get simple answers out. But if we remember that NiMvLSUkY29zRzYjKiYlJm9tZWdhRyIiIiUidEdGKS0lI1JlRzYjKSUiZUcqKCUiaUdGKUYoRilGKkYp (that funny script R is Maple's pretty representation of Re, the real part) then lots of formulas can be simplified. Here's an example. Suppose we have 12 different oscillations going like NiMtJSRjb3NHNiMsJiomJSZvbWVnYUciIiIlInRHRilGKSYlJHBoaUc2IyUibkdGKQ== , all interfering with each other by adding together and suppose also that the nth wave has a phase shift given by NiMvJiUkcGhpRzYjJSJuRyoqIiIjIiIiRidGKiUjUGlHRioiIzghIiI= . Using the power of Maple we can add these oscillations together to getrestart;s1:=Sum(cos(omega*t+2*Pi*'n'/13),'n'=1..12);s1:=value(s1);simplify(s1);Well, that's an answer, but it's not very pretty, and it's tough to get Maple to simplify it. Now let's try doing it using the complex plane. Instead of adding 12 cosines together we'll add 12 complex exponentials together. Since the real part of each one is a cosine we can do the complex sum, then take the real part at the end and it will be as if we had added 12 cosines together. The only difference is that the answer will be a lot prettier. Ok, let's see how this goes. Rather than giving the problem to Maple right away, let's do a little pre-analysis first. Here's the sum whose real part we will take at the endNiMtJSRzdW1HNiQpJSJlRywmKiglImlHIiIiJSZvbWVnYUdGKyUidEdGK0YrKiZGKkYrJiUkcGhpRzYjJSJuR0YrRisvRjI7RisiIzc= .We will take out the common factor of NiMpJSJlRyooJSJpRyIiIiUmb21lZ2FHRiclInRHRic= ( notice: time factored out! this is the whole reason for using the complex exponential) and then rewrite the remaining complex exponential this wayNiMvKSUiZUcqLCUiaUciIiIiIiNGKCUjUGlHRiglIm5HRigiIzghIiIpKUYlKipGJ0YoRilGKEYqRihGLEYtRis= . So now our sum looks like thisNiMqJiklImVHKiglImlHIiIiJSZvbWVnYUdGKCUidEdGKEYoLSUkc3VtRzYkKSUiekclIm5HL0YwO0YoIiM3Rig= where NiMvJSJ6RyklImVHKiolImlHIiIiIiIjRiklI1BpR0YpIiM4ISIi . Now Maple can finish it off.z:=exp(I*2*Pi/13);s:=Sum(z^n,n=1..12);s:=simplify(value(s));Finally, we tack on the NiMpJSJlRyooJSJpRyIiIiUmb21lZ2FHRiclInRHRic= we factored out front at the beginning, take the real part, and discover that the big mess of cosine functions in the original Maple sum is just:NiMvLSUkc3VtRzYkLSUkY29zRzYjLCYqJiUmb21lZ2FHIiIiJSJ0R0YtRi0qKiIiI0YtJSNwaUdGLSUibkdGLSIjOCEiIkYtL0YyO0YtIiM3LCQtRig2I0YrRjQ=The lesson here is hopefully clear; if you are doing an interference problem where you have to add up a whole bunch of sines or cosines, do it with complex exponentials instead. Also, don't be discouraged if Maple doesn't give you a simple answer right away. Use what you know about complex numbers to give Maple some extra help.Problem 4.11(Note: this isn't really a problem. Just follow along, execute all of the Maple commands, and pay close attention; some real problems will follow.) Let's do a simple interference problem using complex analysis. The two-slit diffraction pattern is always taught in sophomore physics, but only in the far field approximation. We'll use Maple to do it right. We'll have two sources of light a distance NiMlImRH apart and perpendicular to the line between them at distance NiMlIkxH is a screen. We want to find the intensity of a wave on the screen as a function of distance NiMlInlH on the screen, measured upward from the midline from between the sources to the screen, as shown in the plot below. (Note that this shows you how to draw figures in Maple. Use ?plottools to find more drawing stuff.)restart:with(plots):l1:= listplot([[0,0],[2,0]]): # distance to screent1:= textplot([1,-.1,"L"]): # L label l2 := listplot([[-.08,-.2],[-.1,-.2],[-.1,.2],[-.08,.2]]): # d brackett2:= textplot([-.15,0,"d"]): # d labelp1:= pointplot([0,-.2],symbol=circle): # lower sourcep2:= pointplot([0,.2],symbol=circle): # upper sourcel3:= listplot([[2,-1.25],[2,1.25]]): # screent3:= textplot([2.08,.5,"y"]): # y labell4:= listplot([[0,.2],[2,.6]]): # upper rayt4:= textplot([1.5,.6,"r1"]): # r1 labell5:= listplot([[0,-.2],[2,.6]]): # lower rayt5:= textplot([1.5,.3,"r2"]): # r2 label plots[display]([l1,t1,l2,t2,p1,p2,l3,t3,l4,t4,l5,t5],axes=none,thickness=3,view=[-.5..2.1,-1.25..1.25],font=[HELVETICA,14]);To study the interference of these two sources with as much accuracy as possible we will let the field from each one fall off like NiMqJiklImVHKiYlImlHIiIiLCYqJiUia0dGKCUickdGKEYoKiYlJm9tZWdhR0YoJSJ0R0YoISIiRihGKEYsRjA= from the source. The two distances are given by NiMvJiUickc2IyIiIi0lJXNxcnRHNiMsJiokLCYlInlHRicqJiUiZEdGJyIiIyEiIkYyRjFGJyokJSJMR0YxRic= and NiMvJiUickc2IyIiIy0lJXNxcnRHNiMsJiokLCYlInlHIiIiKiYlImRHRi9GJyEiIkYvRidGLyokJSJMR0YnRi8= so when we add the two fields together to get the total field at the screen we get the kind of mess Maple was invented to handle:Define functions for r1(y) and r2(y) R1:=y-> sqrt((y-d/2)^2+L^2);R2:=y-> sqrt((y+d/2)^2+L^2);The straightforward thing to do now would just be to add the wavefunctions from the two sources, take the real part, and square it to get the intensity, like this:Intensity:= y-> Re( exp(I*k*R1(y)-I*omega*t)/R1(y) + exp(I*k*R2(y)-I*omega*t)/R2(y))^2;Unfortunately, it's not that simple. The problem is with the time. If we just choose some convenient time, like t=0, then we will be comparing instantaneous intensities at different places and at each place the intensity varies between zero and some maximum. We don't want to see fake zeros in our intensity pattern on the screen just because we look at a special time. To get rid of this problem we want to find the time-averaged intensity.Since we usually work with sines and cosines it is useful to know what the time averages of sines, cosines, and their products are:Int(sin(t),t=0..2*Pi)/(2*Pi);value(%);Int(cos(t),t=0..2*Pi)/(2*Pi);value(%);Int(cos(t)*sin(t),t=0..2*Pi)/(2*Pi);value(%);Int(cos(t)^2,t=0..2*Pi)/(2*Pi);value(%);Int(sin(t)^2,t=0..2*Pi)/(2*Pi);value(%);You need to memorize these results: the time averages of NiMtJSRzaW5HNiMlInRH , NiMtJSRjb3NHNiMlInRH , and NiMqJi0lJHNpbkc2IyUidEciIiItJSRjb3NHRiZGKA== are all zero. The time averages of NiMqJC0lJGNvc0c2IyUidEciIiM= and NiMqJC0lJHNpbkc2IyUidEciIiM= are both 1/2. These answers even make sense: sin, cos, and sin*cos all spend equal amounts of time being positive and negative, so they average to zero. Their squares oscillate symmetrically between 0 and 1, so their averages are 1/2.OK, having learned this we can tackle the intensity again. Here's what Maple gives us for the intensity in expression form:assume(k,real,r1,real,r2,real,omega,real,t,real);Intense:= Re( exp(I*k*r1-I*omega*t)/r1 + exp(I*k*r2-I*omega*t)/r2)^2;To make the calculation simpler, let's redefine the arguments of these cosine functions to be x1 and x2, respectively:Intense:=(cos(x1)/r1+cos(x2)/r2)^2;Now expand it like thisIntense:=expand(Intense);and then time average each term.combine(cos(x1)*cos(x2));(Note: to get trig identities try expand, simplify, and combine.) The x1+x2 term goes like NiMqKCIiIyIiIiUmb21lZ2FHRiUlInRHRiU= and time averages to zero, while the x1-x2 term has no time dependence at all, so its time average is just itself. So we getIntense:= 1/(2*r1^2)+cos(x1-x2)/(r1*r2)+1/(2*r2^2);With time averaging complete we can redefine our intensity function of position yIntensity:=y->1/(2*R1(y)^2)+cos(k*R1(y)-k*R2(y))/(R1(y)*R2(y))+1/(2*R2(y)^2);Now define the details of physical situation with d=.01mm, L=1m, and red light of wavelength 600 nmd:=1e-5;L:=1;k:=2*Pi/600e-9;Finally, we can plot the intensity as a function of y to see what the pattern should look like on the screen. We will just look in a window 1 m wide near the center of the pattern and see a beautiful interference pattern.plot(Intensity(y),y=-0.5..0.5);---------------------------------------------------------------------------------------------------Problem 4.12Serway says that the first minimum away from y=0 is at the place where NiMvKiglImtHIiIiJSJkR0YmLSUkc2luRzYjJSZ0aGV0YUdGJiUjUGlH , where NiMlJnRoZXRhRw== is the angle indicated below ( NiMvJSJ5RyomJSJMRyIiIi0lJHRhbkc2IyUmdGhldGFHRic= ). Verify that the first interference minimum in the plot above is at the correct place by measuring y-values on the plot in 4.11 and converting y to angle NiMlJnRoZXRhRw== . Use the same values of the variables that were used in Problem/Example 4.11:restart:with(plots):l1:= listplot([[0,0],[2,0]]): # distance to screent1:= textplot([1,-.1,"L"]): # L label l3:= listplot([[2,-1.25],[2,1.25]]): # screent3:= textplot([2.08,.5,"y"]): # y labell4:= listplot([[0,0],[2,.6]]): # hypotenuset4:= textplot([.6,.1,"q"]): # theta labelp1:=plots[display]([l1,t1,l3,t3,l4],axes=none,thickness=3,view=[-.5..2.1,-1.25..1.25],font=[HELVETICA,14]):p2:=plots[display]([t4],axes=none,thickness=3,view=[-.5..2.1,-1.25..1.25],font=[SYMBOL,20]):display(p1,p2);------------------------------------------------------------------------------------------------Problem 4.13Something that Serway doesn't do is show what happens when the screen gets closer and closer to the source. This is complicated because the two fields no longer have about the same magnitude and the distance functions NiMmJSJyRzYjIiIi and NiMmJSJyRzYjIiIj vary more rapidly with y. Rerun the calculation in Problem 4.11 above twice more, once with L=10d and once with L=2d and comment on what these near-field patterns look like. In particular, does the formula given in Problem 4.12 still work? (Be sure to reduce the window in y over which you plot to an appropriate size; -20d..20d is interesting.) There is a lesson here: things are really complicated when you are close to radiation sources.Go to top of section<Text-field bookmark="Electrostatics with line charges" layout="_pstyle6" style="_pstyle6">Electrostatics with line charges</Text-field>DebuggingThe complex plane is a wonderful place to visualize electric fields and equipotential surfaces. Since the complex plane is only two-dimensional, the only kinds of fields you can visualize there are the fields of infinitely long line charges. It turns out (you will just have to trust me until you take a course in complex analysis) that the complex function NiMvLSUiRkc2IyUiekcsJCooJSdsYW1iZGFHIiIiLSUjbG5HNiMsJkYnRismRic2IyIiISEiIkYrKigiIiNGKyUjUGlHRismJShlcHNpbG9uR0YxRitGM0Yz has the property that its real part is the electrostatic potential of a line charge with charge/length NiMlJ2xhbWJkYUc= located in the xy-plane at complex position NiMmJSJ6RzYjIiIh , and that the lines in the complex plane where the imaginary part is constant are the electric field lines! This function combined with Maple's plotting ability makes it possible to quickly visualize equipotential surfaces and field lines for a variety of line charge arrangements. And in the process we will review how Maple does contour plots (contour plot). Here is a contourplot that shows equipotential surfaces in blue and electric field lines in red for a single line charge. (Since we are just visualizing things I have left off all of the physical constants out front.)restart:with(plots):p1:=contourplot(Re(-ln(x+I*y)),x=-5..5,y=-5..5,grid=[30,30],contours=30,coloring=[cyan,blue]):p2:=contourplot(Im(-ln(x+I*y)),x=-5..5,y=-5..5,grid=[30,30],contours=30,coloring=[red,red]):plots[display]([p1,p2],scaling=constrained);This looks quite nice except for the mess in the electric field along the negative x-axis. This is the infamous branch cut of the log function which plots as a cliff. If you can just ignore this lousy feature, the plots look nice. (Another way to visualize the electric field without this annoying cliff is to use Maple's fieldplot command, discussed in Chapter 2. A quick way to find it in this book is to click Edit on the toolbar, click Find, then search on fieldplot.)Problem 4.14Make contour plots just like the one above, but for (a) two line charges of equal density, one at NiMvJSJ6RyUiaUc= and the other at NiMvJSJ6RywkJSJpRyEiIg== , (b) two line charges with equal density magnitudes but opposite sign located as in part (a), and (c) put a line charge of strength 2 at NiMvJSJ6RywkJSJpRyEiIg== and one of strength 1 at NiMvJSJ6RyUiaUc= . In this part you will need a finer grid and more contours to see what's going on. See if you can identify a place where the electric field is zero.---------------------------------------------------------------------------------------------------It is also possible to use complex functions to study the behavior of potential and voltage near conducting corners. Consider the following contour plot of the function NiMqJiUiaUciIiIqJCUiekciIiNGJQ== .restart:with(plots):p1:=contourplot(Re(I*(x+I*y)^2),x=0..5,y=0..5,grid=[30,30],contours=40,coloring=[cyan,blue]):p2:=contourplot(Im(I*(x+I*y)^2),x=0..5,y=0..5,grid=[30,30],contours=40,coloring=[red,red]):plots[display]([p1,p2],scaling=constrained);Recalling that the potential is given by the real part and the field lines by the imaginary part we haveNiMvKiYlImlHIiIiKiQlInpHIiIjRiYsJiomJSJ4R0YmJSJ5R0YmISIiKiZGJUYmLCYqJEYsRilGJiokRi1GKUYuRiZGJg==and in the plot the blue contours are equipotentials and the red lines are field lines. With NiMvJSJWRywkKiYlInhHIiIiJSJ5R0YoISIi both the x-axis and the y-axis are grounded, so you are looking at the way electric fields behave in a grounded right-angle corner. You can see the red field lines far apart from each other in the corner, indicating that the electric field is zero there. And how does the electric field behave as we approach the corner? Remember from electricity and magnetism that NiMvJiUiRUc2IyUieEcsJC0lJWRpZmZHNiQlIlZHRichIiI= and NiMvJiUiRUc2IyUieUcsJC0lJWRpZmZHNiQlIlZHRichIiI= , so NiMmJSJFRzYjJSJ4Rw== is proportional to y and NiMmJSJFRzYjJSJ5Rw== is proportional to x, so as we approach the corner where x=0 and y=0, both fields go linearly to zero.We can also find a function that represents the way fields behave in the neighborhood of a convex corner instead of a concave one by using the function NiMqJiklImVHLCQqKCUiaUciIiIlI1BpR0YpIiInISIiRixGKSklInpHKiYiIiNGKSIiJEYsRik= .restart:with(plots):p1:=contourplot(Re(exp(-I*Pi/6)*(x+I*y)^(2/3)),x=-5..5,y=-5..5,grid=[30,30],contours=40,coloring=[blue,blue]):p2:=contourplot(Im(exp(-I*Pi/6)*(x+I*y)^(2/3)),x=-5..5,y=-5..5,grid=[30,30],contours=40,coloring=[red,red]):plots[display]([p1,p2],scaling=constrained);To see how this is the field of a corner, ignore the third quadrant and just focus on quadrants 1, 2, and 4. The blue lines are equipotentials and they get pulled tightly around the corner, and the red field lines radiate out from the corner. In cylindrical coordinates this potential is proportional to NiMpJSJyRyomIiIjIiIiIiIkISIi so the electric field, which is the negative derivative of the potential, is proportional to NiMqJiIiIkYkKSUickcqJkYkRiQiIiQhIiJGKQ== , which goes to infinity at the corner.You may be asking yourself where these weird formulas are coming from. They are called conformal mappings and you will study them in a course on complex analysis. It's something fun to look forward to. Problem 4.15Now I'll let you do a very sharp needle-like corner. The function to use is NiMtJSVzcXJ0RzYjJSJ6Rw== . Your job is to make a picture of potential and E-lines. This time the branch cut will be your friend, because it will be right where the needle is. By thinking about how this potential varies with NiMlInJH in cylindrical coordinates and realizing that the electric field goes like the r-derivative, find out how the electric field blows up as you approach the tip.Go to top of sectionGo to top of chapter<Text-field bookmark="Linear algebra (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 5: Linear algebra</Text-field>Linear algebra in physics is the art of using matrices and vectors to solve physical problems. Maple knows a lot about linear algebra and you can explore what it knows by typing ?LinearAlgebra. The sections below just give a brief introduction, but before you start doing any of this stuff you have to tell Maple you want it to use linear algebra, like this:with(LinearAlgebra):<Text-field layout="_pstyle6" style="_pstyle6">Matrices, vectors, and basic operations</Text-field><Text-field bookmark="Defining matrices and vectors (top)" layout="_pstyle10" style="_pstyle10">Defining matrices and vectors</Text-field>DebuggingThe first thing you need to know how to do is to make matrices and vectors. There are multiple ways to do this in Maple, but I suggest you do it in the following way because it is close to the way it is done in Matlab, which is another computer language you are likely to encounter. (It is actually like the HP-48 syntax.) To build a 2x2 matrix A containing 1,2,3,4 you would useA:=Matrix([[1,2],[3,4]]);To refer to the elements of this matrix use the notation A[row,column], i.e. A[1,2] like this:A[1,2];And if you want to just define a 2x2 matrix B but not load values yet you would useB:=Matrix(1..2,1..2);Once B is defined you can load its elements any way you want, including by hand, like thisB[1,1]:=2;B[1,2]:=3;B[2,1]:=7;B[2,2]:=4;You might want to look at B to check that it is right, and try thisB;For more details about the Matrix command use ?Matrix.You can also make column and row vectors using the Vector command, like this:The default is to make a column vectorb:=Vector([5,6]);To make a row vector you have to specifically tell Maple, like thisb:=Vector[row]([5,6]);And if you want to fill vectors with numbers from the rows or columns of a matrix you can use Maple's Column and Row commands. For example, to load c with the second column of the matrix A above usec:=Column(A,2);To load c with the first row of A usec:=Row(A,1);There is also a handy short syntax for defining matrices and column vectors. Column vectors can be defined without a special command using the <...> syntax:s:=<1,2,3>;And since a matrix can be thought of as a collection of column vectors, matrices can be defined similarlyR:=<<1,2,3>|<4,5,6>|<7,8,10>>;This short form is sometimes used in the examples in online help so I thought you should know about it.Another one of Maple's ways of entering matrices is so handy that it should be mentioned here. Start by placing the cursor in an empty execution group (use the one below). Then click View on the toolbar, select Palettes, and then Matrix Palette. You will now be looking at a template for selecting various sizes of matrices. Click on the size you want (3x3, for example) and a modified version of the short-form Maple command for a matrix will appear in the execution group below, just waiting for you to enter matrix elements in place of the %? entries, and then to assign it a name with :=.If this works right you should get a Maple command that looks like this:<<%? | %? | %?> , <%? | %? | %?> , <%? | %? | %?>>;Since this is Maple, you don't have to just work with numbers. Your matrices and vectors can also be formulas, like thisd:=Matrix([[x11,x12],[x21,x22]]);ore:=Matrix([[x^2*y,y*x],[sin(x),1/x]]);Now suppose you want to give x and y values and then see what the matrices are in floating point formx:=1;y:=2;e;Well, we've been here before and we know what to do--just use evalf:evalf(e);Hmmm--apparently not. The problem is that e is not an expression but a matrix of expressions, so Maple needs to use two eval commands: evalm on the inside to refer directly to the elements of e and evalf on the outside to force floating point evaluation.evalf(evalm(e));Use ?evalm to see what this command is about, or just remember to use decimal points on your numbers when you want a numerical answer to come out.Go to top of section<Text-field bookmark="Add, subtract, and multiply (top)" layout="_pstyle10" style="_pstyle10">Add, subtract, and multiply</Text-field>Debuggingrestart:with(LinearAlgebra):As usual, there are multiple ways of doing these basic operations in Maple, but I am going to show you only one. To find the others use ?LinearAlgebra To add two 3x3 matrices B and C use the Add command.B:=Matrix([[1,2,3],[4,5,6],[7,8,9]]);C:=Matrix([[3,2,1],[5,6,4],[9,7,8]]);E:=Add(B,C);Subtraction is just adding with a minus sign E:=Add(B,-C);You do have to be careful that addition and subtraction make sense. For instance, you can't do thisF:=Matrix([[5,7],[1,3]]);Add(E,F);because the matrices are not the same size.Multiplication of matrices and vectors can be done with the Multiply command:G:=Multiply(B,C);There is a wordier way to do matrix multiplication which you can find in the command list by going to ?LinearAlgebra.Problem 5.1Verify that Maple did this right by computing NiMmJSJHRzYjIiNB by hand.--------------------------------------------------------------------------------------------------You can also multiply matrices and vectors together, like thisb:=<5,6,7>;Multiply(B,b);As expected, a square matrix times a column vector is a column vector. A row vector times a square matrix would be a new row vector, and Maple knows how to do this too:c:=Vector[row]([1,2,3]);(Or you could use the shorthand form)c:=<1|2|3>;Multiply(c,C);You can also multiply matrices and vectors by scalars using the ordinary multiplication operator 3*b;5*B;Finally, you will notice that division is not mentioned here. That's because division with matrices and vectors is rather tricky and actually falls under the heading of "Solving systems of linear equations", which comes a little later.Problem 5.2An important application of matrix multiplication is the rotation of vectors in three-dimensional space. With a carefully drawn picture and some trigonometry you can show that if a vector v is rotated by angle NiMlJnRoZXRhRw== about the x-axis in the counterclockwise direction when looking from positive x toward the origin, then the new vector is simply given by the matrix Rx multiplied by v, where Rx is given byRx:=Matrix([[1,0,0],[0,cos(theta),-sin(theta)],[0,sin(theta),cos(theta)]]);Similarly, the rotation matrices about the y- and z-axes through angles NiMlJHBoaUc= and NiMlJHBzaUc= are given byRy:=Matrix([[cos(phi),0,sin(phi)],[0,1,0],[-sin(phi),0,cos(phi)]]);Rz:=Matrix([[cos(psi),-sin(psi),0],[sin(psi),cos(psi),0],[0,0,1]]);(Note: there is not a sign mistake on the sines in the Ry matrix. The sine signs are different in this matrix than they are in Rx and Rz because rotation is always defined with respect to the right-hand rule on angle: put your thumb in the direction of the rotation axis and your fingers curl in the direction of positive angle. Try it with your hand with NiMvJSRwaGlHKiYlI3BpRyIiIiIiIyEiIg== and check that Ry is correct.) Use these rotation matrices to check where the vector [1,0,0] ends up after the following sequence of rotations: (a) by NiMqJiUjcGlHIiIiIiIjISIi about the y-axis, then (b) by NiMqJiUjcGlHIiIiIiIlISIi about the x-axis, and finally (c) by NiMqJiUjcGlHIiIiIiIjISIi about the z-axis. After Maple gives you the answer verify that it is correct by making a coordinate system with your fingers and doing the rotations. (Make sure the coordinate system is right-handed). Then start with the same vector [1,0,0] but do the rotations in the reverse order. Do you end up in the same place? (You don't--we describe this situation by saying that rotation operations don't commute.) Rotation should not change the magnitude of the vector; does this sequence of matrix multiplications preserve the magnitude of the vector? You can get the magnitude of a vector v with the command Norm(v,2).Go to top of section<Text-field bookmark="Inverse, determinant, etc. (top)" layout="_pstyle10" style="_pstyle10">Inverse, determinant, norm, etc.</Text-field>DebuggingThere are many other operations you can perform on matrices, and Maple knows how to do a lot of them. To see what's available type ?LinearAlgebra and browse through the topics. Here are a few of the common ones encountered in physics.Define some matrices to play withrestart:with(LinearAlgebra):B:=Matrix([[1,2,3],[4,5,6],[7,8,9]]);C:=Matrix([[3,2,1],[5,6,4],[9,7,8]]);MatrixInverse: To get the inverse of a matrix, say C, just do thisMatrixInverse(C);To check it do thisMultiply(C , MatrixInverse(C));Determinant: Get the determinant of a matrix this wayDeterminant(B);Determinant(C);Transpose: the transpose of a matrix is obtained by switching rows for columns; think about reflecting the matrix across the main diagonal. It also makes sense to take the transpose of a non-square matrix.Transpose(C);E:=Matrix([[1,2,3]]);Transpose(E);And in quantum mechanics you will want to take the transpose of the complex conjugate, which is called the HermitianTranspose:F:=<<1,I>|<2*I,2>>;HermitianTranspose(F);Trace: The trace of a square matrix is the sum of the diagonal elements.Trace(C);Norm: The norm of a vector has many definitions. You are used to squaring the elements, adding them together, then taking the square root. We use this definition almost exclusively in physics, but Maple is smarter than this, taking the kth root of the sum of the kth powers of the elements. To use our standard k=2 in this definition you would use Norm(E,2);For matrices the norm is more complicated; look under ?LinearAlgebra[Norm].Problem 5.3Find the inverse of the matrix B defined in this section. Explain why you get an error message instead of an answer.Go to top of section<Text-field bookmark="Solving systems of linear equations (top)" layout="_pstyle6" style="_pstyle6"> Solving systems of linear equations</Text-field>DebuggingMaple knows how to do problems like this:There are three friends, Alice, Bob, and Chuck. The sum of Alice's and Bob's ages are 1.5 times Chuck's age. Chuck's age minus Bob's age is 6. Alice's age added to Chuck's age is 2.25 as large as Bob's age. If Bob used to date Alice, but is now far away in a foreign country, and if Chuck thinks Alice is really cute, is Bob in big trouble? The mathematical part of this problem is just a problem in linear algebra of the form A*x = b, with the ages in the order [Alice, Bob, Chuck]. Here are A and b:restart;with(LinearAlgebra):A:=Matrix([[1,1,-3/2],[0,-1,1],[1,-2-1/4,1]]);b:=Vector([0,6,0]);We would like to solve for the vector x of the friends' ages. Maple has a command LinearSolve that makes this kind of problem really easy:LinearSolve(A,b);And that's all there is to it. Any linear system can be solved this way. We will learn later that Maple's equation solving command solve can also do problems like this.Problem 5.4Consider 5 springs with spring constants NicmJSJrRzYjIiIiJkYkNiMiIiMmRiQ2IyIiJCZGJDYjIiIlJkYkNiMiIiY= hooked together along the x-axis in this order. If each spring has known relaxed length NicmJSJsRzYjIiIiJkYkNiMiIiMmRiQ2IyIiJCZGJDYjIiIlJkYkNiMiIiY= , find the unknown lengths of each spring NicmJSJ4RzYjIiIiJkYkNiMiIiMmRiQ2IyIiJCZGJDYjIiIlJkYkNiMiIiY= when the springs are stretched until the sum of their lengths is twice their total unstretched length. Have Maple give you the general algebraic solution to this problem (it is moderately horrible), then get a numerical answer using NicvJiUia0c2IyIiIi0lJkZsb2F0RzYkIiImISIiLyZGJTYjIiIjRicvJkYlNiMiIiRGMC8mRiU2IyIiJUY0LyZGJTYjRistRik2JCIjTkYs . Let all the relaxed lengths be the same and equal to 10 cm. Recall that the force exerted by a spring is given by the formula NiMvJSJGRywkKiYlImtHIiIiLCYlInhHRiglImxHISIiRihGLA== . You will also need to remember how to do equilibrium problems from freshman mechanics.Go to top of section<Text-field bookmark="Dot and cross (top)" layout="_pstyle6" style="_pstyle6">Vectors: dot and cross products</Text-field>DebuggingMaple knows how to do dot products, cross products, and how to find the angle between two vectors with the commands DotProduct, CrossProduct, and VectorAngle.restart:with(LinearAlgebra):v1:=<1|2|3>;v2:=<4|5|6>;DotProduct(v1,v2);CrossProduct(v1,v2);That's all there is to it. Oh, and to get the angle between them useVectorAngle(v1,v2);or, rather,evalf(VectorAngle(v1,v2));Note that it comes out in radians.Go to top of section<Text-field bookmark="Eigenvalues (top)" layout="_pstyle6" style="_pstyle6">Eigenvalues and eigenvectors</Text-field>DebuggingOne of the most important ideas from linear algebra as applied to physics are eigenvalues and eigenvectors. They show up in classical mechanics, math physics, quantum mechanics, numerical analysis, and other places. So heads up here, this is important.The eigenvalue problem as applied to matrices is this: given a square matrix A, what are the vectors NiMmJSJ4RzYjJSJpRw== and the numbers NiMmJSdsYW1iZGFHNiMlImlH such that when A is multiplied into NiMmJSJ4RzYjJSJpRw== the result is the same vector NiMmJSJ4RzYjJSJpRw== , but multiplied by NiMmJSdsYW1iZGFHNiMlImlH ? Or in other words, are there NiMmJSJ4RzYjJSJpRw== and NiMmJSdsYW1iZGFHNiMlImlH such that ANiMvJiUieEc2IyUiaUcqJiYlJ2xhbWJkYUdGJiIiIkYkRis= ? Since matrix multiplication by a vector simultaneously rotates the vector and multiplies it by a factor, it is not clear that there is any solution at all to this problem. But it can be proven mathematically that in most cases, if the matrix is NxN, then there are N such vectors and values (called eigenvectors and eigenvalues). The eigenvalues and eigenvectors are often complex, which might seem to mean that they wouldn't have physical meaning, but even when complex numbers show up physical meaning can often be obtained from them. But when the eigenvalues turn out to be real, then the eigenvectors have a very special property--when NiMmJSJ4RzYjJSJpRw== is multiplied by A the result is a vector that is either parallel to (if NiMmJSdsYW1iZGFHNiMlImlH is positive) or opposite to (if NiMmJSdsYW1iZGFHNiMlImlH is negative) the eigenvector NiMmJSJ4RzYjJSJpRw== .Here is a simple example that illustrates these ideas.restart:with(LinearAlgebra):A:=Matrix([[1,2,3],[4,3,2],[-1,0,2]]);Eigenvectors(A);Ok, it's clear we've got to do something about this. We usually just want numbers, not gigantic algebraic expressions. An easy way to get them (for the 142nd time) is to enter the elements of the matrix as floating-point numbers, i.e., they have to have decimal points, like thisA:=Matrix([[1.,2.,3.],[4.,3.,2.],[-1.,0.,2.]]);v:=Eigenvectors(A);This is much better. Now let's look at the output. According to online help for Eigenvectors the first set of numbers is a column vector containing the eigenvalues, and the second set of numbers is a matrix whose columns are the eigenvectors. So if we wanted to study the third eigenvector we would start by picking off the third eigenvalue like thislambda3:=v[1][3];(I know this looks weird, but since v[1] is a column vector it makes sense to ask for its third element with [3]). Now we want the third column of v[2], a job tailor made for Maple's Column commandv3:=Column(v[2],3);Now we are ready to see if this really is an eigenvector by multiplying NiMmJSJ2RzYjIiIk by A. If it works, then ANiMmJSJ2RzYjIiIk will just give us NiMqJiYlJ2xhbWJkYUc2IyIiJCIiIiYlInZHRiZGKA== back.y:=Multiply(A ,v3);To see if it got it right let's divide y by NiMmJSdsYW1iZGFHNiMiIiQ= and see if we are looking at the eigenvector NiMmJSJ2RzYjIiIky/lambda3;If you compare this vector with NiMmJSJ2RzYjIiIk in the matrix produced by Eigenvector (see above) you will see that it is the same, to the precision of Maple floating point numbers with Digits set to its default value of 10.Problem 5.5Here's a simple eigen-idea that shows up in numerical analysis all the time. Think about what happens if you pick a vector and just keep multiplying it by A in the example above all the time. Your original vector could be written as a linear combination of the eigenvectors (usually), so you can think about what multiplication by A does to each of the three eigenvector components. Now look, this is not too hard--all that happens is that eventually, the vector with the largest eigenvalue will completely take over because every time you multiply by A you get more of it back than you get of the other two. In the example above the biggest eigenvalue is about twice its nearest competitor, and you already know what repeatedly multiplying by 2 can do. So now do this: choose a random vector; then multiply it by A and divide it by its norm using Norm(v,2) so that the result is a unit vector; then do this multiplication and renormalization about 20 times. Now find the angle between your final result and the eigenvector with the largest eigenvalue; did your calculation get this eigenvector? Can you explain the angle you get? ---------------------------------------------------------------------------------------------------Problem 5.6Go get the rotation matrix Rx from Problem 5.2 and have Maple find its eigenvalues and eigenvectors. Then think about what rotation means and see if you can make physical sense out of Maple's answers. Maple will require you to choose a value for theta, so try (a) NiMvJSZ0aGV0YUctJSZGbG9hdEc2JCIjOCEiIg== , (b) NiMvJSZ0aGV0YUclI1BpRw== , and (c) NiMvJSZ0aGV0YUcqJiUjUGlHIiIiIiIjISIi . (Note: you will encounter (c) when you study spin in quantum mechanics.) A good way to do this problem is to define a Maple function NiMtJSJNRzYjJSZ0aGV0YUc= that defines the matrix Rx.M:=theta->Matrix([[1,0,0],[0,cos(theta),-sin(theta)],[0,sin(theta),cos(theta)]]);and then use this function to define the three matrices in parts (a)-(c).Problem 5.7Just as 3-vectors can be rotated using rotation matrices, 3x3 matrices can also be rotated. The operation that rotates a vector v is R*v, and the operation that rotates a matrix M is inv(R)*M*R. , where inv(R) means the inverse of the matrix R. You will encounter this idea in some of your more advanced mathematics and physics courses, but here you will just work with it briefly. (a) Create the diagonal matrix NiM+JSNNMUctJSdSVEFCTEVHNiUiKVshUWMjLSUnTUFUUklYRzYjNyU3JSIiJSIiIUYvNyVGLyIiIkYvNyVGL0YvIiIjJSdNYXRyaXhH and transform it to a rotated coordinate system using the orthonormal rotation matrix NiM+JSJSRy0lJ1JUQUJMRUc2JSInd2ohKS0lJ01BVFJJWEc2IzclNyUsJCooIiIiRjAiIiMhIiIpRjEqJkYwRjBGMUYyRjBGMiooRjBGMCIiJ0YyKUY2RjRGMCooRjBGMCIiJEYyKUY5RjRGMDclRi9GNUY4NyUiIiEsJCooRjBGMEY5RjJGN0YwRjJGOCUnTWF0cml4Rw==. Call the new matrix M2. (b)Calculate the eigenvalues and eigenvectors of both M1 and M2. How do they compare? (c) Multiply by the vector NiM+JSJhRy0lJ1JUQUJMRUc2JSIpRzFTQy0lJ01BVFJJWEc2IzclNyMlInhHNyMlInlHNyMlInpHJiUnVmVjdG9yRzYjJSdjb2x1bW5H on both sides of M1 using the rule transpose(a)*M1*a and then set the result equation to 4 to create the quadratic equation NiMvLCgqJiIiJSIiIiokJSJ4RyIiI0YnRicqJCUieUdGKkYnKiZGKkYnKiQlInpHRipGJ0YnRiY=, and use implicitplot3d to visualize it. Use the axes=boxed plot option. The forms are identical except for their orientations. The eigenvalues of M1 are related to the geometric width of the correpsonding ellipsoid and are unaffected by rotation. Visually demonstrate this by doing the same thing with M2.Go to top of section<Text-field bookmark="Vector calculus (top)" layout="_pstyle6" style="_pstyle6"> Vector calculus: grad, div, and curl</Text-field>DebuggingMaple's ability to do algebra means it can do vector derivatives too using the commands Gradient, Divergence, Curl, and Laplacian. And it can do it using Cartesian, cylindrical, and spherical coordinates, but you have to invoke the special vector calculus package VectorCalculus to use these commands and the coordinate system must be set with the SetCoordinates command.restart:with(VectorCalculus):Here are some gradient examples in each coordinate system.Cartesian: first set the coordinate system, then define the function and take its gradientSetCoordinates('cartesian'[x,y,z]);f1:=3*x^2+y*sqrt(z);Gradient(f1);Cylindrical:SetCoordinates('cylindrical'[r,theta,z]);f2:=cos(theta)/sqrt(r^2+z^2);Gradient(f2);Spherical:SetCoordinates('spherical'[r,theta,phi]);f3:=sin(phi)*r^2*(3*cos(theta)^2-1);Gradient(f3);Maple can do the divergence in all three coordinate systems too. The divergence acts on a vector field, so the VectorField command must first be used to define the vector field in whatever coordinate system you are in. Here are examples in each coordinate system.Cartesian:SetCoordinates('cartesian'[x,y,z]);g1:=VectorField(<x^2,y^2,z^2>);Divergence(g1);Cylindrical:SetCoordinates('cylindrical'[r,theta,z]);g2:=VectorField(<r^2*cos(theta),r^2*sin(theta),z^2>);Divergence(g2);Spherical:SetCoordinates('spherical'[r,theta,phi]);g3:=VectorField(<r^2*cos(theta),r^2*sin(theta),cos(phi)>);Divergence(g3,[r,theta,phi],coords=spherical);And Maple can do the curl, like this, using the same vector fields used for the divergence.Cartesian:SetCoordinates('cartesian'[x,y,z]);Curl(g1);Cylindrical:SetCoordinates('cylindrical'[r,theta,z]);Curl(g2);Spherical:SetCoordinates('spherical'[r,theta,phi]);Curl(g3);And finally, it also knows how to do del-squared, the Laplacian, in each coordinate system. Here it is for each of the scalar functions used with the gradient.Cartesian:SetCoordinates('cartesian'[x,y,z]);Laplacian(f1);Cylindrical:SetCoordinates('cylindrical'[r,theta,z]);Laplacian(f2);Spherical:SetCoordinates('spherical'[r,theta,phi]);Laplacian(f3);?LaplacianThis capability might be nice, but usually in physics the problem is not calculating these vector derivatives, but in undoing them to find a field. This is much harder and Maple is not much help in this regard.Problem 5.8Two of Maxwell's equations for static electric and magnetic fields are NiMvLSUkZGl2RzYjJSJFRyomJSRyaG9HIiIiJiUoZXBzaWxvbkc2IyIiISEiIg== and NiMvLSUlY3VybEc2IyUiQkcqJiYlI211RzYjIiIhIiIiJSJKR0Yt . For each of the following E or B fields use Maple's vector calculus routines to find formulas for the charge density NiMlJHJob0c= and the current density NiMlIkpH . Note: NiMlIkVH and NiMlIkJH are vectors, so you need to define them properly to do this problem. For instance, if NiMvJiUiQkc2IyUmdGhldGFHKiYlImtHIiIiJSJyR0Yq then you need to define NiMlIkJH this way: B:=array([0,k*r,0]);(a) Spherical coordinates: NiMvJiUiRUc2IyUickcqJiUia0ciIiIqJEYnIiIjISIi (point charge) (b) Spherical coordinates: NiMvJiUiRUc2IyUickcqJiUia0ciIiJGJ0Yq (solid sphere of charge)(c) Cylindrical coordinates: NiMvJiUiRUc2IyUickcqJiUnbGFtYmRhRyIiIioqIiIjRiolI1BpR0YqJiUoZXBzaWxvbkc2IyIiIUYqRidGKiEiIg== (line charge) (d) Cylindrical coordinates: NiMvJiUiRUc2IyUickcqJiUia0ciIiJGJ0Yq (solid cylinder of charge)(e) Cylindrical coordinates: NiMvJiUiQkc2IyUmdGhldGFHKiYlImtHIiIiJSJyRyEiIg== (long wire) (f) Cylindrical coordinates: NiMvJiUiQkc2IyUmdGhldGFHKiYlImtHIiIiJSJyR0Yq (uniform current in a wire)(g) Cylindrical coordinates: NiMvJiUiQkc2IyUiekctJSJrRzYjLCYqJCUiYUciIiMiIiIqJCUickdGLiEiIg==-----------------------------------------------------------------------------------------------------Problem 5.9The electrostatic potential of a point dipole is given in spherical coordinates byNiMvLSUiVkc2JSUickclJnRoZXRhRyUkcGhpRyooJSJwRyIiIi0lJGNvc0c2I0YoRiwqKiIiJUYsJSNQaUdGLCYlKGVwc2lsb25HNiMiIiFGLEYnIiIjISIi . Find the electric field of this dipole in spherical coordinates by using the defining relation for the potential NiMvJSJFRywkLSUlZ3JhZEc2IyUiVkchIiI= . What is the power law for the way E falls off with distance from the origin?Go to top of sectionGo to top of chapter<Text-field bookmark="Solving equations (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 6: Solving equations</Text-field>In the linear algebra chapter you saw how to solve systems of linear equations. These are relatively easy, but Maple can handle much harder non-linear equations as well. In this chapter we will learn how to find the roots of polynomials, solve impossible equations involving both elementary and special functions, and even handle sets of impossible equations.<Text-field bookmark="Equations in a single variable (top)" layout="_pstyle6" style="_pstyle6">Equations in a single variable</Text-field>DebuggingMaple makes short work of hard equations in a single variable. The commands that do the job are solve and fsolve, corresponding as usual to symbolic and real number answers. For instance, Maple knows the quadratic formularestart;s1:=solve(a*x^2+b*x+c=0,x);Notice that the syntax of solve is solve(equation,variable). Both of the answers are given, separated by commas. And if you give it numerical coefficients, it will try to give you numerical answerss2:=solve(x^2-8*x+14=0,x);Maple even knows the formula for the cubic equations3:=solve(a*x^3+b*x^2+c*x+d=0,x);but it is so ugly that it is almost never used. Instead we give numerical coefficients and expect a numerical answers4:=solve(x^3+3*x^2-2*x+7=0,x);Well, these are numbers correct, but because Maple was thinking symbolically, they don't look very useful. To get actual numbers you can either use our old friend evalfevalf(s4);or enter the coefficients in the equation with decimal points.s4:=solve(x^3+3.*x^2-2.*x+7.=0,x);The solve command with polynomials is smart: it knows the fundamental theorem of algebra, which is that an NiMpJSJuRyUjdGhH order polynomial has NiMlIm5H roots. For instance if you ask it for the roots of x^6+1 this ways5:=evalf(solve(x^6+1=0,x));it will give you all 6. Let's try another ones6:=solve(x^6+3*x^5+2=0,x);You will be seeing RootOf a lot as you solve equations in Maple. The problem is that you gave Maple a polynomial with integer coefficients, which tells Maple to try to solve the equation with radicals (square roots, cube roots, etc.). And in this case it couldn't do it, except for the root -1. But if you just want numbers, either use evalf, or change the coefficients to floating point numbers by adding decimal points and you will get all 6. evalf(s6);solve(x^6+3.*x^5+2.=0,x);Maple can also handle equations involving harder functions, like this one: NiMvLCYtJSRjb3NHNiMlInhHIiIiKiZGKEYpIiM1ISIiRiwiIiE= .s7:=solve(cos(x)-x/10=0,x);RootOf again, and the solution is the same: change the 10 to 10., or use evalf(s7), to find at least one of the solutions.evalf(s7);But when you solve hard equations like this you need to be careful, because there may be more than one answer and Maple will not give you all of them. Let's try plotting the function NiMsJi0lJGNvc0c2IyUieEciIiIqJkYnRigiIzUhIiJGKw== and see how many zero-crossings it has to see how many answers we should have found.plot(cos(x)-x/10,x=-15..15);So Maple didn't actually lie; it just didn't volunteer information. 1.427551779 is a solution, but there are others as well. This is important: whenever possible, make a plot first so you know how many solutions you are looking for.Well, how do we get Maple to give us all of the roots? Since we are only going to find numerical roots anyway we might as well use a numerical solver, which is fsolve in Maple. When using fsolve you don't just give it an equation and a variable, but rather an equation and a variable which is set equal either to a search range or to a single initial guess for the solution. For instance, in the problem at hand the plot tells us that there are roots near -9.6, -9.2, -4, -2, 1.5, 5, and 7. You must instruct fsolve to look near each of these to get them allfsolve(cos(x)-x/10=0.,x,-10..-9.5);fsolve(cos(x)-x/10=0.,x,-9.5..-8.8);etc. Notice what happens if you accidentally specify a range in which there is no solution:fsolve(cos(x)-x/10=0.,x,-8.5..-8);In general, when Maple just gives back what you gave it, it means either it couldn't find the answer, or you loused up. It's your job to figure out which it is.Notice also that you can just give it a single guess at where the solution is instead of a rangefsolve(cos(x)-x/10=0.,x=1.5);But be careful here. If you give fsolve an initial guess that is close to a maximum of the function whose zeros you are looking for fsolve might get lost, or at least go find a solution that is nowhere your initial guess. When you study the secant method in Chapter 8 you will see why this happens.fsolve(cos(x)-x/10=0.,x=0);Yet another way of controlling which solution Maple gives you is the avoid option in fsolve. Suppose you are looking for solutions of the equation NiMvLCYtJSRjb3NHNiMlInhHIiIiKiZGKEYpIiIkISIiRikiIiE= . If you plot this function to see where the zeros are, you will see two closely spaced solutions just below 3. This command will find one of them:s1:=fsolve(cos(x)+x/3=0,x=3);but maybe you wanted the next one down and it is hard to tell from the graph what initial guess or range to use to get it. Well, you can tell Maple to find another one near 3, but not to find s1 again, like thiss2:=fsolve(cos(x)+x/3=0,x=.09,avoid={x=s1});Problem 6.1Find all of the roots, real and complex, of the following polynomials. Use both solve and fsolve on them. You will notice that solve will give you complex values, but fsolve won't. You can fix this by telling fsolve that you want complex solutions, like this:fsolve(x^2+1=0,x,complex). Also see what happens when you use the command factor(f,complex), where f is the polynomial you want to factor.(a) NiMsJiokJSJ4RyIiJSIiIkYnISIi (b) NiMsKiokJSJ4RyIiJCIiIiokRiUiIiNGJ0YlRidGJ0Yn----------------------------------------------------------------------------Problem 6.2(a) Find all of the solutions between -5 and 20 of the equation NiMvLSUkZXhwRzYjJSJ4RyomIiM1IiIiLSUkc2luR0YmRio= .(b) Find all of the solutions of the equation NiMvLSUkZXhwRzYjLCQlInhHISIiRig= . Use both solve and fsolve and compare their answers----------------------------------------------------------------------------Problem 6.3Find all of the roots of the function NiMvLSUiZkc2IyUieEcsJiomLSUkY29zRzYjLCYiIiJGLiokRiciIiNGLkYuLCZGLkYuRidGLiEiIkYuKiYiIyoqRi4sJkYuRi4qJiIkNiJGLkYnRi5GLkYyRi4= for NiMlInhH between 0 and 10.---------------------------------------------------------------------------Problem 6.4Find all of the zeros of the Bessel function derivative NiMtSSVkaWZmR0kqcHJvdGVjdGVkR0YlNiQmSSJKRzYiNiMiIiNJInhHRik= between 0 and 100 and load them into a column vector NiMmSSJhRzYiNiNJIm5HRiU= .You can do this problem very compactly by using the seq command with fsolve inside it. Since this problem is a bit difficult, let's do it in small steps.(i) First plot the function between 0 and 100, then refine the plot range a couple of times so that you know about where the first and second zeros are, and about how far apart they are. (You should find that they are separated by about NiNJI3BpRzYi .(ii) Use the seq command to use the information you found in (i) to generate all of these zeros. Recall that the seq command generates a list of numbers, like this: seq(n^2,n=0..20); then note that the first argument of seq can be anything that generates a number that depends on NiNJIm5HNiI=, even the result of an fsolve. Here, for example, is a way to use seq and fsolve to build a sequence of zeros of the cosine function using guesses that start at 1.4 and are separated by NiNJI3BpRzYi : seq(fsolve(cos(x)=0,x=1.4+n*Pi),n=0..20); (iii) All you have to do now is to load these numbers into a column vector. Go back to Chapter 5 to see how this is done, then figure out how to put the first zero at NiMvSSJ4RzYiIiIh in by hand.Go to top of section<Text-field bookmark="Systems of equations (top)" layout="_pstyle6" style="_pstyle6">Systems of equations</Text-field>DebuggingMaple can also handle systems of both linear and nonlinear equations, but this is a much trickier business because it is harder to plot the equations to understand what is going on, and because there is so much more space in which to get lost in multiple dimensions. The commands that handle these systems are solve and fsolve again, but this time you give them sets (stuff in curly brackets) of equations and variables. As a first example, let's have solve do a simple linear algebra problem like the ones in Chapter 5. John is twice as old as Kimberly. Kimberly's age added to John's age is 27. Find their ages. Using the LinearAlgebra package we would set this up as a matrix, but solve (and fsolve) can work with the equations directly, like this:restart;E1:=J=2*K;E2:=K+J=27;solve({E1,E2},{J,K});fsolve({E1,E2},{J,K});Because you don't have to worry about the conversion to matrix form, this is probably the method of choice for solving systems of linear equations.But solve and fsolve can also solve nonlinear systems, i.e., system of equations in which the variables are squared, cubed, sit inside sines, cosines, exponentials, etc. For example, here is a set of two nonlinear equations to solverestart;E1:=x^2-y=5;E2:=x-y^2=-13; Let's try the solve command firsts:=solve({E1,E2},{x,y});Maple was smart; it used equation E1 to eliminate y from equation E2 to get a single equation for x. Then it factored this quartic equation to pull out the answer (x,y)=(3,4) and reduced the rest of the problem to a cubic. If we let evalf finish the problem it gives us thisevalf(s);But if you plot the cubic in RootOf above, whose roots are supposed to give the values of x that satisfy the equation, you will see that there are supposed to be two more solutions; where are they? You could try fsolve, and you would get thiss:=fsolve({E1,E2},{x,y});which is even worse since it only gives us one root. You could look for the roots one at a time by giving fsolve initial guesses like this:s:=fsolve({E1,E2},{x=2.9,y=4.1});But there is a way to get Maple to give you all 4 roots. Just repeat the first thing we tried, but with all of the integers replaced with floating point numbers:restart;E1:=x^2.-y=5.;E2:=x-y^2.=-13.;s:=solve({E1,E2},{x,y});There is a lesson here: be creative and try a few different ways to solve the problem and maybe one of them will work.Maple has another tool that is useful when you have two nonlinear equations in two unknowns. Just as it was helpful in one-variable problems to make a plot first so that we could see about where the solutions were, two-dimensional plots can help when you have two unknowns. The Maple command that does this is the plot command implicitplot, which takes an equation in two variables, like this one: NiMvLCYqJCUieEciIiMiIiIlInlHISIiIiIm and plots the curve it defines in the NiQlInhHJSJ5Rw== plane: ( note that you have to load the extra plotting commands first by using with(plots) )with(plots):implicitplot(x^2-y=5,x=-3..3,y=-6..3);To use this to graphically find the solutions of two equations just plot both equations on the same graph and look for the places where the two curves cross each other, like thisimplicitplot({x^2-y=5,x-y^2=-13},x=-14..4,y=-6..5,numpoints=5000); The picture makes it clear that we have two parabolas, and that they intersect each other in 4 places, so there should be 4 solutions. Note that you have to be careful to choose your plot window big enough that you can see the whole picture. For instance, here is what the picture looks like if you choose a plot window that is too small:implicitplot({x^2-y=5,x-y^2=-13},x=-3..3,y=-5..3,numpoints=5000);And if you have 3 nonlinear equations in 3 unknowns, you can do something similar by using implicitplot3d (see Maple help.)Problem 6.5Find all of the solutions (real and complex) of the set of equationsNiMvLCYqJCUieUciIiMiIiIqJCUieEdGJyEiIiwkRidGKw==NiMvLCYlInhHIiIiKiQlInlHIiIkISIiRik=Before you start solving use implicitplot to make a picture that will help you see how many solutions there are and to estimate the solution values of NiMlInhH and NiMlInlH .--------------------------------------------------------------------------Here's another nonlinear set to put Maple to the test.restart;E1:=cos(x)+y-sqrt(z)=-.191748502;E2:=x*y*z=3;E3:=x+y+2*z=8;Let's try solve firstsolve({E1,E2,E3},{x,y,z});(Maple thinks for a while, but nothing happens.) Well, that was informative. Now let's try fsolve with specified ranges for each variablefsolve({E1,E2,E3},{x,y,z},{x=-3..3,y=-3..3,z=-3..3});so it looks like (x,y,z)=(1,1,3) is pretty close to a solution. I warn you, however, that in 3 dimensions and higher Maple can just get lost and run forever unless (a) you know there is a solution and (b) you tell Maple approximately where to look.To try to get a better idea of where the solutions might lie you could try implicitplot3d, like this:with(plots):implicitplot3d({E1,E2,E3},x=-5..5,y=-5..5,z=0..5);Click on this figure and rotate it to see what it looks like. After being baffled by what it means for a while plot it again with the ranges restricted to the neighborhood of the one solution we know: NiMvNyUlInhHJSJ5RyUiekc3JSIiIkYpIiIk :implicitplot3d({E1,E2,E3},x=.5..1.5,y=.5..1.5,z=2.5..3.5,grid=[10,10,10]);In the middle of this plot there is a point where all three of the surfaces defined by E1, E2, and E3 intersect at a point. This is what you are looking for when you use implicitplot3d, but I admit that it can be pretty hard to see what's happening in three dimensions..Problem 6.6A particle finds itself in a region of space where its potential energy function is given by the formulaNiMvLSUiVUc2JSUieEclInlHJSJ6RywsKiRGJyIiIyIiIiokRigiIiVGLSokRilGLEYtKiYtJSRjb3NHNiMqJiIjN0YtRidGLUYtLSUkc2luRzYjKiZGNkYtRihGLUYtRi0tRjM2IyomRjZGLUYpRi0hIiI= . By using the fact that the force on the particle is given by NiMvJSJGRywkLSUlZ3JhZEc2IyUiVUchIiI= , find 4 points of equilibrium. (Finding just one will be pretty easy--after that you will have to use the range option in fsolve with some creativity to avoid finding the same ones over and over.) To see how to take the gradient in Maple go back to the vector calculus section in Chapter 5.Problem 6.6Suppose that you have three data points (x1,y1), (x2,y2), (x3,y3) that you know represent a smooth function NiMtJSJ5RzYjJSJ4Rw== . As an approximation to this smooth function, fit these three data points to a parabola of form NiMvLSUieUc2IyUieEcsKCUiYUciIiIqJiUiYkdGKkYnRipGKiomJSJjR0YqKiRGJyIiI0YqRio= by finding three fitting equations that can be used to solve for the unknown parabola coefficients a, b, and c . Set these three equations up and use solve to find formulas fora, b, and c, then define a Maple expression for the resulting parabola.This expression looks pretty complicated, but if we use equally spaced points it doesn't look so bad. So set NiMvJSN4MkcsJiUjeDFHIiIiJSJoR0Yn and NiMvJSN4M0csJiUjeDFHIiIiKiYiIiNGJyUiaEdGJ0Yn and simplify your parabolic expression for this case where the points are equally spaced by an amount NiMlImhH . Now that you have an approximate form for the function you can do various things with it.(a) Estimate the area under the curve between x1 and x3 by integrating the parabola formula between these two limits. The formula that results is called Simpson's rule. To see if this approximate integral is any good let x1=0, x2=0.5, and x3=1.0 and y1=cos(x1), y2=cos(x2), and y3=cos(x3), so that your approximate area should be close to NiMvLSUkaW50RzYkLSUkY29zRzYjJSJ4Ry9GKjsiIiEiIiItJSRzaW5HNiNGLg== . Does your approximate integration formula do a good job? (b) Estimate the derivative of the function NiMtJSJ5RzYjJSJ4Rw== at the middle point x2 by differentiating your parabola and evaluating it at x=x2. This formula is called the centered-difference formula for the first derivative. Check to see how accurate it is at x2=0.5 by using x1=0.4 and x3=.6 with NiMvLSUieUc2IyUieEctJSRleHBHRiY= .(c) Estimate the second derivative of the function NiMtJSJ5RzYjJSJ4Rw== at x2 by differentiating your parabola formula again. This is the centered second derivative formula for equally spaced points. Check its accuracy as you did in part (b).You will use these approximate integration and differentiation formulas in Physics 330 and 430.Go to top of sectionGo to top of chapter<Text-field bookmark="Odes (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 7: Ordinary differential equations</Text-field>Differential equations are the language of physics and Maple can help you solve them. As you work through the sections below you will learn several ways to tackle problems involving differential equations.<Text-field bookmark="First order differential equations (top)" layout="_pstyle6" style="_pstyle6">First order differential equations</Text-field>Debuggingrestart;Let's begin by asking Maple to solve the first differential equation you probably ever saw, the equation for radioactive decay. If the decay rate of the atoms in a sample is NiMlImdH (g has units of 1/second), then the equation determining the number of atoms still left in the sample is(Differential equations are built like ordinary equations in Maple, but using the diff command:)E1:=diff(N(t),t)=-g*N(t);along with the initial condition that at time NiMvJSJ0RyIiIQ== there were NiMmJSJORzYjIiIh atoms in the sample. The problem is to find the function NiMtJSJORzYjJSJ0Rw== . Maple solves it this way using the command dsolve.dsolve(E1,N(t));As expected, the solution is a dying exponential. Maple gives you an unknown constant out front because we didn't tell it what the initial conditions are yet. The constant is not too hard to find because at NiMvJSJ0RyIiIQ== the exponential function is 1, so the constant NiMlJF9DMUc= must be NiMmJSJORzYjIiIh . But dsolve will accept initial conditions as well and do even this little bit of work for you. You simply replace the first argument of dsolve with a set containing E1 and the initial condition, like this. (See ?dsolve,initial_conditions for more details)dsolve({E1,N(0)=No},N(t)); Ok, now suppose you wanted to get a plot of this solution. First you need to tell Maple what the values of NiMmJSJORzYjIiIh and NiMlImdH are like thisNo := 5;g:=3;and then you do something that seems a little odd. You have to somehow grab the expression on the right-hand side of the solution from dsolve so you can pass it into plot. One way to do this would be to start the plot command like this, plot( then stop, use the mouse to highlight the expression on the right-hand side of N(t)=... above and paste it in. But this seems awkward; surely Maple will give you access to the solution it just found? It will, and here is one way that works. Instead of just solving the differential equation to the screen, assign the solution to a variable, like thisS1:=dsolve({E1,N(0)=No},N(t));You can now refer to this solution by its name, S1, and in particular you can refer to the solution itself by rhs(S1), like thisplot(rhs(S1),t=0..3);Note that the command rhs picks off the right-hand side of an equation. You can probably guess what lhs does. Another way to plot this result is to tell Maple to invent a variable with the name N(t) which can be used as an expression in the plot command. The syntax for this is simply assign(S1); .assign(S1);and then we can useplot(N(t),t=0..3);The question naturally arises, "What exactly has become of N?" If you try to look at it this wayN;there isn't anything there. The problem is that Maple did something perfectly natural for it, but rather odd for us. It took the result for S1, which is NiMvLSUiTkc2IyUidEcqJiIiJiIiIi0lJGV4cEc2IywkKiYiIiRGKkYnRiohIiJGKg== quite literally and "sort of " made an expression called N(t). Look atN(t);It makes sense to differentiate this thingdiff(N(t),t);It makes sense to solve for when it is 1solve(N(t)=1,t);But you can easily see that it isn't a function that you can plug numbers into by doing this:N(5);And if you try to give t a value and then evaluate the expression N(t), not only does it not work, but it ruins N(t) as well:t:=3;evalf(N(t));solve(N(t)=1,t);The problem seems to be that the symbol N(t) that comes out of the assign is a funny mix of expression and function, so if you want to use this assign syntax instead of rhs, and it often does seem to be more natural to do so, be very careful about assigning values to the things that appear in the expression. And also notice that you can't go back to dsolve again with different initial conditions either, because N(t) has been ruined--it's time to restart.S1:=dsolve({E1,N(0)=3},N(t));This may seem so troublesome that you might never want to use assign, but assign makes the plot and other commands look so much cleaner than they do with rhs that I think it is still worth it sometimes. But don't plan on using it exclusively; rhs is often the safer thing to use.One final note about this: in the plot syntax, in the solve syntax, and in the differentiation syntax when it looks like we are using a Maple function N and invoking it with N(t) we are actually using a Maple expression (sort of) called N(t). If this is confusing (and it certainly confuses me) it might help to review the difference between expressions and functions way back in Chapter 1. Expressions and functionsProblem 7.1The differential equation governing the current NiMtJSJpRzYjJSJ0Rw== in a circuit containing a battery of emf NiMlKGVwc2lsb25H , resistance NiMlIlJH , and inductance NiMlIkxH isNiMvLCYqJiUiTEciIiItJSVkaWZmRzYkLSUiaUc2IyUidEdGLkYnRicqJiUiUkdGJ0YrRidGJyUoZXBzaWxvbkc=(Perhaps you are wondering why we aren't using NiMtJSJJRzYjJSJ0Rw== for the current? Recall that NiMlIklH is NiMtJSVzcXJ0RzYjLCQiIiIhIiI= in Maple, so we don't want to use this symbol for anything else.) Solve this differential equation for the current and plot the result if the initial current is zero, NiMvJSJMRy0lJkZsb2F0RzYkIiIiISIk H, NiMvJSJSRyomIiQrIiIiIiUmT21lZ2FHRic= , and NiMvJShlcHNpbG9uRyIiJw== V.----------------------------------------------------------------------------Problem 7.2Here is a problem involving the idea of "explosive growth". Suppose that you have discovered some process in which the rate of growth of the quantity NiMlInlH is not proportional to NiMlInlH itself, as in exponential growth, but is instead proportional to some power of NiMlInlH , say NiMqJCUieUciIiM= or NiMqJCUieUciIiQ= . Use Maple to explore these two cases by having it solve the differential equationNiMvLSUlZGlmZkc2JCUieUclInRHKUYnJSJwRw==for NiMvJSJwRyIiIw== and NiMvJSJwRyIiJA== and with the initial condition NiMvLSUieUc2IyIiISIiIg== . Then plot the solution over a big enough time interval that you can see the explosion.----------------------------------------------------------------------------Problem 7.3Consider the relatively innocuous first-order differential equationNiMvLSUlZGlmZkc2JCUieUclInhHLSUkc2luRzYjKiZGKCIiIkYnRi0= with NiMvLSUieUc2IyIiISIiIg== .Ask Maple to solve it and see what happens. In a later section on solving differential equations numerically we will try to solve this equation again.------------------------------------------------------------------------------You should also be aware of a couple of dsolve options that might be helpful.implicit: If you have a differential equation for NiMtJSJ5RzYjJSJ4Rw== , but think the solution might look simpler if NiMtJSJ5RzYjJSJ4Rw== were not explicitly solved for, use the implicit option:eq:=diff(y(x),x)=sin(y(x))/cos(x);"Explicit solution"dsolve(eq);"Implicit" solutiondsolve(eq,implicit);Notice that we don't have a solution in the form NiMvLUkieUc2IjYjSSJ4R0YmSSpzb21ldGhpbmdHRiY= but instead have an equation involving NiMtSSJ5RzYiNiNJInhHRiU= which must still be solved.parametric: And sometimes the combined option implicit,parametric can give you a nice solution instead of a horrible one:eq:=diff(y(x),x)^2-diff(y(x),x)+y(x);dsolve(eq);dsolve(eq,implicit,parametric);In this solution NiMlI19URw== is a parameter which, as it changes, gives both NiMlInlH and NiMlInhH , and hence gives (implicitly and parametrically) NiMtJSJ5RzYjJSJ4Rw== . Try this method if your solution comes back with RootOf troubles.Go to top of section<Text-field bookmark="Second order differential equation (top)" layout="_pstyle6" style="_pstyle6">Second order differential equations</Text-field>DebuggingSecond order equations are very common in physics because Newton's second law is second order and because diffusion, waves, and quantum mechanics all have governing equations containing second derivatives. Let's start with Newton's law of motion, and just as a warm up, let's do a falling object. The differential equation is justrestart:E2:=diff(y(t),t$2) = -g;S2:=dsolve({E2,y(0)=y[0],D(y)(0)=v[0]},y(t));Well, that should be a familiar result. Notice a few things about the way this was done. To enter an initial condition on the derivative of y use D(y), which means dy/dt (D is Maple's generic derivative symbol) then tack on (0) to tell it that the derivative is evaluated at t=0. Yes, this means that diff and D both mean derivative, and there is an important and subtle difference between them that is hard to remember; it is discussed in the section on derivatives in Chapter 3(diff and D). So either memorize the syntax of the dsolve command above, or remember where it is in this document so you can easily find it when you need to solve problems like this.Here's another famous second order differential equation, the harmonic oscillator.E3:=diff(y(t),t$2)=-omega^2*y(t);Maple solves it in its generic form with arbitrary constants this way dsolve(E3,y(t));Warning: this form of the solution is dangerous because there is no guarantee that every time you run a worksheet with this dsolve command in it that _C1 will go with sine and _C2 will go with cosine. Maple has its own internal logic about how to make this choice, but it can turn out to look pretty random in more complicated differential equations than this one. So don't let Maple make the choice. Once you get this form of the solution, use the mouse to copy the solution onto a new line and choose your own unknown coefficients like this (and get rid of the awkward y(t) = and replace it with a genuine assignment as well:)ysol:= A*sin(omega*t)+B*cos(omega*t);Any calculations you do to determine A and B will now work the same way every time because you have determined for all time that A goes with sine and B goes with cosine.If the constants are to be determined by initial conditions there is a form of the dsolve command that will determine them automatically. For instance, suppose that you want to solve the differential equation E3 with initial conditions y(0)=1 and dy/dt(0)=2. Then you can uses:=dsolve({E3,y(0)=1,D(y)(0)=2},y(t));Now we have Maple give us the expression y(t) by using assignassign(s);And then we can plot the solutionplot(y(t),t=0..20);Hmmm; that didn't work too well. The plot frame is there, but no function. And, unfortunately, no hint about what went wrong. To debug this problem it would be nice to put some values for t into y(t), but remember that y(t) looks like an expression, but isn't quite, and that assigning t a value will ruin it. So let's just look at y(t) this way and see if we can see what's wrongy(t);The plot command will supply numerical values for t, but the fact that NiMlJm9tZWdhRw== is just sitting in this expression without having a numerical value tells us what is wrong; we haven't given NiMlJm9tZWdhRw== a numerical value! Ok, so now do thisplot(subs(omega=1,y(t)),t=0..20);Now this problem was simple enough that you could have easily done it yourself once you had taken a class about differential equations. But Maple can do harder problems with ease as well. Let's add some damping to the harmonic oscillator by putting in a damping force of the form NiMvJSJGRywkKiglIm1HIiIiJSJ2R0YoJSR0YXVHISIiRis= , where NiMlJHRhdUc= is the characteristic time for damping to occur. The new equation of motion is nowrestart:with(DEtools):Eq:=diff(y(t),t$2) + diff(y(t),t)/tau + omega^2*y(t)=0;and we get the general solution this waydsolve(Eq,y(t));Well, that looks impressive. But if it's supposed to be an oscillator that damps, where are the sines and cosines? The problem is that Maple doesn't yet know how big NiMlJm9tZWdhRw== and NiMlJHRhdUc= are. Let's think physically for a minute. Suppose we have a natural frequency NiMlJm9tZWdhRw== of about NiMqJiIiIyIiIiUjUGlHRiU= , so the period NiMvJSJURyooIiIjIiIiJSNQaUdGJyUmb21lZ2FHISIi is 1 second. Now let's suppose that we have this oscillator (think of a pendulum) in motor oil at 50 degrees below zero so that the characteristic damping time is 0.05 seconds (so much friction that motion stops in 0.05 seconds). Your intuition should tell you that if you pull the pendulum back and release it, you are not going to see any swinging; all that is going to happen is that the pendulum will slowly ooze its way into the vertical position and stay there. Let's see what Maple saysomega:=2*Pi;tau:=.05;Y:=dsolve({Eq,y(0)=1,D(y)(0)=0},y(t));plot(rhs(Y),t=0..20);OK, Maple agrees with your intuition. Now let's change the damping and imagine what will happen. Your intuition should tell you that if you warm the oil up, or use WD-40 instead, or maybe even just air, the pendulum will start to swing and only damp slowly. For example, if NiMvJSR0YXVHIiM/ then Maple gives usomega:=2*Pi;tau:=20;Y:=dsolve({Eq,y(0)=1,D(y)(0)=0},y(t));plot(rhs(Y),t=0..20);Well, now it swings and only slowly damps. By what miracle did the exponential functions in the original solution above become sines and cosines? Remember Euler's formula: NiMvLSUkZXhwRzYjKiYlImlHIiIiJSZ0aGV0YUdGKSwmLSUkY29zRzYjRipGKSomRihGKS0lJHNpbkdGLkYpRik= ; in this oscillating case the constants in the exponential become imaginary, and that's how the formula changes from decay to wiggles.This brings up the question of what value of NiMlJHRhdUc= makes the transition from pure damping to damped oscillation. Look back at the general form and you will see that there is a square rootNiMvLSUlc3FydEc2IywkKiYsJiooIiIjIiIiJSR0YXVHRiwlJm9tZWdhR0YsRixGLCEiIkYsLCZGKkYsRixGLEYsRi8tRiU2IywmRixGLCooIiIlRiwqJEYtRitGLEYuRitGLw== in the exponentials. If the argument of this square root is positive, then both of the fundamental solutions in the sum are decaying exponentials and we have damping. If the argument of the square root is negative, then the square root is imaginary, the exponentials are imaginary exponentials, i.e., sines and cosines, and we have oscillation. The transition between the two is when the argument of the square roots is zero, i.e., when NiMvJSR0YXVHKiYiIiJGJiomIiIjRiYlJm9tZWdhR0YmISIi . This special case is called critical damping.Problem 7.4Have Maple solve the damped harmonic oscillator differential equation for the case of critical damping with NiMvJSZvbWVnYUciIiI= and plot the function y(t) from t=0 to t=20 with initial conditions y(0)=1 and dy/dt(0)=0. The plot will look just like damping with no hint that you are right on the border between damping and oscillation. To verify that you are right on the border increase NiMlJHRhdUc= by 2% and make the plot again. Window the graph down enough that you can see that y(t) goes a little bit negative, indicating that oscillation has begun. You will have to do some serious windowing to see this effect.----------------------------------------------------------------------------Problem 7.5One last harmonic oscillator problem: (a) Let's add a sinusoidal driving force at a frequency a little bit different from the natural frequency NiMlJm9tZWdhRw== , say NiMvJiUmb21lZ2FHNiMlImRHKiYtJSZGbG9hdEc2JCIjNiEiIiIiIkYlRi4= . Have Maple solve this differential equation and plot it from t=0 to t=300 with NiMvJSZvbWVnYUciIiI= and NiMvJSR0YXVHIiNJ . Use completely-at-rest initial conditions, y(0)=0 and dy/dt(0)=0.NiMvLCgtJSVkaWZmRzYkLSUieUc2IyUidEctJSIkRzYkRisiIiMiIiIqJi1GJjYkRihGK0YwJSR0YXVHISIiRjAqJiUmb21lZ2FHRi9GKEYwRjAtJSRjb3NHNiMqJiZGNzYjJSJkR0YwRitGMA==The plot should show the classic pattern of the driven-damped harmonic oscillator: an initial period of start-up with some beating between the natural and driving frequencies, then a transition to a state of oscillation with y(t) matched to the driving frequency. Verify graphically that the final oscillation frequency of y(t) is NiMmJSZvbWVnYUc2IyUiZEc= . (Hint: to avoid solving the differential equation over and over again with different parameter values when you get to part (b) below, have Maple solve the differential equation symbolically using variables NiMlJm9tZWdhRw== , NiMlJHRhdUc= , and NiMmJSZvbWVnYUc2IyUiZEc= , then plot it with specified values using the subs command, like this (the f here is just an example):f:=cos(w*t)/(1+s^2*t^2);plot(subs(w=2,s=3,f),t=0..5);(b) Study resonance in this system by making plots of NiMtJSJ5RzYjJSJ0Rw== vs. NiMlInRH in the following cases: (i) NiMvJSR0YXVHIiNJ : NiMvJiUmb21lZ2FHNiMlImRHKiYtJSZGbG9hdEc2JCIiKSEiIiIiIkYlRi4= , NiMvJiUmb21lZ2FHNiMlImRHRiU= , and NiMvJiUmb21lZ2FHNiMlImRHKiYtJSZGbG9hdEc2JCIjNyEiIiIiIkYlRi4= . (ii) NiMvJSR0YXVHIiIm : NiMvJiUmb21lZ2FHNiMlImRHKiYtJSZGbG9hdEc2JCIiKSEiIiIiIkYlRi4= , NiMvJiUmb21lZ2FHNiMlImRHRiU= , and NiMvJiUmb21lZ2FHNiMlImRHKiYtJSZGbG9hdEc2JCIjNyEiIiIiIkYlRi4= . (iii) NiMvJSR0YXVHLSUmRmxvYXRHNiQiIikhIiI= : NiMvJiUmb21lZ2FHNiMlImRHKiYtJSZGbG9hdEc2JCIiKSEiIiIiIkYlRi4= , NiMvJiUmb21lZ2FHNiMlImRHRiU= , and NiMvJiUmb21lZ2FHNiMlImRHKiYtJSZGbG9hdEc2JCIjNyEiIiIiIkYlRi4= .Verify that as the damping time gets longer, the resonant amplitude gets larger and the resonance gets narrower. You will save yourself some grief if you use the subs trick mentioned at the end of part (a) to make these plots. (c) Find formulas for the steady state motion of this driven-damped oscillator by substituting the guessNiMvLSUieUc2IyUidEcqJiUiQUciIiItJSRjb3NHNiMsJiomJiUmb21lZ2FHNiMlImRHRipGJ0YqRiolJHBoaUchIiJGKg==into the differential equation in part (a). Then require the NiMtJSRjb3NHNiMqJiYlJm9tZWdhRzYjJSJkRyIiIiUidEdGKw== and NiMtJSRzaW5HNiMqJiYlJm9tZWdhRzYjJSJkRyIiIiUidEdGKw== in the resulting equation to be separately equal (they are independent functions) to get two equations for the two unknowns NiMlIkFH and NiMlJHBoaUc= (see the collect command in Chapter 9 for an efficient way to separate the equation into these two parts). Solve these two equations and verify that the formula for NiMtJSJBRzYjJiUmb21lZ2FHNiMlImRH agrees with the steady state amplitudes you found in part (b). Finally, make plots of NiMtJSJBRzYjJiUmb21lZ2FHNiMlImRH and NiMtJSRwaGlHNiMmJSZvbWVnYUc2IyUiZEc= for the three choices of NiMlJHRhdUc= used in part (b) and verify again that a long damping time NiMlJHRhdUc= leads to larger and sharper resonance.----------------------------------------------------------------------------Problem 7.6Use Maple to solve the following second-order differential equations in general form.(a) NiMvLCgqJiUieEciIiMtJSVkaWZmRzYkLSUiZkc2I0YmLSUiJEc2JEYmRiciIiJGMSomRiZGMS1GKTYkRitGJkYxRjEqJiwmKiRGJkYnRjEqJCUibkdGJyEiIkYxRitGMUYxIiIh(b) NiMvLCgqJiUieEciIiMtJSVkaWZmRzYkLSUiZkc2I0YmLSUiJEc2JEYmRiciIiJGMSomRiZGMS1GKTYkRitGJkYxRjEqJiwmKiRGJkYnRjEqJCUibkdGJ0YxRjFGK0YxISIiIiIh(c) NiMvLCgqJiwmIiIiRicqJCUieEciIiMhIiJGJy0lJWRpZmZHNiQtJSJmRzYjRiktJSIkRzYkRilGKkYnRicqKEYqRidGKUYnLUYtNiRGL0YpRidGKyooJSJuR0YnLCZGOUYnRidGJ0YnRi9GJ0YnIiIhGo to top of section<Text-field bookmark="Systems of differential equations (top)" layout="_pstyle6" style="_pstyle6">Systems of differential equations</Text-field>DebuggingIt is often more convenient to deal with systems of differential equations than with second, third, or higher order differential equations. Indeed, many numerical methods require that you write your differential equation as a system of first order differential equations. Here's a simple example. If we call the acceleration dv/dt and the velocity dx/dt, then the harmonic oscillator equation can be written as the following first order setNiMvLSUlZGlmZkc2JC0lInZHNiMlInRHRiosJComJSZvbWVnYUciIiMtJSJ4R0YpIiIiISIiNiMvLSUlZGlmZkc2JC0lInhHNiMlInRHRiotJSJ2R0YpThe Maple command dsolve handles systems like this by asking for a set {sets have curly brackets} of equations and initial conditions, a set of functions to be solved for, and perhaps extra arguments, like thisrestart:Eq1:=diff(v(t),t)=-omega^2*x(t);Eq2:=diff(x(t),t)=v(t);dsolve({Eq1,Eq2,x(0)=1,v(0)=0},{x(t),v(t)});Notice that this is actually a nice form to have the answer in because we get both the position and the velocity simultaneously. And another good thing is that you don't have to remember the D notation for derivative initial conditions. To plot x(t) and v(t) we first need to give NiMlJm9tZWdhRw== a value, then solve againomega:=1;XV:=dsolve({Eq1,Eq2,x(0)=1,v(0)=0},{x(t),v(t)});then make the plots like this using the assign command againassign(XV);plot([x(t),v(t)],t=0..20);Problem 7.7Here are the equations of motion for a charged particle of mass m and charge q moving in the field of a constant magnetic field B in the z-direction and a constant electric field E in the y-direction which come from Newton's second law using the Lorentz force law: NiMvJSJGRywmKiYlInFHIiIiJSJFR0YoRigqJkYnRigtJSZjcm9zc0c2JCUidkclIkJHRihGKA== . (Note: the phrase equation of motion has special meaning for physicists and it takes a while for beginning physicists to figure out what we are talking about. It seems natural at first to think that the phrase "equation of motion" must mean the equations that describe the motion, like NiMvJSJ5RywoJkYkNiMiIiEiIiIqJiYlInZHRidGKSUidEdGKUYpKiglImdHRikqJEYtIiIjRilGMSEiIkYy , or NiMvLSUieEc2IyUidEcqJiUiQUciIiItJSRjb3NHNiMqJiUmb21lZ2FHRipGJ0YqRio= . This is not what physicists mean when they say "equation of motion". By equation of motion we mean the differential equation which, when solved, gives the formulas that describe the particle motion. If you can get this straight early on it will save you a lot of trouble.)NiMvLSUlZGlmZkc2JCUieEclInRHJiUidkc2I0YnNiMvLSUlZGlmZkc2JCUieUclInRHJiUidkc2I0YnNiMvLSUlZGlmZkc2JCYlInZHNiMlInhHJSJ0RyoqJSJxRyIiIiUiQkdGLiZGKDYjJSJ5R0YuJSJtRyEiIg==NiMvLSUlZGlmZkc2JCYlInZHNiMlInlHJSJ0RywmKiglInFHIiIiJSJFR0YvJSJtRyEiIkYvKipGLkYvJSJCR0YvJkYoNiMlInhHRi9GMUYyRjI=Define these equations in Maple and have Maple solve them with q=-1.6e-19, m=9.11e-31, B=0.2, E=3000 with initial conditions NiMvLSUieEc2IyIiIUYn , NiMvLSUieUc2IyIiIUYn , NiMvLSZJInZHNiI2I0kieEdGJzYjIiIhKiQiIzUiIiY= , NiMvLSYlInZHNiMlInlHNiMiIiFGKg== . Make plots in the x-y plane of the particle orbits NiMtJSJ4RzYjJSJ0Rw== and NiMtJSJ5RzYjJSJ0Rw== (they must be parametric plots with t as the parameter). You will need to choose a time interval for plotting and if you just choose something simple like 1 or 2, you will get garbage. Think about the physics of the problem; in particular, think about the cyclotron frequency: NiMvJiUmb21lZ2FHNiMlImNHKiglInFHIiIiJSJCR0YqJSJtRyEiIg== . Also make x-y plane plots of NiMtJiUidkc2IyUieEc2IyUidEc= and NiMtJiUidkc2IyUieUc2IyUidEc= with the scaling=constrained option. In this way you will be able to see that the velocity goes around in a circle (cyclotron motion) but with an offset. Verify that the velocity offset (called the "drift velocity") is given by NiMqJi0lJmNyb3NzRzYkJSJFRyUiQkciIiIqJEYoIiIjISIi .Go to top of section<Text-field bookmark="Numerically solving differential equations (top)" layout="_pstyle6" style="_pstyle6">Numerically solving differential equations</Text-field>DebuggingMost of the time Maple will not be able to solve your differential equation for you in terms of functions that it knows. When this happens you will want to solve the equation numerically, i.e., perhaps make a plot of the solution, find out what the solution is at x=2, etc. You tell Maple to solve the differential equation numerically by using dsolve with the option type=numeric, as shown in the example below. But before we start doing this let me warn you. (1) "Numerical" implies that floating point numbers (numbers with decimal points) are used. If you give Maple integers for values in initial conditions or constant definitions, dsolve(....type=numeric) may fail. (2) Since the whole point of doing a numerical calculation is to get a number and since Maple is loath to ever give you numbers, doing useful things with what Maple returns as the numerical solution of a differential equation is a bit awkward. You are likely to become more frustrated in this section of the text than any other so far. (3) You will have much better luck at getting Maple to give you what you want if you define your differential equations as first order sets than if you use 2nd, and higher, order derivatives. (4) Assign the result of dsolve to a variable name so you can refer to it later, i.e., use F:=dsolve(...type=numeric).OK, let's start by doing the harmonic oscillator numerically. First define the equations for x(t) and v(t).restart:omega:=1.;Eqx:=diff(x(t),t)=v(t);Eqv:=diff(v(t),t)=-omega^2*x(t);then define the initial conditionsIC:=x(0)=1.,v(0)=0.;and finally invoke dsolve with the numerical option set to get the numerical solutionXV:=dsolve({Eqx,Eqv,IC},{x(t),v(t)},type=numeric);XV is now a procedure that expects to be given a value of t so that it can return an approximate solution to x(t) and v(t), like thisXV(2.);Notice that the answer came out apparently accurate to 18 decimal places. In this case we know the answer is just NiMvLSUieEc2IyUidEctJSRjb3NHRiY= , so we can check it (after increasing the number of digits Maple keeps in floating point calculations).Digits:=18:cos(2.);Apparently Maple lied--the result of dsolve is pretty accurate (7 decimal places) but not as accurate as the numbers it returned would indicate. We can make it more accurate at the expense of having the solution take longer by specifying the numerical method to use (use ?dsolve,numeric to see what the choices are; rkf45 is a pretty good choice; if you have trouble, try another method) and setting the allowable error like thisXV:=dsolve({Eqx,Eqv,IC},{x(t),v(t)},type=numeric,method=rkf45,abserr=1e-10);XV(2);So this is better, but Maple won't let you improve it forever. Try changing the error to 1e-15 in the command above and see what happens. (Don't leave it this small in what follows or you will work your computer to death.)And now a word of advice: don't try to compute to an accuracy of 1 part in 1000000000000. Five or six significant figures is usually fine, although it is a good idea to do a numerical calculation twice with different error tolerances to make sure the setting you are using most of the time is OK for the problem at hand.All right, Maple has given us a procedure called XV that solves this differential equation numerically. Now suppose we want to plot it. Here's one thing that won't work: you can't use assign(XV) like we did with symbolic solutions. The easiest way that does work is to use the Maple command odeplots which expects to be given output from dsolve(....type=numeric). Note that you have to use the command with(plots) to make this command available. Here's another problem before we proceed. The error tolerance in the dsolve command above is set to 1e-10, which is so small that asking odeplot to find lots of points at this level is asking to be bored in front of a busy screen for a long time. So before we proceed, let's set the error to a more reasonable value for plotting.XV:=dsolve({Eqx,Eqv,IC},{x(t),v(t)},type=numeric,method=rkf45,abserr=1e-6);In this case it would be used like this to plot x(t)with(plots):odeplot(XV,[t,x(t)],0..20,numpoints=500,color=navy);or this way to plot both x(t) and v(t)odeplot(XV,[[t,x(t)],[t,v(t)]],0..20,numpoints=200);or do this to make a phase-space plot of v(t) vs. x(t) with time t as the parameterodeplot(XV,[x(t),v(t)],0..20,numpoints=200);Note two things. (1) odeplot takes all the usual plot options so you can make it look good and (2) if you have your error set really low and numpoints set really high, you are going to be waiting a long time for your plot to come out.Problem 7.8Here is problem 7.3 again, which Maple couldn't do symbolically. Do it numerically and plot y(x) from x=0 to x=20.NiMvLSUlZGlmZkc2JCUieUclInhHLSUkc2luRzYjKiZGKCIiIkYnRi0= with NiMvLSUieUc2IyIiISIiIg== .----------------------------------------------------------------------------Problem 7.9Here is a real physics problem. In Physics 121 you did the problem of a hard-hit baseball, but because you did it without air friction you were playing baseball on the moon. Let's play ball in a real atmosphere now. The air-friction drag on a baseball is approximately given by the following formulaNiMvJSJGRywkKjAmJSJDRzYjJSJkRyIiIiYlJHJob0c2IyUkYWlyR0YrJSNQaUdGKyUickciIiMtJSRhYnNHNiMlInZHRitGNkYrRjIhIiJGNw==where NiMmJSJDRzYjJSJkRw== is the drag coefficient (about 0.35 for a baseball), where NiMmJSRyaG9HNiMlJGFpckc= is the density of air (about 1.2 kg/NiMqJCUibUciIiQ= ), where NiMlInJH is the radius of the ball (about 0.037 m) and where NiMlInZH is the vector velocity of the ball. The absolute value in this formula pretty much guarantees that Maple won't be giving you a formula for the solution of this problem. If we take the vertical direction to be y and the horizontal direction to be x then Newton's second law in vector-component form gives us the following first-order set of equationsNiMvLSUlZGlmZkc2JCUieEclInRHJiUidkc2I0YnNiMvLSUlZGlmZkc2JCUieUclInRHJiUidkc2I0YnNiMvLSUlZGlmZkc2JCYlInZHNiMlInhHJSJ0RywkKjAmJSJDRzYjJSJkRyIiIiYlJHJob0c2IyUkYWlyR0YyJSNQaUdGMiUickciIiNGJ0YyLSUlc3FydEc2IywmKiRGJ0Y5RjIqJCZGKDYjJSJ5R0Y5RjJGMiomRjlGMiUibUdGMiEiIkZFNiMvLSUlZGlmZkc2JCYlInZHNiMlInlHJSJ0RywmKjAmJSJDRzYjJSJkRyIiIiYlJHJob0c2IyUkYWlyR0YyJSNQaUdGMiUickciIiNGJ0YyLSUlc3FydEc2IywmKiQmRig2IyUieEdGOUYyKiRGJ0Y5RjJGMiomRjlGMiUibUdGMiEiIkZFJSJnR0ZFwhere NiMlIm1H is the mass of the baseball (0.145 kg) and where NiMlImdH is the acceleration of gravity (9.8 m/NiMqJCUic0ciIiM= ). Give this problem to Maple by coding the four differential equations and hit a home run with it using initial conditionsNiMvLSUieEc2IyIiIUYnNiMvLSUieUc2IyIiISIiIg==NiMvLSYlInZHNiMlInhHNiMiIiEqJiZGJkYpIiIiLSUlc3FydEc2IyIiIyEiIg==NiMvLSYlInZHNiMlInlHNiMiIiEqJiZGJkYpIiIiLSUlc3FydEc2IyIiIyEiIg== where NiMvJiUidkc2IyIiISIjZw== m/s. Then use dsolve(...type=numeric) to solve it and make overlaid plots: (i) without air drag (set NiMvJiUiQ0c2IyUiZEciIiE= ) and (ii) with air drag, as discussed above. Plot y(t) vs. x(t) so you can see the path of the ball by using [x(t),y(t)] in odeplot instead of [t,y(t)]. Can you see that the trajectory with air friction is not a parabola? Power hitters in baseball say they would much rather play in Coors Field in Denver than in sea-level stadiums because it is so much easier to hit home runs. Do they know what they are talking about? To find out, do the home run with air friction again, but at the higher altitude of Denver to see if the ball goes significantly farther. The air pressure in Denver is about 10% lower than it is at sea level. Finally, to really see that the trajectory is not a parabola, use a very large initial velocity and observe that the ball finally comes down almost vertically. Can you explain why this is so?----------------------------------------------------------------------------Maple has a differential equation tools package called DEtools which has many different features, one of which provides a way of visualizing the way the solution to a differential equation "flows". This nice tool is called DEplot, and I will illustrate it with a damped harmonic oscillator:NiMvLSUlZGlmZkc2JC0lInhHNiMlInRHRiotJSJ2R0YpNiMvLSUlZGlmZkc2JC0lInZHNiMlInRHRiosJiomJSZvbWVnYUciIiMtJSJ4R0YpIiIiISIiKiYlImdHRjFGJ0YxRjI=where NiMlJm9tZWdhRw== is the angular frequency and where NiMlImdH is the damping rate. The command below shows how to give this coupled set of differential equations to DEplot and have it display the solution as a curve in the [x,v] plane. We call this plane phase space in physics and you will encounter it when you study classical mechanics at the junior level.First invoke the DEtools packagerestart:with(DEtools):eqx:=diff(x(t),t)=v(t);eqv:=diff(v(t),t)=-x(t)-.5*v(t);Now we will numerically solve this differential equation with initial conditions NiMvLSUieEc2IyIiISIiIg== and NiMvLSUidkc2IyIiIUYn , run it for 20 seconds, and plot its solution in [x,v] phase space. DEplot will also plot arrows that show how the solution curve flows in this space. This nice feature allows you to visualize what the solution looks like for initial conditions other than the one you chose.DEplot([eqx,eqv],[x(t),v(t)],t=0..20,[[x(0)=1,v(0)=0]],x=-1..1,v=-1..1,stepsize=.01,scaling=constrained,color=red,linecolor=navy);Take a minute now and use ?DEplot to study this command and learn what each of the terms in the above command does. Then increase the damping rate NiMlImdH and watch how the picture above changes. And finally change the damping term from NiMqJiUiZ0ciIiIlInZHRiU= to NiMqKCUiZ0ciIiIlInZHRiUtJSRhYnNHNiNGJkYl (air damping) and watch how the picture changes. Can you explain why the picture changes from the way it looked before?Advanced topic: shootingProblem 7.10 Sometimes we don't want to just solve a differential equation with known initial values. Perhaps there is a parameter in the differential equation that is unknown and we need to determine its value based on the solution of the differential equation at some other point. Or perhaps we want to start out with part of the initial conditions given and then adjust the undetermined initial conditions until that the solution satisfies some other conditions at the far end. Adusting things so that you start at point a and then hit a target at point b sounds so much like artillery that techniques that solve this kind of problem are usually called shooting methods. When a symbolic solution can be found this is not so hard, but when the differential equation must be solved numerically it can be quite difficult. In fact, I can't make Maple do it with its built-in commands, so I will have to give you a procedure based on one written by Dr. Robert Israel to show you how such problems are solved. But first, let's choose a specific problem to solve.Schrodinger's equation for the bound states of a particle in a harmonic oscillator potential well is this:NiMvLCYqKCUlaGJhckciIiMtJSVkaWZmRzYkJSRwc2lHLSUiJEc2JCUieEdGJyIiIiomRidGMCUibUdGMCEiIkYzKiolImtHRjAqJEYvRidGMEYrRjBGJ0YzRjAqJiUiRUdGMEYrRjA=To make it a nice dimensionless problem we change the length variable from NiMlInhH to NiMlI3hpRw== by doing this:NiMvJSJ4RyomJSJhRyIiIiUjeGlHRic= where NiMvJSJhRykqJiUlaGJhckciIiMqJkYoIiIiJSJtR0YqISIiKiZGKkYqIiIlRiw=and by changing NiMlIkVH into the eigenvalue NiMlJ2xhbWJkYUc= by doing this:NiMvJSdsYW1iZGFHKiwiIiMiIiIlIm1HRiclImFHRiYlIkVHRicqJCUlaGJhckdGJiEiIg== .With these changes of variable Schrodinger's equation becomesNiMvLCYtJSVkaWZmRzYkJSRwc2lHLSUiJEc2JCUjeGlHIiIjIiIiKiYsJiUnbGFtYmRhR0YuKiRGLEYtISIiRi5GKEYuRi4iIiE= .The solutions of this equation come in two types: even functions in NiMlI3hpRw== and odd functions in NiMlI3hpRw== . Hence we will have two different kinds of initial conditions at NiMvJSN4aUciIiE= : even: NiMvLSUkcHNpRzYjIiIhIiIi and NiMvLS0lJWRpZmZHNiQlJHBzaUclI3hpRzYjIiIhRis= odd: NiMvLSUkcHNpRzYjIiIhRic= and NiMvLS0lJWRpZmZHNiQlJHBzaUclI3hpRzYjIiIhIiIi(You may be wondering why we use 1 for the initial value or slope; why not .7, 1e-16, or something else? What we use doesn't matter. If you look at the differential equation every term has NiMlJHBzaUc= in it, so if you double some solution that you have found, the doubled NiMlJHBzaUc= will also be a solution, just twice as big. So since the size doesn't matter we just use 1. If you were going to do real physics, however, then at the end you would have to choose an overall multiplier for NiMlJHBzaUc= so that the total probability is 1. You will learn all about this in quantum mechanics.)The only solutions for the wave function NiMlJHBzaUc= that make physical sense are the ones that go to zero as NiMlI3hpRw== approaches NiMlKWluZmluaXR5Rw== . You will shortly see that this is only true for very special values of the parameter NiMlJ2xhbWJkYUc= , so we need a procedure that does the following: (i) It must be able to solve the differential equation numerically and (ii) it must be able to adjust the parameter NiMlJ2xhbWJkYUc= to make the wavefunction NiMlJHBzaUc= be small at large NiMlI3hpRw== .Well, here is the Maple code containing the shooting procedure, all set up to solve a simpler problem, which is similar to our quantum problem. The practice differential equation is (harmonic oscillator) NiMvLCYtJSVkaWZmRzYkJSJ5Ry0lIiRHNiQlInhHIiIjIiIiKiYlJ2xhbWJkYUdGLUYoRi5GLiIiIQ== with NiMvLSUieUc2IyIiIUYn and NiMvLS0lJWRpZmZHNiQlInlHJSJ4RzYjIiIhIiIi .We want to adjust NiMlJ2xhbWJkYUc= so that we meet the condition NiMvLSUieUc2IyIiIiIiIQ== . Follow along and run the procedure below, then modify it to find the values of NiMlJ2xhbWJkYUc= in Schrodinger's equation for the first 6 bound states (3 even and 3 odd). You will need to decide how far out to go in NiMlI3hpRw== to approximate infinity. Don't overdo it! Somewhere in the 5-10 range is probably enough.Start fresh and pull in odeplotrestart:with(plots): Define the differential equation and assign it to deqn. NOTE: the parameter you are going to vary to satisfy the shooting condition on the right end must be called lambda for this section of code to work. deqn:=diff(y(x),x$2)+lambda^2*y(x)=0; Define the left and right endpoints of the intervala:=0;b:=1; Define the initial conditions at the beginning of the interval.bc:=y(a)=0,D(y)(a)=1;yright:=0;lambda:=2.5;Note that the startinit=true option tells dsolve to always start with the specified initial conditions. This is important to have set when we use fsolve to find the value of param that gives the solution with y(b)=yright.S:=dsolve({deqn,bc},y(x),type=numeric,startinit=true);odeplot(S,[x,y(x)],a..b);F:=proc(z)local a,b,deqn,bc,S;deqn:=diff(y(x),x$2)+z^2*y(x)=0; a:=0;b:=1;bc:=y(a)=0,D(y)(a)=1; if type(z,numeric) then S:=dsolve({deqn,bc},y(x),type=numeric,startinit=true,abserr=1e-6); subs(S(b),y(x)) else 'F(z)'; end if;end;F(NiMlJ2xhbWJkYUc= ) now can be passed into fsolve to find a value of NiMlJ2xhbWJkYUc= that satisfies F(b)=yright. In the paragraph below you will see how to do this.Set Digits to a lower value so fsolve doesn't kill itself trying to get an answer correct to many significant figures when dsolve isn't accurate enough to deliver this much accuracy. If you don't get the right balance between abserr in the dsolve in the procedure and the Digits setting here, fsolve will run forever.Digits:=5;F(3.);lambda:=fsolve(F(z)=yright,z=3.0..3.2);S:=dsolve({deqn,bc},y(x),type=numeric):odeplot(S,[x,y(x)],a..b);Notice that the solution now goes to zero at the right edge, as we desired.----------------------------------------------------------------------------------Problem 7.11The equation of motion of a relativistic harmonic oscillator is NiMvLSUlZGlmZkc2JCUicEclInRHLCQqKCUibUciIiIqJCYlJm9tZWdhRzYjIiIhIiIjRiwlInhHRiwhIiI= , where NiMlInBH is the relativistic momentum NiMvJSJwRyooJSJtRyIiIiUidUdGJy0lJXNxcnRHNiMsJkYnRicqJkYoIiIjKiQlImNHRi4hIiJGMUYx , where NiMlInVH is the particle velocity NiMvJSJ1Ry0lJWRpZmZHNiQlInhHJSJ0Rw== . (a) Write this equation of motion in the form of two coupled first order differential equations. The first one is easy because it has been given in the first line of this problem. The second one is of the form NiMvLSUlZGlmZkc2JCUieEclInRHJSJ1Rw== . Solve for NiMlInVH in terms of NiMlInBH to get this second equation. (b) Use dsolve(...type=numeric) to make a procedure that you can use in odeplot to make graphs of NiMtJSJ4RzYjJSJ0Rw== for the cases NiMvLSUieEc2IyIiIS0lJkZsb2F0RzYkIiIjISIi , .4, 1., 5. and NiMvLSUicEc2IyIiIUYn . Verify graphically in the last case that the reason that x(t) looks so strange is that it is obeying the relativistic speed limit. In this last case make a plot of the particle speed u(t).Go to top of section<Text-field bookmark="How does a differential equation mean? (top)" layout="_pstyle6" style="_pstyle6">How does a differential equation make a curve?</Text-field>DebuggingIt is important in physics to have an intuitive feel for what differential equations mean rather than just memorizing a bunch of techniques and formulas. Without this feel you won't be able to propose and refine mathematical models for physical processes. So let's look at a simple one and try to translate it into words:NiMvLSUlZGlmZkc2JCUieUclInhHRic=Since NiMtJSVkaWZmRzYkJSJ5RyUieEc= is the slope of the function y(x) this equation says that the bigger y gets the bigger its slope gets. Let's try the two possible cases. (i) y(0) is positive. The differential equation then says that the slope is positive, so y is increasing. But if y increases its slope increases, making y increase more, making its slope increase more, etc. So it is no surprise that the solution of this equation is a function like NiMtJSRleHBHNiMlInhH that gets huge as x increases. (ii) y(0) is negative. Now the differential equation says that the slope is negative, so y will have to decrease, i.e., become more negative than it was at x=0. But if y is more negative then the slope is more negative, making y even more negative, etc. Again, it's no surprise that the solution is a strongly decreasing function like NiMsJC0lJGV4cEc2IyUieEchIiI= .With this kind of qualitative analysis in mind, let's go back to an explosive-growth differential equation like the ones you did in the section on first order equations, sayNiMvLSUlZGlmZkc2JCUieUclInhHKiRGJyIiIw== .Keeping in mind that with a first power on the right we got the exponential function, this equation says that if y starts out positive, y should increase even more than it did before, i.e., get bigger faster than the exponential function. That would have to be pretty impressive, and it is: it goes to infinity before x gets to infinity: s:=dsolve({diff(y(x),x)=y(x)^2,y(0)=1},y(x));plot(rhs(s),x=0..1);Problem 7.12Now think about what should happen if y(0) is negative. Make some rough sketches, then check your answer by changing the initial conditions in the example above. ----------------------------------------------------------------------------You can play this game with second-order differential equations too. Let translate the simple harmonic oscillator equation NiMvLSUlZGlmZkc2JCUieUctJSIkRzYkJSJ4RyIiIywkRichIiI=into words. We need to remember that the second derivative means the curvature of the function: a positive second derivative means that the function curves like the smiley face of someone who is always positive, while negative curvature means that it curves like a frowny face (easy to remember, no?) And if the second derivative is large in magnitude then the smile or frown is very narrow (like a piece of string suspended between its two ends from fingers held close together) and if the second derivative is small in magnitude it is like taking the same piece of string and stretching your arms apart to make a wide smile or frown. Ok, what does this equation say if y=1 to start? Well, the second derivative is negative, so the function y curves downward, making y smaller, which makes the frowniness smaller, but still negative, so y keeps curving downward until it crosses y=0. Then with y negative the differential equation says that the curvature is positive, making y start to smile and curve upward. It doesn't curve much at first because y is pretty small in magnitude, but eventually y will have a large enough negative value that y(x) turns into a full-fledged smile, stops going negative, and heads back up toward y=0 again. When it gets there y becomes positive, the function gets frowny and turns back around toward y=0, etc. So it is no surprise that the solution of this equation is an oscillation, NiMtJSRjb3NHNiMlInhH .Problem 7.13(a) Use this qualitative analysis to guess what the solution of this equation would look like, then check your answer with Maple.NiMvLSUlZGlmZkc2JCUieUctJSIkRzYkJSJ4RyIiI0Yn with NiMvLSUieUc2IyIiISIiIg== and NiMvLS0lJWRpZmZHNiQlInlHJSJ4RzYjIiIhRis= .(b) Use this qualitative analysis to guess what the solution of this equation would look like, then check your answer with Maple (you will need to use dsolve(....type=numeric) and odeplot).NiMvLSUlZGlmZkc2JCUieUctJSIkRzYkJSJ4RyIiIywkKiRGJ0YsISIi with NiMvLSUieUc2IyIiISIiIg== and NiMvLS0lJWRpZmZHNiQlInlHJSJ4RzYjIiIhRis=(c) Same thing for this oneNiMvLSUlZGlmZkc2JCUieUctJSIkRzYkJSJ4RyIiIywkKiRGJyIiJCEiIg== with NiMvLSUieUc2IyIiISIiIg== and NiMvLS0lJWRpZmZHNiQlInlHJSJ4RzYjIiIhRis=----------------------------------------------------------------------------Problem 7.14Think again about the baseball problem, Problem 7.9. If you look at your trajectory, and expecially if you increase the initial speed of the bat up to something like 80 m/s, you will see that instead of a parabola you get a curve that starts like a parabola, but then drops almost vertically at the end. Use qualititative analysis on the x and y components of Newton's second law to explain why this occurs.----------------------------------------------------------------------------Problem 7.15Consider again the harmonic-oscillator bound-state problem, Problem 7.10:NiMvLCYtJSVkaWZmRzYkJSRwc2lHLSUiJEc2JCUjeGlHIiIjIiIiKiYsJiUnbGFtYmRhR0YuKiRGLEYtISIiRi5GKEYuRi4iIiE=Think about what its solutions qualitatively look like both for small NiMlI3hpRw== and for large NiMlI3hpRw== and show that this qualitative analysis gives roughly the right answer for what the bound state eigenfunctions look like.Go to top of section<Text-field bookmark="Nonlinear dynamics" layout="_pstyle6" style="_pstyle6">Nonlinear dynamics and chaos (advanced topic)</Text-field>DebuggingThe use of computers over the past 40 years has completely revived the stodgy old subject of classical mechanics, and the system of equations that started the whole thing are these three coupled ode's discovered by Ed Lorentz while trying to model the weather.restart;with(plots):Eq1:=diff(x(t),t) = sigma*(y(t)-x(t));Eq2:=diff(y(t),t) = r*x(t)-y(t)-x(t)*z(t);Eq3:=diff(z(t),t) = x(t)*y(t)-b*z(t);where the constants NiMlJnNpZ21hRw== , NiMlInJH , and NiMlImJH can chosen however you like. For most choices of these parameters the solutions are not particularly interesting, but Lorentz discovered that there is a range of choices for which the solution behaves in a very strange way. If we choosesigma:=10;b:=8/3;and then vary NiMlInJH from 0 up to about 30, a transition occurs from ordinary boring behavior to something so strange that it has revolutionized many fields of science, including physics. To numerically solve this set for a specific choice of r we user:=10;s:=dsolve({Eq1,Eq2,Eq3,x(0)=1,y(0)=1,z(0)=1},{x(t),y(t),z(t)},type=numeric);and to see what the solutions look like we use odeplotodeplot(s,[[t,x(t)],[t,y(t)],[t,z(t)]],0..30,numpoints=600);Take a few minutes now and run this execution group for the following values of NiMlInJH : 10, 20, 28, 35, 45. For r above about 25 the oscillations form a never-repeating pattern (which you can sort of see if you run for a longer time in the odeplot). And what's worse, if you use slightly different initial conditions you get a completely different pattern (this is the famous butterfly effect. To observe it use NiMvJSJyRyIjXQ== and compare x(0)=1 in the initial conditions with x(0)=1.0000001, paying particular attention to what the green and red traces look like near NiMvJSJ0RyIjSQ== .) This is completely unexpected. The equations that govern this behavior are completely deterministic and quite simple--how can random garbage come out of something this simple? It's truly amazing, and this kind of behavior is called dynamical chaos. Here is another way to look at it. Instead of plotting x(t), let's plot the trajectory of the solution curve [x(t),y(t),z(t)] as a 3-dimensional curve using Maple's spacecurve plot command. To use it we need to make a loop that repeatedly calls dsolve to generate a sequence of 3-dimensional points along the system trajectory. This sequence of points is then passed into spacecurve, like this:Put the initial values of (x,y,z) in r0, the starting time in t1, the ending time in t2 and the number of points along the trajectory in numpoints; then calculate the time step between successive points.r0:=[1,1,1];t1:=0;t2:=10;numpoints:=400;dt:=(t2-t1)/numpoints;Set the system parameter rr:=50;Step the system along with repeated calls to dsolve, each one having for its initial conditions the ending conditions from the previous step. This is done with a for-do-end do loop, which we will study in Chapter 8. Note: this takes a while, so be patient.for i from 1 to numpoints do s:=dsolve({Eq1,Eq2,Eq3,x(0)=r0[1],y(0)=r0[2],z(0)=r0[3]},{x(t),y(t),z(t)},type=numeric): t0:=t1+(i-1)*dt: tf:=t0+dt: sol:=s(tf-t0):Store (x,y,z) in rf[i] after each step rf[i]:=[rhs(op(2,sol)),rhs(op(3,sol)),rhs(op(4,sol))]:Get the next initial condition r0:=rf[i]:Bottom of the loop; go back up and do it againend do:Turn rf into a sequence for use with spacecurveL:=[seq(rf[i],i=1..numpoints)]:Plot the trajectoryspacecurve(L,orientation=[45,60]);Now make 100 spacecurve plots, each one with a slightly different viewing angle. Then we will animate the sequence so that the trajectory rotates on the screen, making it easy to see its 3-dimensional characterfor i from 1 to 100 do theta :=45:phi:=i*3.6:p[i]:=spacecurve(L,orientation=[theta,phi]):od:Plot the animation. Note: when the picture comes up and the clock goes away, click on the picture to make the animation controls appear on the toolbar.plots[display]([seq(p[i],i=1..100)],insequence=true);Of course you can just click on a single space curve plot and use the cursor to rotate the picture any way you want, but I wanted you to see how to animate a spacecurve.Problem 7.16Look at how the system trajectory changes character as it changes from going to a fixed point to wandering around on the so-called strange attractor displayed by spacecurve. The transition occurs as r increases past a number around 25, or so, although if you let the system run for a long time the attractor starts to show up at lower values of r. If you try to keep numpoints too high this will take forever, and if you don't run long enough you won't be able to see where the transition occurs; use numpoints=200 and t2=20.Go to top of sectionGo to top of chapter<Text-field bookmark="Programming (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 8: Programming -- logic, loops, and procedures</Text-field>Sometimes Maple won't have a command that does what you need to do. When this happens you have to do your own programming in Maple using logic, loops, and procedures. We will start with logic<Text-field bookmark="Logic: if-then-else-fi (top)" layout="_pstyle6" style="_pstyle6">Logic: if-then-else-end if</Text-field>DebuggingThe basic logic command in Maple is the if statement. To illustrate it, suppose that you wanted a Maple function f(x) that would accept a value x and return -1 if x<0, 0 if x=0, and +1 if x>0. You would write it this way:restart;f:=x-> if x<0 then -1 elif x=0 then 0 else 1 end if;Here's a test to see if it worksf(-.5);f(0);f(.5);(Note: this is the same as Maple's signum function.)(As you will see in a minute, this if-then-elif-else-end if way of building functions with special cases doesn't work well in Maple. The piecewise syntax introduced below is the best syntax to use. I am only using this more awkward form to introduce you to logic statements.)The statement defining the function f almost reads like English if you just translate elif as "else if" and end if as "we're done". As you can see there are three elements that go into this statement. The first are the logical syntax commands if ... then, elif ... then, else, and end if. They have to be in this order. The second element is the conditional statement (logical test statement). These are things like x<0, etc. Maple allows the following logical tests < less than <= less than or equal > greater than >= greater than or equal = equal <> not equalWhen Maple encounters a test like this it evaluates it as a Boolean expression, i.e., as an expression whose value can be true or false. To help you debug things Maple has a a Boolean evaluator command evalb. It works like thisevalb(7>5);evalb(3=4);evalb(3<>4);Stare at the results of executing these commands until they make sense. Note: and, or, and not can also be used to combine logic statements, like this -2<=x and x<=-1 .There are other conjuctions as well; see ?if and ?boolean for more details.The third element of the if statement is the set of statements that it executes. In the example above these are just the numbers -1, 0, and 1, but any valid expression could go in these positions. For instance, we could use this construct to define a function which is one thing for negative numbers and another for positive numbers, like this:g:=x-> if x<0 then 1/(1+x^2) else cos(x) end if;Test it to make sure there are no errorsg(-1.5);g(2.5);Ok, we seem to be getting numbers out. But watch what happens if you do thisg(Pi);You need to able to interpret this error message because you will be getting it occasionally. It tells you that it tried to evaluate g, but that when it did, at least one of the Boolean expressions couldn't be evaluated. This happened because Pi is not really a number in Maple, so we just asked for a comparison between the number 0 and the non-number Pi. (Pi is more of an idea than a number in Maple.) You get the same error if you try to evaluate g(a), where a hasn't been given a number yetg(a);The problem with Pi can be fixed by remembering that Pi is tricky and always using evalf(Pi) when you want a number:g(evalf(Pi));Now let's plot our function and see what it looks likeplot(g(x),x=-10..10);Whoa, bad booleans again. Now what went wrong? Well, with the if statement in g(x) Maple can't plot with this syntax. When x goes from the plot command into g, x is apparently not yet a number. A clue to solving this problem is found by looking at what Maple did to our statement g:=x->... above; it turned it into a procedure (more about these later). And Maple plots procedures using "operator notation", meaning that you don't say g(x),x=-10..10 in the plot command, you just leave x out, like thisplot(g,-10..10);It can be differentiated with the D command like this:D(g);But if you try to integrate it, you are at a dead end:int(g(x),x=-2..2);This difficulty is the reason that the if-then-else-end if syntax is not very convenient for defining functions in Maple. But piecewise functions like this are pretty important, so it would be good if there were some clean way to handle them. Fortunately, there is. Maple has a piecewise command that is used for exactly this purpose. To redefine the function g(x) using piecewise we would do thisg:=x->piecewise(x<0, 1/(1+x^2),x>=0, cos(x));Now it really is a function and you can plot it like a functionplot(g(x),x=-5..5);integrate it like a functionint(g(x),x=-5..5);and differentiate it like a functiondiff(g(x),x);So this is the best way to do piecewise functions; if-then-elif-end if is mostly used inside loops and procedures, which we will get to shortly.Problem 8.1Use the piecewise construct to define a Maple function which evaluates the so-called cubic B-spline function and plot it from t=-4..4. The function is defined this way: _____________________________________________________________ NiMqJiwmIiIjIiIiJSJ0R0YmIiIkIiInISIi if NiMlInRH is in the range -2..-1 ______________________________________________________________NiMqJiwmIiIiRiUqJiwmRiVGJSUidEdGJUYlLCYiIiRGJSomRidGJSwmRipGJSomRipGJUYnRiUhIiJGJUYlRiVGJUYlIiInRi4= if NiMlInRH is in the range -1..0 B(t) = ______________________________________________________________NiMqJiwmIiIiRiUqJiwmRiVGJSUidEchIiJGJSwmIiIkRiUqJkYnRiUsJkYrRiUqJkYrRiVGJ0YlRilGJUYlRiVGJUYlIiInRik= if NiMlInRH is in the range 0..1 ______________________________________________________________ -NiMqJiwmJSJ0RyIiIiIiIyEiIiIiJCIiJ0Yo if NiMlInRH is in the range 1..2 ______________________________________________________________For NiMlInRH outside of the range -2..2 , NiMvLSUiQkc2IyUidEciIiE= . You will discover that when you need to specify a range with a beginning and an end, like -1 to 0, you will need to combine two inequalities, i.e. b<a<c. Maple does this by using two different inequality conditions and combining them with and, like this:b<a and a<c. When you get the function defined, plot it between -4 and 4.----------------------------------------------------------------------------Problem 8.2Integrate B(t) from -3..3. Also plot its first three derivatives on the interval -3..3.----------------------------------------------------------------------------Problem 8.3Here's an example of a problem where piecewise won't work cleanly and it is better to use the if...end if syntax.Use this syntax to make a plot of the sine function from NiM7LCQqJiIiIyIiIiUjUGlHRichIiJGJQ== , but with the peaks and valleys all chopped off flat at height 0.9 or depth -0.9. The Maple command signum will be useful in doing this, as will your old friend evalf. Note that instead of doing logic horizontally (in x), as we do when using piecewise, you will be doing logic vertically (in y) instead.Go to top of section<Text-field bookmark="Loops: for, do, od, while, and break (top)" layout="_pstyle6" style="_pstyle6">Loops: for, do, end do, while, and break</Text-field>DebuggingMuch of computing is done in loops: Maple's sum command has a loop at the bottom, as does numerical integration, fsolve, numerical differential equation solving, dsolve(...type=numeric), and many more. You have seen an example of a homemade loop in the three-dimensional integration procedure in the calculus section[Triple integrals] and in the differential equation section on Shooting. When Maple won't do what you want it to do, you will often find yourself writing your own loop. So that we have something concrete to talk about, let's write our own loop to sum the squares of the integers from 1 to 100. Maple's sum command does it this waysum(i^2,i=1..100);Somewhere down in Maple's depths, what is actually being done by this command is a loop. A handmade one would go like this. Sum Loop:First you decide where you want the answer to be stored and set that variable to zero:answer:=0;Then you make a loop that counts from 1 to 100, and inside that loop you square the counter and add its square into answer, like this using Maple's for..from..to..do..end do syntax. Note that do means "beginning of the loop" and end do means "end of the loop".for i from 1 to 100 do answer:=answer + i^2;end do;Well, that was more information than you wanted. To fix this, end the end do that terminates the loop with a colon instead of a semicolon then look at answer at the end.answer:=0;for i from 1 to 100 do answer:=answer + i^2;end do:answer;And what if you want to sum the odd numbers from 1 to 99? Well, you just want to start at 1, end at 99, and step up by 2. A loop that does this using Maple's by syntax isanswer:=0;for i from 1 by 2 to 99 do answer:=answer + i^2;end do:answer;Successive Substitution Loop:If you know how far you want to count this is all you have to do, but sometimes you don't know how many times you want to loop. Instead, you want to loop until some condition is met. For instance, here is an interesting little trick that some of you may have noticed on your hand calculators. What happens if you just take the cosine of a number over and over and over? Let's let Maple do it 20 times and show us what it's doing as it goes along.x:=5.;for i from 1 to 20 doTake the cosine of x and store the result in x so we can do it again and again x:=cos(x);end do;It looks like the answer is converging to something. And in fact, if you think for just a minute, you will be able to see that the number it is converging to has to be a solution of the equation NiMvLSUkY29zRzYjJSJ4R0Yn . (Explain to your partner or to the TA why this is true.) But you can also see that 20 times was not enough to get 10 digits right; what we would really like to do is loop until successive answers are within some tolerance of each other, say 1e-8, just to make the problem definite. Maple will let you end the loop that way too, with just a little bit of extra programming.Choose a starting value of x and an initial fake value of xold, the "previous value of x"x:=5.;xold:=0;Keep looping as long as |x-xold|>1e-8 (this is why we need the initial fake value of xold)while abs(x-xold)>1e-8 doPut the new x from taking the cosine into a temporary variable tempx tempx:=cos(x):Put the current x into xold so we will be able to tell when to quit xold:=x:Put the new x (called t right now) into xx:=tempx;print(x); # print the new x each iterationGo back up and do it againend do: # colon suppresses printing, except for the print commandThis is called successive iteration, and it is used in computing a lot. It would be a good idea for you to look at the structure of this loop carefully to see how it is built. In particular, pay attention to when each variable is computed and where it is stored. Well, those are two commonly used kinds of loops. For additional information see ?for.Problem 8.4Write a loop that evaluates the power series for the cosine function, NiMvLSUkY29zRzYjJSJ4Ry0lJHN1bUc2JCooKSwkIiIiISIiKiYlIm5HRi4iIiNGL0YuKUYnRjFGLi0lKmZhY3RvcmlhbEc2I0YxRi8vRjE7IiIhJSlpbmZpbml0eUc= for NiMlIm5H even . Give NiMlInhH a value outside the loop, use the by syntax to get even numbers, and keep looping until the next term added to the sum is less than 1e-8. To do this you will need to know how to make a loop that adds. There is one at the beginning of this section, right here: Adding loop--------------------------------------------------------------------------------Problem 8.5Write a loop that evaluates the Fourier series NiMvLSUiZkc2IyUmdGhldGFHLSUkc3VtRzYkKigpLCQiIiIhIiIlIm5HRi4tJSRzaW5HNiMqJiwmKiYiIiNGLkYwRi5GLkYuRi5GLkYnRi5GLkY1Ri8vRjA7IiIhJSlpbmZpbml0eUc= . Give NiMlJnRoZXRhRw== a value outside the loop and keep looping until the magnitude of the terms being added drop below 1e-4 in magnitude. Since the sine function is never greater than 1 in magnitude, this means that you only need to apply the while test to NiMqJiIiIkYkLCYqJiIiI0YkJSJuR0YkRiRGJEYkISIi . (It is bad to test on the whole term with the sine included because the sine might just happen to be really small and cause the loop to terminate too soon.)--------------------------------------------------------------------------------Problem 8.6Write a loop to solve the equation NiMvJSJ4Ry0lJGV4cEc2IywkRiQhIiI= by successive substitution. Get the answer to 8 significant figures. To see how to build a successive substitution loop go here (just above): Successive substitution loop--------------------------------------------------------------------------------Problem 8.7 (Secant Method)Here's a loop that computational physicists use all the time. It's called the secant method and it's a way of solving hard equations in one variable. In fact, Maple almost certainly uses a fancy varition of this technique inside the fsolve command. I also used it in the shooting procedure for differential equations in Chapter 7. Here's the idea.Suppose you want to solve a hard equation of the form NiMvLSUiZkc2IyUieEciIiE= , for NiMlInhH . The secant method starts by asking you for two reasonably close guesses NiMmJSJ4RzYjIiIi and NiMmJSJ4RzYjIiIj . Then you evaluate the function at each value of NiMlInhH to get NiMvJiUiZkc2IyIiIi1GJTYjJiUieEdGJg== and NiMvJiUiZkc2IyIiIy1GJTYjJiUieEdGJg== . You learned in high school algebra what to do with two ordered pairs (NiQmJSJ4RzYjIiIiJiUiZkdGJQ== ) and (NiQmJSJ4RzYjIiIjJiUiZkdGJQ== ) like this: use the two-point line formula to put a straight line through them: NiMvLCYlInlHIiIiJiUiZkc2IyIiIyEiIiooLCZGJ0YmJkYoNiNGJkYrRiYsJiUieEdGJiZGMUYvRitGJiwmJkYxRilGJkYyRitGKw== . But what we have just built is a straight-line approximation to the function NiMtJSJmRzYjJSJ4Rw== , so to get an approximation to the value of NiMlInhH that solves our hard equation, we just solve the line formula above for the value of NiMlInhH that gives NiMvJSJ5RyIiIQ== and call it NiMmJSJ4RzYjIiIk , our next best guess at where the solution is.restart;Eqline:=0-f2=(f2-f1)/(x2-x1)*(x-x2);x3:=solve(Eqline,x);This is a good algebraic expression, but not a good numerical one because as we get close to the root when both x1 and x2, and f1 and f2, are close to each other we get x3 by almost dividing zero by zero. This can cause floating point troubles, so it is better to rearrange this formula so that it looks like this:NiMvJiUieEc2IyIiJCwmJkYlNiMiIiMiIiIqKCYlImZHRipGLCwmRilGLCZGJTYjRiwhIiJGLCwmRi5GLCZGL0YyRjNGM0Yz .With this form we get the next best guess by adding something small to the previous best guess and we get in less numerical trouble. It is true that both (NiMsJiYlInhHNiMiIiMiIiImRiU2I0YoISIi ) and (NiMsJiYlImZHNiMiIiMiIiImRiU2I0YoISIi ) are small, so we are dividing zero by zero again, but the values of NiMmJSJmRzYjIiIi and NiMmJSJmRzYjIiIj in the numerator are extra small because we are close to NiMvLSUiZkc2IyUieEciIiE= , so the sins we commit in dividing zero by zero don't affect the answer as much. Ok, here is finally the problem: Write a loop that uses the secant method to solve the equation NiMvLCYtJSR0YW5HNiMlInhHIiIiKiYiIiNGKUYoRikhIiIiIiE= for a root near NiMvJSJ4RyIiIg== . (Make your loop similar to a Successive substitution loop.) In the loop you will find that it is desirable to jump out of the loop if NiMvJiUiZkc2IyIiIyZGJTYjIiIi to as many significant digits as Maple is keeping (typically 10; see online help about Digits) because this will keep you from dividing by zero. This is hard to do with while, but fortunately there is a way to jump out using the break command. Here is a stupid example: suppose you were looping from 1 to 100 but you wanted to jump out when i was 20. You would usefor i from 1 to 100 do if i=20 then break end if;end do;Notice that after the jump, i has the value it had when the jump occurred.i;You will want to use this in the secant method procedure you are developing here. To test your use of it in your loop, keep repeating the calculation until the value of f2 is less than 1e-10 by using while; this should make division by zero happen so you will need the break command to protect your loop.You may discover, however, that getting Maple to divide by zero in this problem is difficult. If it won't cooperate, don't worry about it. The break statement is still a good idea in general, though, so I want you to practice putting it in.Go to top of section<Text-field bookmark="Procedures: putting loops and logic to work (top)" layout="_pstyle6" style="_pstyle6">Procedures: putting loops and logic to work</Text-field>DebuggingWell, you have probably noticed that loops and logic are messy. They take up a lot of space in your worksheet and to do them over and over you have to keep moving the cursor around. Maple has provided a way to put complicated stuff like this into something that works like a function so you can just pass values into it and get answers back out. The structure that does this is the procedure which uses the proc comm, and you have already encountered some of these in earlier sections. Now you get to learn how to write your own. Here is the basic structure.restart;Assign the procedure to a name and define an argument list for itf:=proc(x,y)Declare the names of local variables, those only used within the procedure local a,b,z;Declare the names of global variables, those from outside to be used inside global d;Now come the Maple statements that get the job done. In this case we use local a and b, global d, and passed in x and y to compute function value z, which is local. So how does Maple know what value to give us back? The returned value is always the last thing computed in the procedure.a:=3.;b:=17.; z:=a*b*x*y*d; # last valueend;Give the global variable d a valued:=31.;f(1,2);To illustrate how a procedure works, here is one that simply evaluates the cosine of an angle in degrees. restart;cosdeg:=proc(theta) local phi,answer; phi:=theta*Pi/180.; answer:=cos(phi);end;Now test ityy:=cosdeg(45.);Because a procedure is a program that you write, it will usually fail. (I am not trying to insult you. This sentence is also true: "When scientists and engineers write procedures, they usually fail.") And when it fails you will need to see what it is doing to find out how to fix it. The Maple command to tell a procedure to reveal to you its inner workings is the command trace. To debug the procedure above usetrace(cosdeg);then execute it like thiscosdeg(45);And then when it is working right and you don't want to see all of this stuff every time you use it typeuntrace(cosdeg);Problem 8.8Notice that you didn't get a number out of this cosdeg procedure. Fix it so that it gives a floating point number back. Make sure that your fix takes place inside the procedure and not in the call you make to it. --------------------------------------------------------------------------------If you look at how cosdeg is used you can see that a procedure is used just like a function. But because it is a self-contained little program it can be a really complicated function. And this is, in fact, the usual reason for writing a procedure. You have to be careful, though, because functions defined this way may not be compatible with other Maple commands like plot, int, sum, dsolve, etc. In addition, procedures are usually slower than the built-in Maple commands.Problem 8.9Write a procedure that computes the cubic B-spline function described in Problem 8.1. Plot your procedure (function) from -3..3. Note: if you are going to plot the result of a procedure the answer has to be returned as the last result, and the only arguments that can be passed in are the appropriate independent variables, i.e. for a one-dimensional function you would use B:=proc(x), for 2-d use C:=proc(x,y), etc. When you plot output from a procedure, you can treat it like a function using the plot(f(x),x=a..b) command, or you can use Maple's operator notation with the name of x left out: plot(B,-3..3).--------------------------------------------------------------------------------Problem 8.10You can also use procedures to perform a task that you want to do a whole bunch of times while you change some parameter. Write a procedure that takes as inputs the parameter Nterms and the angle NiMlJnRoZXRhRw== and returns the value of the Fourier series NiMtJSJmRzYjJSZ0aGV0YUc= given in Problem 8.5. Use Maple's sum command inside the procedure and keep terms up to n=Nterms. Then make three plots of NiMtJSJmRzYjJSZ0aGV0YUc= vs. NiMlJnRoZXRhRw== with Nterms=10, Nterms=100, and Nterms=400. This will give you an instructive way of seeing how the Fourier representation improves as you keep more terms. Because your procedure has more than one input variable, you will need to use a plot command of form plot(f(Nterms,theta),theta=0..Pi) .--------------------------------------------------------------------------------Problem 8.11Write a procedure that takes as input the parameter NiMlImFH , then solves the differential equationNiMvLSUlZGlmZkc2JC0lImZHNiMlInhHLSUiJEc2JEYqIiIjLCQqJEYnIiIkISIi with NiMvLSUiZkc2IyIiIUYn and NiMvLS0lJWRpZmZHNiQlImZHJSJ4RzYjIiIhJSJhRw== . Let the procedure return NiMtJSJmRzYjIiIi as a single number (you will likely need to use trace to get this right). Then try different values of NiMlImFH and see if you can find at least 2 values of NiMlImFH (other than 0) for which NiMvLSUiZkc2IyIiIiIiIQ== . Find these 2 values of NiMlImFH accurate to 5 significant figures.This is a pretty hard problem, so here are some hints. You will want to put dsolve(...type=numeric) into the procedure and have it return a number. But the output from the numerical version of dsolve is a set of equations, like thisrestart;f:=dsolve({diff(y(t),t$2)=-y(t),y(0)=2,D(y)(0)=0},{y(t)},type=numeric);g:=f(1);When we encountered this before we used the assign statement to get the number assigned to y(t), like thisassign(g);This failed because the derivative symbol is not a valid variable to assign to. So now you have two choices. (i) Change the second order ode into a coupled set of ode's and use the assign statement to extract the number or (ii) learn how to use Maple's op and rhs commands to extract the number. The command op picks out elements of almost anything Maple generates: expressions, functions, lists, sets, etc. Go back up to the restart above, execute the restart,the dsolve, and the g:=f(1); but do not execute the assign statement. Then in the statement below change the 1 to 2 and then to 3, and see what you get backop(1,g);The number f(1) is really close now; all we have to do is get it out of the equation, and that's just what rhs does: it extracts the right-hand side of an equation. So see what happens when you do thisrhs(op(2,g));You will need to use this construction inside your procedure so that it can return a number.--------------------------------------------------------------------------------Problem 8.12Write a procedure that changes the Pnm(x) Associated Legendre Function discussed in Problem 3.4 into a real function that returns a number for any valid choice of n and m, including m=0. This means that you have to solve the "differentiate zero times" problem discussed in Chapter 3. Associated Legendre functions Test your procedure sufficiently that you know it is working correctly. (a) First write the procedure so that it returns an expression in x, then (b) change it so it returns a floating point number.Go to top of section<Text-field layout="_pstyle6" style="_pstyle6">Example: plotting results from fsolve</Text-field>DebuggingHere is something that it is a little technical, but I run up against it all the time, so maybe you will too. Suppose you have a hard equation to solve that has a variable parameter NiMlImtH in it, like thisNiMvLSUkY29zRzYjJSJ4RyomJSJrRyIiIkYnRio=where NiMlImtH varies from 0 up to 20. I want to build a function NiMtJSJGRzYjJSJrRw== that returns the solution NiMlInhH of this equation for any NiMlImtH that I give it, and then I want to plot this function NiMtJSJGRzYjJSJrRw== . The only way I know to do this is to write a procedure. After the Maple commands inside the procedure below have executed, F is assigned the last result calculated in the procedure, in this case the value of x from the fsolve, which is just what we want F to be.) Study the procedure below, then execute the plot.restart;Declare F to be a procedure F:=proc(k)Declare variables that will only be used inside the procedurelocal s,x;Use fsolve to solve the equation using the value of k passed in through proc(k)s:=fsolve(cos(x)-k*x,x,0..2);Returnend;Try a few valuesF(1);F(2);Make a plot (use operator notation--the form plot(F(k),k=0..20) doesn't work)plot(F,0..20);Problem 8.13Consider the polynomial NiMsLCokJSJ4RyIiJSIiIiomJSJhR0YnKiRGJSIiJEYnRicqJEYlIiIjRidGJUYnRidGJw== with NiMlImFH a variable parameter. You can give this polynomial to fsolve and it will find all four roots as long as NiMlImFH has a value.a:=2.5;P:=x^4+a*x^3+x^2+x+1;s:=fsolve(P,x,complex);If you want to select one of the roots, say the second one, you just do thiss[2];Copy the procedure at the start of this section and modify it to plot the second root of this polynomial as NiMlImFH varies between 2 and 10. (Just put the Maple code in this problem into the procedure.) Note: procedures return the last value calculated, so in your new procedure, right after the s:=fsolve(....) you will need the command s[2]; to return the value of the second root.---------------------------------------------------------------------Problem 8.14(a) Write a procedure that returns the function NiMtJSJ0RzYjJSJ4Rw== defined as the solution of the implicit equationNiMvJSJ0RyooJSJ4RyIiIi0lJGV4cEc2IywkRiQhIiJGJywmRidGJyokRiQiIiNGJ0Ys . In the procedure use Maple's fsolve command to do the solve and when you have built it, plot t(x) on the range x=0..10.(b) Do the same thing as in (a), but this time use the function notation to define NiMtJSJ0RzYjJSJ4Rw== , i.e., t:=x->fsolve(...). Are the two ways of doing this equivalent?(c) Write either a function or a procedure that will give you the derivative of this implicitly defined function, i.e., get a Maple function or procedure for NiMtJSVkaWZmRzYkLSUidEc2IyUieEdGKQ== . Warning: do not just take the NiMlInhH -derivative of the equation above treating NiMlInRH like a constant--NiMlInRH is really NiMtJSJ0RzYjJSJ4Rw== on both sides of the equation. So rewrite the equation with NiMlInRH replaced by NiMtJSJ0RzYjJSJ4Rw== , then use diff to differentiate the whole equation with respect to NiMlInhH . Then have Maple solve for NiMtJSVkaWZmRzYkLSUidEc2IyUieEdGKQ== and evaluate the resulting expression by modifying your procedure for NiMtJSJ0RzYjJSJ4Rw== . When you have built this procedure, use it to plot NiMtJSVkaWZmRzYkLSUidEc2IyUieEdGKQ== on the range 0..10 and verify visually that it looks like the derivative of the function you plotted in part (a).--------------------------------------------------------------------------------Go to top of chapter<Text-field bookmark="Symbolic algebra (chapter top)" layout="_pstyle5" style="_pstyle5">Chapter 9: Symbolic algebra</Text-field>DebuggingThis is what Maple was actually designed to do: symbolic mathematics. We have already seen some of its ability to do this as we have taken derivatives, integrated, and solved differential equations. I have placed this material in the last chapter because it's almost an art form and you need to be pretty comfortable with Maple before you tackle it. You can use this chapter as a source for what to try when Maple gives you answers that are correct, but not in the form you want. It may take many months to get good at this, but it is worth the effort because Maple will not make minus sign mistakes or lose factors of 2. The trick, however, is to coax it to combine precision with a sense of style and good taste. This is done via a partnership: Maple supplies the precision; you supply the style and taste. I will give you just enough of an introduction to get you started. After that it's up to you and online help. copy and paste:Maple almost never gives you exactly what you want, so you will still need to do some algebra by hand. But the editing capability of Maple using the mouse, copy (ctrl-c) and paste (ctrl-v) often makes it possible for you to stay in the Maple worksheet and do algebra by hand. expand: Here are some examples of what expand does.expand((x-1)^2*(x+2));expand(cos(x+y));expand(exp(x-y));assume(x,real);expand(ln(x/(1+x^2)));expand(tan(x-y));This command is half of Maple's all-purpose algebra simplification duo--simplify(expand(%));. Always try this combination first when you get an algebraic expression that needs help.combine:This is the flip side of expand. The two of them together know some trig identities, but not as many as they should.restart;expand(cos(x+y));combine(%);expand(exp(x-y));combine(%);assume(x,real);expand(ln(x/(1+x^2)));combine(%);restart;expand(tan(x-y));combine(%);Hmm---and sometimes it doesn't work. Let's try expand and simplify and see what happensexpand(%);simplify(%);Well, sometimes you just can't get where you want to go.simplify: Maple tries to read your mind with this command, but doesn't always succeed. You usually have to be creative with the other commands discussed here to get exactly what you want. A good thing to try is a combination of expand, simplify, and combine. And don't forget that you can change the forms of expressions by using copy and paste.simplify(cos(x)^2+sin(x)^2);simplify((x^2-2*x+1)/(x-1));simplify(cos(x)^2-sin(x)^2);simplify(2*sin(x)*cos(x),trig);combine(cos(x)^2-sin(x)^2);combine(2*sin(x)*cos(x),trig);So you will have to be creative and play around with these commands to master them. simplify with side-relations:You can give simplify some extra help by using side-relations (see ?simplify/siderels). The idea is to tell Maple what identities you want to use to put your expression into the form you want. For example, suppose you wanted to put the expression NiMsKCokLSUkY29zRzYjJSJ4RyIiJSIiIiIiJCEiIiokRiUiIiNGKg== into a new form involving NiMqJiIiIyIiIiUieEdGJQ== instead of NiMlInhH by using the identity NiMvKiQtJSRjb3NHNiMlInhHIiIjKiYsJiIiIkYsLUYmNiMqJkYpRixGKEYsRixGLEYpISIi . You could do thisf:=cos(x)^4-3+cos(x)^2;simplify(f,{cos(x)^2 = (1+cos(2*x))/2});(Notice that the side-relations must be inside curly brackets.) You may think that this is just a substitution (see the subs command, discussed below), but to Maple it isn't the same:subs(cos(x)^2=(1+cos(2*x))/2,f);Using side-relations is like an intelligent substitution where Maple tries to change everything it can using the identity you gave it. The side-relations go in curly brackets, as shown in the example above, and several identities can be specified at once using the syntax simplify(expression,{side1,side2,side3});f:=cos(x)^4+1-cos(x)^2-sin(x)^2+3*sin(x)^6;s1:=cos(x)^2=(1+cos(2*x))/2;s2:=sin(x)^2=(1-cos(2*x))/2;simplify(f,{s1,s2});sort: Sort puts expressions, especially polynomials, in order from high powers down to lowsort(2-3*x^2-x+x^4);sort(1-cos(x)^2+cos(x)); factor: Factor tries to write polynomials as products of termsfactor(x^2-6*x+8); collect: This is sort of a half-way factor command. Perhaps you see a common factor within a larger expression and you would like to collect together all terms that contain it, like the NiMtJSNsbkc2IyUieUc= term below. Then do thisF:=x*ln(y)-5*x + 3*ln(y)+5*exp(y);collect(F,ln(y));And if you want to collect more than one factor at once, give collect a list of factors, like thisF:=a*x*sin(y)+b*a*x/cos(y);collect(F,[x,a]);solve: We have seen this before; it solves an equation for the specified variable. If the variable to solve for is obvious because there is only one, you don't have to give it; and if you just give solve an expression without an = sign, it solves it by setting it equal to zero.solve(x^2-6*x+8);solve(ln(y/x)=3,y);solve(ln(y/x)=3,x);solve(1-tan(x)^2=-2,x);Can you spot the difference between this next one and the previous one?solve(1-tan(x)^2=-2.,x);If you give Maple an equation that has no solution, it just hands it back to you, or gives you nothing.plot(1-tan(x)^2,x=-Pi..Pi,-3..3);solve(1-tan(x)^2=2,x);As you can see from the plot the function NiMsJiIiIkYkKiQtJSR0YW5HNiMlInhHIiIjISIi can never be 2, so Maple can't solve the equation. normal: The normal form for rational functions is to have a common denominatornormal(1/x + 1/(x+1));And what happens if you try to expand this result?expand(%);It's expanded, but not back to where it came from. To get it back to where it started you have to be more specific and use the convert command, which is coming up. numer and denom: Maple will let you refer directly to the numerator or denominator of a fractional expression, like thisdenom((1+x)/(3-x^2));numer((1+x)/(3-x^2));but with perhaps not exactly the form you expected. You actually have much more control over parts of expressions like this by using the Maple editor's copy and paste ability:(1+x)/(3-x^2);Use the mouse to highlight the numerator of the expression above, copy it (ctrl-c), then paste (ctrl-v) in this execution groupop:This command picks out pieces of expressions. Its syntax is op(n,expr), which picks out the nth piece of the expression expr. Just experiment with it whenever you need to take something apart.kk:=(1+x^2)/(sin(x)+tan(x))*cosh(x)/(1+tanh(x));op(1,kk);op(2,kk);op(3,kk);op(4,kk); subs: This is the substitute-one-variable-for-another commandEq1:=cos(x)^2-5*cos(x)+1;subs(cos(x)=y,Eq1);Eq2:=exp(2*x)-t^2=x*t;subs(x=xi,t=tau,Eq2);As you use subs you may become frustrated because it seems stupid, like this:f:=x^4-3*x^2+5;subs(x^2=y,f);Why couldn't it recognize that NiMvKiQlInhHIiIlKiQlInlHIiIj ? Well, subs is just very literal, not algebraic. There is, however, an algebraic form of subs called algsubs which is much smarter. You will probably have lots better luck with it because it recognizes that your NiMqJCUieEciIiM=substitution was really an NiMlInhH substitution.algsubs(x^2=y,f); convert: Finally, there is the convert command, which is actually many commands depending on what kind of conversion you want to do. Use ?convert to see all of the possibilities. When you get stuck and the commands discussed above don't do the job, try looking through the list of convert options in online help. Here are a few of what I think are useful or interesting options.Here is the start of the show: convert a RootOf answer to one with square roots, cube roots, etc.eq1:=x=a*y;eq2:=x^2=b*y^2+c;s:=solve({eq1,eq2},{x,y});convert(s,radical);You may notice that the expressions in RootOf are quadratics, so there should have been two solutions. You can find all of the solutions this way:convert(s,radical,1);convert(s,radical,2);where the number at the end of the command tells Maple which root you want to see.Convert a Taylor series into a polynomial with the polynom option h:=taylor(sqrt(1-x^2),x,6);h2:=convert(h,polynom);Put rational functions in partial fraction form with the parfrac optionconvert((2*x+1)/(x*(x+1)),parfrac,x);Convert rational functions to continued fraction form with confracconvert((2*x+1)/(x*(x+1)),confrac,x);Express functions in exponential form with expconvert(sin(x),exp,x);convert(sinh(x),exp,x);Convert expressions with sines and cosines into tangent form with tanrestart;a:=convert((2+cos(x)^2)/(2-sin(x)^2),tan);a:=simplify(a);Convert expressions with tangents into sine-cosine form with sincosconvert(a,sincos);simplify(%);Convert English units to metric ones with convert(,metric)convert(1.*acre,metric);convert(1.*MPH,metric);To see what English quantities can be converted to metric try?convert/metricConvert expressions containing abs, Heaviside, signum, etc, into piecewise functionsF:=abs(x);F:=convert(F,piecewise,x);For instance, convert will give you a nice definition of Maple's signum function G:=signum(x);G:=convert(G,piecewise,x);Convert complex expressions to polar formconvert(x+I*y,polar);Now this is probably not exactly what you had in mind. Fortunately Maple's map command can put it in a more useful form. The command map tells Maple to apply the procedure in the first slot of map(a,b) to each of the operands of the object in the second slot, in this case the magnitude and argument expressions, The conversion procedure is evalc, so we would do thismap(evalc,%);Map is quite powerful; see ?map for details. ratpoly:The ratpoly option converts a series into a rational function. This is often a very convenient and compact way to get an approximate expression for a complicated function. The syntax is convert(series,ratpoly,numdeg,dendeg) where numdeg is the order of the numerator polynomial and where dendeg is the order of the denominator polynomial. These two arguments are optional. If you don't specify them convert will just choose the appropriate orders for the number of terms in your series. Here are a few examples with illustrative plots using taylor to generate the series.Approximate the sine function. Compare the exact result (red) with the rational aproximation (blue).sinap:=convert(taylor(sin(x),x=0,10),ratpoly);plot([sin(x),sinap],x=0..6,color=[red,navy]);tanap:=convert(taylor(tan(x),x=0,10),ratpoly);plot([tan(x),tanap],x=0..5,-10..10,color=[red,navy]);I know this may seem a little strange--why would I want to build a rational function approximation to a function I already have? Well, suppose you had to have Bessel functions in a C or Java program. You could use Maple to get a simple approximation to it using ratpoly, then use this approximation in your other program. (Be careful that you don't use the approximation outside of the domain where it works.)J0ap:=convert(taylor(BesselJ(0,x),x=0,10),ratpoly);plot([BesselJ(0,x),J0ap],x=0..5,color=[red,navy]);Or even better, plot the difference between the exact function and the approximation so you know over what range the approximation is sufficiently good.plot(BesselJ(0,x)-J0ap,x=0..5,-.001..0.001);Strategy: Because Maple will not do exactly what you want it to do you will get very frustrated. Perhaps the best way to avoid ulcers as you use it is not to expect too much. In complicated problems you will need to do a lot of pencil-and-paper work to guide the calculation, but you can use Maple to do the details. Maple does lots better on small chunks of algebra than it does on big ones, so feed it bite-size pieces, then find creative ways of combining the pieces on your paper. And when you find what looks like a promising approach, use Maple to implement it. Finally, when you have used Maple, your head, and your hand to get a final beautifully simplified answer, plot it against the original ugly form to make sure that they are really the same.Sometimes you will need to do algebra on matrices, and you will discover that it is a little tricky. Here is a section on how to handle problems like this.<Text-field bookmark="Matrices and arrays of expressions" layout="_pstyle6" style="_pstyle6">Algebra on matrices filled with expressions</Text-field>Maple will let you do all of the things discussed in the section above to expressions contained inside matrices and arrays, but you have to work a little harder. Suppose we have the following matrix of expressionsrestart;with(LinearAlgebra):F:=Matrix([[x^2+x*y^2,1/x+y/x],[(x-y)*(x+y),x^2+2*x*y+y^2]]);and suppose we want to change its form using the algebra commands discussed in the previous section. We might try to substitute q for x in each term of the matrix using subssubs(x=q,F);which is exactly what we wanted. Now let's try expanding each term using expandexpand(F);Why does subs work and not expand? I don't know, but for algebra commands like expand that fail like this, the map command will do the job. This would be a good time to look up map, but here is basically how it works. The command map(command,symbol) applies the first argument (command) to each part of the expression(s) in the second argument (each term in the matrix in our case).map(expand,F);map(factor,F);etc. With the help of map you should be able to do about anything you want to matrices and vectors containing expressions.Go to top of sectionWell, this is a very brief introduction to a very large subject. You will only get good at algebra in Maple by doing your homework with it in spite of the pain and frustration. Here is an example of how it's done, followed by some problems for you to practice on. Worked example:Here's an example from wave physics. Carefully step through it watching what happens, then proceed to the problems below. The dispersion relation for electromagnetic waves in the ionosphere is NiMvKiQlJm9tZWdhRyIiIywmKiQmRiU2IyUicEdGJiIiIiomJSJrR0YmJSJjR0YmRiw= .I want to find both the phase velocity NiMvJiUidkc2IyUicEcqJiUmb21lZ2FHIiIiJSJrRyEiIg== and the group velocity NiMvJiUidkc2IyUiZ0ctJSVkaWZmRzYkJSZvbWVnYUclImtH as functions of NiMlJm9tZWdhRw== . So first we solve for NiMlJm9tZWdhRw== :restart:Eq:=omega^2=omega[p]^2 + k^2*c^2;solve(Eq,omega);Hmm, no answer--that didn't work well at all. I'm going to show you what went wrong now, and it's very important. I was seduced by Maple's beautiful typesetting capability to write the plasma frequency NiMmJSZvbWVnYUc2IyUicEc= with a subscript, the way it would be done in a textbook. Do not ever use this for anything but comments in your worksheet. When Maple got to omega[p] in the solve it got very confused because it has been asked to find the pth element of the array omega, but omega isn't an array and p isn't an integer. When I code I always use non-subscripted, but suggestive, variables like wp:restart:Eq:=omega^2=wp^2 + k^2*c^2;s:=solve(Eq,omega);I just want the first one and will assign to the name ww:=s[1];Ok, getting the phase velocity is now not too hard:vp:=w/k;s:=solve(Eq,k);Choose the positive one and assign it to kk:=s[1];Now look at the expression for vp with this form for kvp;assume(omega>0);vp:=simplify(vp);Now try the group velocityvg:=diff(w,k);Now what went wrong? Well, we did something bad that you will be tempted to do often, but which you should not do. At the beginning we had a function NiMtJSZvbWVnYUc2IyUia0c= , but now we have solved for NiMlImtH and assigned a formula to it, so NiMtJSZvbWVnYUc2IyUia0c= is now ruined:w;What we should have done is assigned the solution for NiMtJSJrRzYjJSZvbWVnYUc= to another variable, say kk. So let's do everything all over againrestart:Eq:=omega^2=wp^2 + k^2*c^2;s:=solve(Eq,omega);I just want the first one and will assign to the name ww:=s[1];Ok, getting the phase velocity is not too hard:vp:=w/k;s:=solve(Eq,k);Choose the positive one and assign it to kkkk:=s[1];Now look at the expression for vp with this form for k by substituting kk for kvp:=subs(k=kk,vp);Maple can't simplify the square root in the top unless it knows something about NiMlJm9tZWdhRw== , in this case that it is positiveassume(omega>0);vp:=simplify(vp);Now find the group velocityvg:=diff(w,k);Substitute for k againvg:=subs(k=kk,vg);vg:=simplify(vg);and we are finished.Problem 9.1(a) Express the function NiMtJSRjb3NHNiMqJiIjNSIiIiUmdGhldGFHRig= as a polynomial in NiMtJSRjb3NHNiMlJnRoZXRhRw==(b) Express the function NiMqJC0lJGNvc0c2IyUmdGhldGFHIiIk as a sum of terms containing NiMtJSRjb3NHNiMlJnRoZXRhRw== and NiMtJSRjb3NHNiMqJiIiJCIiIiUmdGhldGFHRig= .(c) Coax Maple into giving you the half angle identities for NiMtJSRjb3NHNiMqJiUmdGhldGFHIiIiIiIjISIi , NiMtJSRzaW5HNiMqJiUmdGhldGFHIiIiIiIjISIi , and NiMtJSR0YW5HNiMqJiUmdGhldGFHIiIiIiIjISIi . (Try both expand and combine on each of these expressions and their squares.)----------------------------------------------------------------------------Problem 9.2(This problem is annoying, but in a good way. As you use Maple to do your physis homework, you will spend a lot of time trying to make Maple give you an answer is a certain form. Many times this is virtually impossible, so you need to learn how to use Maple to assist you in doing pencil and paper algebra instead of wasting your time trying to beat Maple into submission.)The formula for the effective resistance of a certain combination of resistors is given byNiMvKiYiIiJGJSUiUkchIiIsKComRiVGJSwmJkYmNiNGJUYlKiZGJUYlLCYqJkYlRiUmRiY2IyIiI0YnRiUqJkYlRiUmRiY2IyIiJEYnRiVGJ0YlRidGJSomRiVGJSZGJjYjIiIlRidGJSomRiVGJSZGJjYjIiImRidGJQ==Workon this with Maple until you can get a semi-nice formula for NiMlIlJH with NiMqJiUjUjRHIiIiJSNSNUdGJQ== in the numerator and a sum of terms in the denominator, one of which is a fraction with denominator NiMsKComJSNSMUciIiIlI1IyR0YmRiYqJkYlRiYlI1IzR0YmRiYqJkYnRiZGKUYmRiY= and with a factor of NiMqJiUjUjRHIiIiJSNSNUdGJQ== in the numerator, times another factor, and the other two added terms in the denominator being NiMsJiUjUjRHIiIiJSNSNUdGJQ== . It will be difficult to make Maple put it in exactly the form you want, so use Maple as a tool to help you avoid mistakes as you do this problem with pencil and paper. This is also an exercise in the creative use of copy and paste as a Maple algebra tool.----------------------------------------------------------------------------Problem 9.3In your first physics course you studied collisions between two particles. Let's do a simple case in which the two particles are constrained to move along the x-axis. The two particles have masses NiMmJSJtRzYjIiIi and NiMmJSJtRzYjIiIj and initial velocities NiMmJSJ2RzYjKiYiIiJGJyUiaUdGJw== and NiMmJSJ2RzYjKiYiIiMiIiIlImlHRig= with the fast particle behind the slow one so they can collide. Find the final velocities NiMmJSJ2RzYjKiYiIiJGJyUiZkdGJw== and NiMmJSJ2RzYjKiYiIiMiIiIlImZHRig= . (a) Elastic collisons:The conditions that allow this problem to be solved are conservation of momentum and energy: NiMvLCYqJiYlIm1HNiMiIiJGKSYlInZHNiMqJkYpRiklImlHRilGKUYpKiYmRic2IyIiI0YpJkYrNiMqJkYyRilGLkYpRilGKSwmKiZGJkYpJkYrNiMqJkYpRiklImZHRilGKUYpKiZGMEYpJkYrNiMqJkYyRilGO0YpRilGKQ== and NiMvLCYqJiYlIm1HNiMiIiJGKSokJiUidkc2IyomRilGKSUiaUdGKSIiI0YpRikqJiZGJzYjRjBGKSokJkYsNiMqJkYwRilGL0YpRjBGKUYpLCYqJkYmRikqJCZGLDYjKiZGKUYpJSJmR0YpRjBGKUYpKiZGMkYpKiQmRiw2IyomRjBGKUY+RilGMEYpRik= , where the NiMqJiIiIkYkIiIjISIi has been cancelled out of the kinetic energy equation. Coax Maple into solving these two equations for the final velocities. You will get two solutions; interpret each set physically. Then specialize to the cases (i) NiMvJiUibUc2IyIiIiZGJTYjIiIj , (ii) NiMmJSJtRzYjIiIj much larger than NiMmJSJtRzYjIiIi and NiMyJiUidkc2IyomIiIjIiIiJSJpR0YpJkYlNiMqJkYpRilGKkYp so that the light particle comes up from behind and collides with the massive particle, and (iii) NiMmJSJtRzYjIiIi much larger than NiMmJSJtRzYjIiIj and NiMyJiUidkc2IyomIiIjIiIiJSJpR0YpJkYlNiMqJkYpRilGKkYp so that the massive particle comes up from behind and whacks the light particle. Does each case make physical sense? Talk about it with someone until you understand each case intuitively.----------------------------------------------------------------------------Problem 9.4In freshman physics you also studied projectile motion with gravity obtaining the following equations describing the horizontal and vertical motion:NiMvLSUieEc2IyUidEcsJiZGJTYjIiIhIiIiKiYmJSJ2RzYjJSN4b0dGLEYnRixGLA== and NiMvLSUieUc2IyUidEcsKCZGJTYjIiIhIiIiKiYmJSJ2RzYjJSN5b0dGLEYnRixGLCooJSJnR0YsKiRGJyIiI0YsRjUhIiJGNg== . Suppose that NiMmJSJ4RzYjIiIh and NiMmJSJ5RzYjIiIh are given as well as the initial speed NiMmJSJ2RzYjIiIh and the angle NiMlJnRoZXRhRw== that the initial velocity makes with the horizontal plane. Also suppose that the elevation of the region in which the projectile will fall NiMmJSJ5RzYjJSJmRw== is known. Find a formula for the horizontal range NiMmJSJ4RzYjJSJyRw== and for the "hang-time" of the projectile (the time it spends in the air). Do not be satisfied with some mess involving RootOf--get workable formulas. And if you get two solutions, figure out which one is the physically relevant one. When you get final expressions for the horizontal range and the hang-time, choose NiMvJiUieEc2IyIiIUYn , NiMvJiUieUc2IyIiIUYn , NiMvJSJnRy0lJkZsb2F0RzYkIiMpKiEiIg== m/NiMqJCUic0ciIiM= , and NiMvJiUidkc2IyIiISIjXQ== m/s and make plots of hang time and range as functions of NiMlJnRoZXRhRw== if the elevation of the target region is NiMvJiUieUc2IyUiZkcsJComIiQrIyIiIiUibUdGKyEiIg== (shooting down into a valley). Use NiMlJnRoZXRhRw== in the range NiM7LCQqJiUjUGlHIiIiIiIjISIiRilGJQ== (straight down to straight up). Carefully examine the graphs to be sure they make physical sense. In particular, why doesn't 45 degrees give the best range in this case?----------------------------------------------------------------------------Problem 9.5The formula relating the focal length NiMlImZH , the object distance NiMlIm9H , and the image distance NiMlImlH for a focusing lens or mirror is NiMvLCYqJiIiIkYmJSJpRyEiIkYmKiZGJkYmJSJvR0YoRiYqJkYmRiYlImZHRig= . Given NiMlImZH and NiMlIm9H , this equation can be solved for the distance to the image. Assume that NiMvJSJmRyIiIg== m (about right for the curved mirror in the ESC lobby) and make a plot of NiMlImlH for NiMlIm9H ranging from 15 m to 0.5m, about the range that is possible in the lobby of the ESC. When NiMlImlH becomes negative it means that the image is virtual (meaning that it's as if there were an image behind the mirror), and because your eye has a lens in it you can see virtual images, and they appear to be at the place given by this formula. Look at your graph, then go down to the lobby and see if what you see is what you got. A good movable object to use to define NiMlIm9H is yourself. In particular, think about what you should see if you let your face be the object and place it so that the object and the image are at the same place. What you see in the lobby will not correspond in an obvious way with your graph because your eye has a lens in it too. This means, among other things, that you can see images at infinity! If you have a partner to argue with, this lobby exercise could be both fun and instructive. ----------------------------------------------------------------------------Problem 9.6Here is a thermodynamics problem that is a pain to do by hand, but Maple takes it right in stride. Suppose you have a quantity of water of mass NiMmJSJNRzYjJSJ3Rw== with specific heat NiMvJiUiY0c2IyUid0ciJSY9JQ== J/kg/K and a quantity of ice of mass NiMmJSJNRzYjJSJpRw== and specific heat NiMvJiUiY0c2IyUiaUciJSs/ J/kg/K. The specific heat of transformation is NiMvJSJMRyInK0lM J/kg. If the water starts out at temperature NiMmJSJURzYjJSJ3Rw== and the ice starts out at temperature NiMmJSJURzYjJSJpRw== , and if the freezing point is at temperature NiMvJiUiVEc2IyIiIUYn (we in are degrees celsius) do the following.(a) Assuming that all of the ice melts (i) find a formula for the final temperature NiMmJSJURzYjJSJmRw== of the combined mass of water and (ii) also find a formula for the mass of ice such that the final water temperature is To (the final mixture has just barely melted). In case you have forgotten, or never studied, heat, here's some help. The heat lost by the water is given by the formulaNiMvJiUiUUc2IyUid0cqKCYlIk1HRiYiIiImJSJjR0YmRissJiYlIlRHRiZGKyZGMDYjJSJmRyEiIkYr and the heat gained by the ice that melts is given by the formulaNiMvJiUiUUc2IyUiaUcsKCooJiUiTUdGJiIiIiYlImNHRiZGLCwmJiUiVEc2IyIiIUYsJkYxRiYhIiJGLEYsKiZGKkYsJSJMR0YsRiwqKEYqRiwmRi42IyUid0dGLCwmJkYxNiMlImZHRixGMEY1RixGLA==Just use conservation of energy and the rest is not too hard. To get definite numbers out, use NiMvJiUiTUc2IyUid0ciIiI= kg. (Notice that part (ii) is quite practical: given water at 20 C and ice at -10 C, how much ice does it take to bring 1 kg of water to be freezing cold?)(b) Assuming that all of the water freezes completely and then cools down below NiMmJSJURzYjIiIh (i) find a formula for the final temperature of the combined mass of ice and (ii) also find a formula for the mass of ice such that the final ice temperature is To (the final mixture is just barely frozen). Similar formulas to those used in part (a) also apply here, except this time it is the ice formula that is simple (it just warms up as ice from NiMmJSJURzYjJSJpRw== to NiMmJSJURzYjJSJmRw== , while the water cools to NiMmJSJURzYjIiIh , then freezes into ice, then cools down further as ice to NiMmJSJURzYjJSJmRw== . Another practical question: How much ice would you need at -10 C to just barely freeze 1 kg of water at 20 C? The answer is impressive and shows that a lot of heat has to be removed to freeze water.----------------------------------------------------------------------------Problem 9.7Light is incident from transparent region a into transparent region b, which in turn transmits light into region c, as shown below. The indices of refraction in each region are denoted by NiMmJSJuRzYjJSJhRw== , NiMmJSJuRzYjJSJiRw== , and NiMmJSJuRzYjJSJjRw== . restart;with(plots):with(plottools):l2:=listplot([[0,-2],[0,2]]):l3:=listplot([[1,-2],[1,2]]):t1:=textplot([-.5,.5,"a"]):t2:=textplot([.5,.5,"b"]):t3:=textplot([1.5,.5,"c"]):l4:=plot(.5*sin(20*(x+1))-.5,x=-1..-.2):a1:=arrow([-.7,-1.3],[-.4,-1.3],.05,.2,.2):plots[display]([t1,l2,t2,l3,t3,l4,a1],axes=none,thickness=3,view=[-2..2,-2..3],font=[HELVETICA,14]); Maxwell's equations tell us that for normal incidence, which we assume we have here, the ratios between the incident wave in region 1 and the reflected wave in region and the transmitted wave in region 2 are given by NiMvKiYmJSJFRzYjJSJyRyIiIiZGJjYjRikhIiIqJiwmJiUibkdGK0YpJkYwNiMiIiNGLEYpLCZGL0YpRjFGKUYs and NiMvKiYmJSJFRzYjJSJ0RyIiIiZGJjYjRikhIiIqKCIiI0YpJiUibkdGK0YpLCZGL0YpJkYwNiNGLkYpRiw= . For convenience we will call these ratios NiMmJSJSRzYjIiM3 and NiMmJSJURzYjIiM3 , respectively. Your job is to follow all of the successive transmissions and reflections in the figure above and arrive at the final ratio of the light reflected back into region a as a function of the three indices of refraction, the thickness NiMlImhH of region b, and the wavenumber NiMmJSJrRzYjJSJiRw== of the light in region b. To do this follow the steps outlined below.(a) Note that the first reflection and transmission ratios are simply NiMmJSJSRzYjJSNhYkc= and NiMmJSJURzYjJSNhYkc= . (Don't do anything except make sure you understand this statement because there are a lot more just like it coming up.)(b) Now think about what happens to the light transmitted into region b. It first reflects from region c, is phase shifted by the complex phase factor NiMtJSRleHBHNiMqKiIiIyIiIiUiaUdGKCYlImtHNiMlImJHRiglImhHRig= due to the round trip through b from a to c and back, then is transmitted back into a. Show that the factor for this whole process, including the first transmission, is NiMqKiYlIlRHNiMlI2FiRyIiIi0lJGV4cEc2IyoqIiIjRiglImlHRigmJSJrRzYjJSJiR0YoJSJoR0YoRigmJSJSRzYjJSNiY0dGKCZGJTYjJSNiYUdGKA== . (This is not too difficult, but be patient--hard stuff is coming up.)(c) Now show that each successive multiple reflection ratio is given by NiMqLCYlIlRHNiMlI2FiRyIiIiYlIlJHNiMlI2JjR0YoJkYlNiMlI2JhR0YoLSUkZXhwRzYjKioiIiNGKCUiaUdGKCYlImtHNiMlImJHRiglImhHRihGKCkqKEYwRigmRipGLkYoRilGKCUibUdGKA== where the first multiple reflection in part (b) corresponds to NiMvJSJtRyIiIQ== .(d) Now combine all of this to get the total reflection ratio formulaNiMvJSJSRywmJkYkNiMlI2FiRyIiIiosJiUiVEdGJ0YpJkYkNiMlI2JjR0YpJkYsNiMlI2JhR0YpLSUkZXhwRzYjKioiIiNGKSUiaUdGKSYlImtHNiMlImJHRiklImhHRilGKS0lJHN1bUc2JCkqKEYzRikmRiRGMUYpRi1GKSUibUcvRkQ7IiIhJSlpbmZpbml0eUdGKUYp . (Here's where the Maple actually starts--copy this into your exercise worksheet and and go to work.)(e) Use the formulas for the reflection and transmission coefficients and Maple's result for the sum to build a formula for NiMtJSJSRzYmJiUibkc2IyUiYUcmRic2IyUiYkcmRic2IyUiY0cqKCIiIyIiIiYlImtHRitGMiUiaEdGMg== . Once you have it, manipulate it into a form where you can easily obtain separate equations for its real and imaginary parts. The reflected wave will be exactly zero if both real and imaginary parts vanish. You will save yourself some trouble if you define a variable NiMvJSJ4RyooIiIjIiIiJiUia0c2IyUiYkdGJyUiaEdGJw== and work with it. It will also simplify the look of some of the equations if you let NiMvJSJ6Ry0lJGV4cEc2IyoqIiIjIiIiJSJpR0YqJiUia0c2IyUiYkdGKiUiaEdGKg== . The formulas will become horrible, and then at the end they become simpler and you will discover that NiMvLSUkc2luRzYjJSJ4RyIiIQ== so that NiMvJSJoRyomJSdsYW1iZGFHIiIiIiIlISIi , and once you know this it becomes not too hard to get NiMvJiUibkc2IyUiYkctJSVzcXJ0RzYjKiYmRiU2IyUiYUciIiImRiU2IyUiY0dGLw== , the same result you get if you ignore the problem of multiple reflections and transmissions. This is a hard problem--it took about all the Maple skill I have, and I learned some new things along the way.Go to top of chapter<Text-field layout="_pstyle5" style="_pstyle5">Debugging </Text-field>Common problems encountered by students and their cures are collected here. You probably came here from a chapter in the text looking for help and will want to go back when you are finished. Here are hyperlinks to take you back to the start of each chapter.Using hyperlinksIntroductionIndexChapter 1: Getting startedChapter 2: PlottingChapter 3: CalculusChapter 4: Complex numbersChapter 5: Linear algebraChapter 6: Solving equationsChapter 7: Differential equationsChapter 8: ProgrammingChapter 9: Symbolic algebraA. Online help If things go wrong the first thing you should try is online help. This will not always solve your problem, but it a good place to start. B. Unexpected results 1. If your problem is that you got an answer, but it isn't what you expected, quite often the trouble is that Maple thinks a variable can be anything, but you were thinking that it was a real number. The fix for this is assume(x,real,y,real,...)so that Maple will know the same things about the variables that you know. However: watch out for this problem: once you have used assume on a variable, however, you may have trouble having Maple give you numbers. The trouble happens when you assume something about a, use a in an expression which is assigned to another variable (say b), then give a value to a, and finally try to evaluate b. Observe:restart;assume(a,real);b:=cos(a);a:=2.;evalf(b);Now watch what happens to the same without the assumerestart;b:=cos(a);a:=2.;evalf(b);I suppose that the lesson here is only to use assume when absolutely necessary and to be aware thatthis problem exists. 2. Another common problem is with = vs :=. If you use = when you really mean assign (:=) you will find that the variable to which you thought you had assigned something doesn't have anything in it. 3. Maple says it has been given an illegal character, but you don't see anything wrong with the line. (a) Look for what looks like a leading space in the command, i.e., for a space betweeen > and the first character of the command. Delete this space. (b) If the problem persists, delete the entire line and retype it.4. You get the message Error, ';' unexpected. Check your parentheses, they might not be balanced.Here is a list of other common errors by category and how to fix or work around them. When you find things that drive you crazy in Maple, please email me and I will put them in this section for the benefit of other students. (ross_spencer@byu.edu)C. Plotting Errorsempty plot Syntax mistake when plotting an expression. For instance if we haverestart;g:=sin(x);plot(g,0..5); we get the empty plot error. The correct syntax for plotting an expression is plot(g,x=0..5); or evenplot(g(x),x=0..5);axes appear, but no function is plotted This happens when an expression, function, or procedure is to be plotted, but a parameter that needs to be assigned a value doesn't have one. For instance if we have a function f, an expression g, and a procedure p like thisrestart;f:=x->sin(x*t);g:=sin(x*t);p:=proc(x)global t;sin(x*t);end; then all three of these plot commands give a zero plotplot(f(x),x=0..5);plot(g,x=0..5);plot(p,0..5); The cure is to assign a value to t, like thist:=5; Now all three plot commands will work.This can also happen when you have set the vertical axes so that the plot doesn't appear in the window, like this negative function plotted in a positive vertical window:plot(-1-x^2,x=-1..1,y=0..2);Fix it by fixing the windowplot(-1-x^2,x=-1..1,y=-2..2);Error, (in plot) invalid arguments Perhaps you are trying to plot with a variable that has been assigned a value, like thisrestart;g:=sin(x);x:=5;plot(g(x),x=0..5); The cure is to undo the assignment like this (the single quotes are important)unassign('x');orx:='x';then try the plot again.Error, (in plot/transform) cannot evaluate boolean: -5.*z < -4 Perhaps you have used = instead of := in giving a variable a numerical value; in any case the problem is that z doesn't have a value. This is an especially subtle error when the thing that doesn't have a value is NiMlI3BpRw== , which happens when you use pi instead of Pi.Parametric plot gives two plots instead This happens when you get the square brackets in the wrong places. Here is a two-function plotplot([sin(s),cos(s)],s=0..2*Pi);and here is a parametric plotplot([sin(s),cos(s),s=0..2*Pi]);Look carefully at the placement of ] in these two cases.Function plotting fails When you have defined a function f(x), you try to plot it with plot(f(x),x=0..5) , and it fails, try operator form instead:f:=x->fsolve(t=x/(1+exp(t)),t);This syntax fails:plot(f(x),x=0..2);This syntax works:plot(f,0..2);D. Differentiation errorsError, wrong number (or type) of parameters in function diff Same thing as the unassign problem above in Plot errors, only in diff.restart:x:=5;diff(sin(x),x);You need to unassign x (remember to use the quotes):unassign('x');E. Integration errorsError, (in int) wrong number (or type) of arguments Same thing again as the unassign problem in Plot errors, except with int.restart:x:=5;int(sin(x),x);You need to unassign x (remember to use the quotes):unassign('x');F. Solve errorsNothing comes back Sometimes Maple can solve a system if the coefficients are rational numbers, but not if they are floating point numbers. So don't use x*0.01 -- use x/100 instead.G. Dsolve errorsH. Algebra errorsError, too many levels of recursion or Warning, recursive definition of name You have somehow set a variable equal to a function of itself. Here is a simple way to get this errorx:=1+x;but you can get it indirectly too if there is a chain of assigned variables and you close the chain on itself. It is helpful to know what variables are assigned to what, and you can find this out with the command anames(), unless the system is so messed up from the error that you get garbage. If this happens a restart is in order.You want x to be a variable, but it is a number instead x was previously assigned a value and you now need it to be a variable again. Here's a way to fix it.x:='x';This is just another way to unassign a variable.I. Miscellaneous errorsError, (in assign) invalid arguments Probably you tried to unassign a variable which was assigned a value and you didn't use single quotes, like thisrestart;x:=5;unassign(x);unassign('x');Note that you can also unassign with this commandx:='x';Go to top of Debugging<Text-field layout="_pstyle5" style="_pstyle5">Laboratory assignments</Text-field>This 1-credit-hour course consists of 14 computer labs to teach you how to use Maple to solve physics problems. Each lab is 3 hours long and there is no assigned work outside of this period. The text is a computer program written in Maple and called phys230.mws. You and your lab partner are assigned to read the text, execute the examples, and solve the assigned problems by using Maple, following the schedule given below. You complete each problem by showing a TA what you have produced on your computer screen and having them record the problem as completed.
No paper will be handed in. Your final grade will be determined by how many of the assigned problems you complete, by your performance on a short oral examination at the end of the course, and by how well you do three significant homework problems from one of your math or physics courses using the skills you are learning in this course. If you are not sure what "significant" means, ask a TA. If you do all of the work you should receive an A or an A-, depending on the level of skill you achieve.
Warning: some of you will be tempted to miss class and just work through the book on your own because the class feels so much like independent study. Do not do this. You will find yourself staring at a piece of Maple code that should work, but doesn't, and not have a clue about what is wrong. This happens in class too, but there you can raise your hand, a TA comes over and says, ``You need a comma right there.'', the code works, and you are underway again. By yourself this comma can take a long time to find. So please: come to class.
Also: watch for the checkpoints listed below after Labs 4, 9, and 14. They are there to keep you from getting behind and trying to finish the whole course in the last week.
Lab 1 (Chapter 1)
(a) Log on to a PC with a partner and copy the Maple worksheet phys230.mws from the floppy onto your space on the u: drive (or run from the floppy.) Or, download phys230.mws from the PhysicsLab 230 course page on the Department of Physics and Astronomy web site (www.physics.byu.edu). This worksheet is the textbook for the course. Then start Maple and use Open under the File menu to go to the directory where you put phys230.mws and open it.(b) Open the Introduction and read it with your lab partner.
(c) Open the Index and look at it. Click on a topic, then figure out a way to get back to the Index.
(d) Open Chapter 1 and work through each section, executing all of the Maple commands and doing what the text tells you to do.
Lab 2 (Chapter 1)(a) Use the things you have learned in Chapter 1 to make a Maple worksheet that presents the following problem in text and equations, discusses how to solve it, then uses Maple commands to solve it.
A charged disk of radius NiMlImFH and uniform charge density NiMlJnNpZ21hRw== produces an electric field NiMmJSJFRzYjJSJ6Rw== along the NiMlInpH -axis (where the NiMlInpH -axis is the line perpendicular to the disk through its center) given by the integral expressionNiMvLSYlIkVHNiMlInpHRicqKiUmc2lnbWFHIiIiRihGKy0lJGludEc2JComJSJyR0YrKSwmKiRGMCIiI0YrKiRGKEY0RisqJiIiJEYrRjQhIiJGOC9GMDsiIiElImFHRisqJkY0RismJShlcHNpbG9uRzYjRjtGK0Y4Find a simple algebraic expression for NiMtJiUiRUc2IyUiekdGJg== , then use NiMvJSZzaWdtYUciIiI= e-6 NiMqJiUiQ0ciIiIqJCUibUciIiMhIiI= , NiMvJiUoZXBzaWxvbkc2IyIiIS0lJkZsb2F0RzYkIiVhKSkhIiQ= e-12 NiMqKCUiTkciIiIqJCUibUciIiNGJSUiQ0chIiI= , and NiMvJSJhRyIiIg== mm to make a plot of NiMtJiUiRUc2IyUiekdGJg== from NiMvJSJ6RywkKiYiIiYiIiIlImFHRighIiI= to NiMvJSJ6RyomIiImIiIiJSJhR0Yn .(b) In Example 15.13 of Serway the Venturi tube is discussed. Bernoulli's equation
NiMvLCYmJSJQRzYjIiIiRigqKCUkcmhvR0YoKiQmJSJ2R0YnIiIjRihGLiEiIkYoLCYmRiY2I0YuRigqKEYqRigqJCZGLUYyRi5GKEYuRi9GKA==and the equation of continuity
NiMvKiYmJSJBRzYjIiIiRigmJSJ2R0YnRigqJiZGJjYjIiIjRigmRipGLUYo
are solved simultaneously to obtain the following formula
for NiMmJSJ2RzYjIiIj :NiMvJiUidkc2IyIiIyomJiUiQUc2IyIiIkYsLSUlc3FydEc2IyooRidGLCwmJiUiUEdGK0YsJkYzRiYhIiJGLComJSRyaG9HRiwsJiokRilGJ0YsKiQmRipGJkYnRjVGLEY1Riw=
Use Maple's solve command to obtain this result. (Hint: if you solve this as two equations in the two unknowns NiMmJSJ2RzYjIiIi and NiMmJSJ2RzYjIiIj , Maple will give you a RootOf mess back. You can get the answer you want, however, by using the command convert(...,radical), as discussed in Chapter 9.)
Lab 3 (Chapter 2)
(a) Go to Chapter 9 and study the symbolic algebra commands listed there, running the examples as you go. Don't work through the long exercise at the end, but just try to become familiar with the commands and what they do. As you work the other problems in this course you will probably refer to this chapter often as you try to talk Maple into giving you results in the form you want.
(b) Work through the sections of Chapter 2 from x-y Plotting to Plotting Data, skipping the advanced topics. Work the following problems and show your work to your TA.
2.1, 2.2, 2.3, 2.6, 2.7, 2.8, and the Plotting Data example.
Lab 4 (Chapter 2) (a) Work through the sections of Chapter 2 from Parametric Plots to 3-D Plotting and do the following problems:
2.10, 2.12, 2.13, 2.14, 2.16, 2.18, 2.20, 2.24, and work through and experiment with the commands in the 3D Plotting section. Especially become familiar with the items available on the toolbar at the top of the plot frame.
(b) Not required, but a good idea: If you have time, do the advanced material on wave
packets in the section on animations
and do problems 2.21-23.
CHECKPOINT 1:
Labs 1-4 must be finished now; no late work accepted after the end of the 4th laboratory period.
Lab 5 (Chapter 3)
Work through Limits, Differentiation, and part of Integration in Chapter 3, up through Elementary Integrals. Show your TA your work on Problems 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, and 3.11.
Lab 6 (Chapter 3)Work through the rest of Integration in Chapter 3, and show to your TA Problems 3.12, 3.13, 3.14, 3.16, and 3.17.
Lab 7 (Chapter 3)
Work through Series Expansions and Sums. Do Problems 3.19, 3.20, 3.21, 3.22, 3.23, 3.24, 3.25, and 3.26.
Lab 8 (Chapter 4)
Work through Chapter 4 on Complex Analysis, doing Problems 4.1, 4.2, 4.3, 4.4, 4.5, 4.7, 4.8, 4.11, 4.12, and 4.13.
Lab 9 (Chapter 5)CHECKPOINT 2:
Labs 5-9 must be finished now; no late work accepted after the end of the 9th laboratory period.
Lab 10 (Chapter 6)
(a) Work through Chapter 6 on Solving Equations, doing problems 6.1, 6.2, 6.3, 6.4, and 6.6. (If you have time, tackle 6.5; it is difficult, but you will gain experience with a problem that is similar to those that show up in researh all the time.)
(b) Find all of the zeros of the Bessel function derivative NiMtJSVkaWZmRzYkLSYlIkpHNiMiIiM2IyUieEdGLA== between 0 and 100 and load them into a column vector NiMmJSJhRzYjJSJuRw== . You can do this problem very compactly by using the seq command with fsolves inside it. Since this problem is a bit difficult, let's do it in small steps.(i) First plot the function between 0 and 100, then refine the plot range a couple of times so that you know about where the first and second zeros are, and about how far apart the later zeros are (you should find that they are separated by about NiMlI3BpRw== .)(ii) Use the seq command to use the information you found in (i) to generate all of the zeros. Recall that seq generates a list of numbers, like this:seq(n^2,n=0..20);then note that the first argument of seq can be anything that generates a number or an expression that depends on NiMlIm5H , even the result of an fsolve. Here, for example, is a way to use the seq command and fsolve to build a sequence of zeros of the cosine function using guesses that start at 1.4 and are separated by NiMlI3BpRw== :seq(fsolve(cos(x)=0,x=1.4+n*Pi),n=0..20);(iii) All you have to do now is to load these numbers into a column vector. Go back to Chapter 5 to see how to do this, then figure out how to put in the first zero at NiMvJSJ4RyIiIQ== by hand.Lab 11 (Chapter 8)
Work through the first two sections of Chapter 8 on Procedures, Loops and Logic, and do problems 8.1, 8.2, 8.3, 8.4, 8.5, 8.6, and 8.7.
Lab 12 (Chapter 8)Work through the last two sections of Chapter 8, doing problems 8.8, 8.9, 8.10, 8.13, and 8.14.
Lab 13 (Chapter 9)
Work through Chapter 9 again and do Problems 9.1 and 9.2. Then do two of the three problems 9.3, 9.4, or 9.5.
Lab 14 (Chapter 9)(a) Meet with your instructor and take a 20-minute oral/computer exam to show that you have a working knowledge of Maple.
(b) Catch up on any late lab work and work on the three homework problems from your other physics or math classes. Pass them off to a TA.
CHECKPOINT 3:
Labs 10-14 must be finished now; no late work accepted after the last lab period.
Go to top of section