{VERSION 5 0 "IBM INTEL NT" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "Helvetica" 1 14 128 0 0 1 0 0 2 0 0 0 0 0 0 1 } {CSTYLE "" -1 257 "" 0 24 0 0 255 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "Helvetica" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 260 "" 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 261 "" 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 262 "" 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 263 "" 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 264 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 265 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 266 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1 " -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 2" -1 4 1 {CSTYLE "" -1 -1 "Times" 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 2 1 0 1 0 2 2 0 1 }{PSTYLE "Title" -1 256 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }1 1 0 0 12 12 1 0 1 0 2 2 19 1 }{PSTYLE "Normal" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 14 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT 257 30 "MLC Lab Visit - Lab 03 \+ - Maple" }}{PARA 0 "" 0 "" {TEXT 256 46 "Mth 355 (a.k.a. Mth 399) Jan \+ 22, 2003 Maple 7" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 258 16 "Bent E. Petersen" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 257 "" 0 "" {TEXT 259 181 "There are 4 problems below. Problem solutio ns are due Jan 29, 2003. Email your solutions to me as Maple worksheet attachments. Your worksheet must execute correctly for full credit." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 62 "In this worksheet we investigate a few more features of Maple." }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 12 "Introduction" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 260 268 "If you a re viewing the MWS version of this document you will note all the Mapl e output has been removed. You will have to execute each command (by p ressing Enter when the cursor is on the command line) to see the outpu t. You can of course also use the menu selections " }{TEXT 261 22 "Edi t/Execute/Worksheet" }{TEXT 262 180 " to execute the entire worksheet, but you should execute the commands one at a time and take the opport unity to experiment along the way! Change some things to see how thing s work." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 123 "The static PDF version of this document shows all of the Maple ou tput. It is useful to look at when Maple is not available." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }} }}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 9 "Equations" }}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 181 "In Maple any expression, including \+ an equation, may be assigned to a label. Thus we can take a simple equ ation such as A=B and assign it to a label for ease in dealing with it . Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "eqn1:=A=B;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 129 "Here eqn1 is the label (or name) of the equation A=B. Sometimes we wish to extract the left or right (hand) s ide of an equation. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "lhs(eqn1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "rhs(eqn1);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 82 "There are devious, sometimes useful, wa ys to achieve the same thing. For example," }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "subs(eqn1,A);" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 328 " Here we have taken the expression A and substituted A=B in it. The res ult is of course B. Note eqn1 is not altered in any way - it simply pr ovides the specification for what to substitute for what. Note also th e subs() approach has the advantage that, unlike rhs(), it correctly h andles expressions containing several equations." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 183 "Another approach is to u se the assign() function. It assigns the right side of each equality i n a list to the left side, that is the left side becomes a label for t he right side. Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "assign(eqn1);" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 8 "B:=6; A;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 57 "In case we want to use A and B again let' s unassign them:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "unassign('A','B'); " }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 135 "The single quotes here prevent Maple from evaluating A and B. Otherwise we would be trying t o unassign 6, which would produce an error." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 29 "Functions and Differentiation" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "A function in Maple is de fined by the \"arrow\" notation:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "f:=x->x^2+2*x-3;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 77 "A suitabl e expression may be converted to a function by using unapply(). Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "expr:=x^2+2*x-3;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "g:=unapply(expr,x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 44 "Yes there is a related apply() function too!" } }{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "apply(g,x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 58 "It's usually easier just to use g(x) to apply g to x." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 129 "Functions are evaluated in the usual familiar way, where as expressions are evaluated by using the substitute command subs(). T hus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "f(t); f(6);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "subs(x=6,expr);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 151 "One thing to be careful about is the x i n the arrow notation above is local to the function we are defining, t hat is, it is just a dummy variable. Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "h:=x->expr;" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 108 "d oes not define the same function as f above, but instead defines the c onstant function whose value is expr," }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "h(t); h(6);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 95 "It is bes t not to be too devious when defining functions. Errors like this can \+ be hard to find!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 246 "Maple works well with expressions, but is not quite as c ompetent with functions. If one plans to use Maple to simplify complic ated expressions, it is best to leave them as expressions, even if hab it makes functions feel more natural to work with." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "is(f=g);" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "is(f(x)=g(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 71 "Note FAIL does not mean false. It means Maple does not know the answer." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 111 "The diff erentiation operator for functions is D(). The differentiation operato r for expressions is diff(). Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "D(f);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 13 "diff(f(x),x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 99 "Note that diff() is very \+ easy to use for partial derivatives and for higher order derivatives. \+ Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "diff(arctan(y/x),x,y): simplify(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 77 "The D operato r on the other hand applies only to functions of one variable." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 504 "Note the use of Maple ditto operator % above. Be very careful! This operator r efers to the previously evaluated expression (in time), not the previo us expression on the worksheet. It makes a difference since one can mo ve around and evaluate expressions in numerous places on the worksheet , so previous in time need not be the same as previous in location. Th e two are the same of course if you restrict % to refer to an expressi on on the same line, as above. That is the safest way to use the % ope rator." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 27 "Plotting Mu ltiple Functions" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 198 "There are several ways to plot multiple functions in one plot, bu t the simplest is to plot a list of functions. Note we can control the colors and add a title and a legend. Here is a simple example:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 111 "plot([cos(x),sin(x)],x=-6..6, color=[blue,red], legend=[\"cos(x )\",\"sin(x)\"], title=\"Plot of cos(x) and sin(x)\");" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 42 "Ordinary Differential Equations (Symbolic)" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 153 "We use the dsolve() command to so lve differential equations. It returns an expression (which may be emp ty) which contains equations giving the solution. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 145 "There are numerous numer ical versions of dsolve() which a procedure for approximating a soluti on. We will discuss this topic in the next section." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 18 "Here's an example:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "ode1:=diff(y(x),x)=x*sec(y(x));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "init1:=y(0)=2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "soln1:=dsolve(\{ode1,init1\},y(x));" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 85 "If one wants the soluti on expressed as a function y, that can be achieved as follows:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "y:=unapply(rhs(soln1),x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 167 "The disadvantage here is we have no w assigned a value to y. We will not be able to use y again as a \"var iable\" in a differential equation without first unassigning it." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 186 "If you j ust want to plot the solution, or manipulate it in some other way, it \+ is not necessary to convert it to a function - you just extract the ap propriate expression and plot it. Thus" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "plot(rhs(soln1),x=-2/5. .1/2,color=red,thickness=2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 15 "Let's clean up:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "unassign('y ');" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 153 "The conversion to a function above can be done more simply by \+ using the assign() function. First we assign y(x) as a label for the solution expression." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "assign(soln1);" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 19 "y:=unapply(y(x),x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 21 "Let's clean up again: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "unassign('y');" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 23 "Here's another example:" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "ode2 :=diff(y(x),x,x)-6*diff(y(x),x)+5*y(x)=exp(5*x)-exp(-5*x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "soln2:=dsolve(ode2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 79 "Notice th e arbitrary constants here. You may prefer a more familiar expression: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "subs(_C1=c[1],_C2=c[2],soln2);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 54 "You can of course al so solve an initial value problem:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "init2:=y(0)=3,D(y)(0)=-2;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "solni2:=dsolve(\{ode2,ini t2\},y(x));" }}}{EXCHG {PARA 4 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 " " {TEXT -1 32 "System of differential equations" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 29 "Let's look at a simple sy stem" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "ode3a:=diff(y(t),t)=3*x(t)-2*y(t);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "ode3b:=diff(x(t),t)=2*x(t)+3*y(t);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "init3:=x(0)=3,y(0)=-1;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "soln3:=dsolve(\{ode3a,ode3b, init3\},\{x(t),y(t)\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 " soln3:=simplify(soln3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 137 "The easiest way to extract the individua l pieces is to use assign(). Also assign() makes no assumptions about \+ the order of the solutions." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "assign(soln3);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 91 "Note this assigns x(t) and y(t) as labels for the appropriate expressions (not \+ functions!)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "x(t);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "y(t);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 235 "It is improtant to realise that x and y remain unassigne d. The labels x(t) and y(t) here are atomic labels, not function evalu ations. If you want x and y to be functions corresponding to the s olutions you have to say so explicitly:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "x:=unapply(x(t),t); y: =unapply(y(t),t);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 50 "Let's clean up before going on to another example: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "unassign('x','y');" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 235 "We do not need to unassign x(t ) and y(t). Those labels were clobbered when we defined the functions \+ x and y, since, after defining the functions, x(t) became the function x evaluated at t and y(t) became the function y evaluated at t. " }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 23 "Symbolic Initial Values" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 92 "As you might expect we can solve (some) initial va lue problems with symbolic initial values:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "ode4:=diff(y(x),x $2)+4*y(x)=sec(x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 171 "Note we used x$2 rather than x,x to indicate the second derivative. It's not a big deal here, but for higher order derivatives the x$n notation has obvious advantages." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "init4:=y (0)=A,D(y)(0)=B;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "soln4:= dsolve(\{ode4,init4\},y(x));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 41 "Ordinary Differential \+ Equations (Numeric)" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restar t;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "with(plots):" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 133 "M aple has a number of numeric method built in that can be used to solve differential equations that Maple can not solve symbolically." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "ode1:=diff(y(x),x)=x^2+x*y(x)+y(x)*tan(y(x));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "init1:=y(0)=1;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "soln1:=dsolve(\{ode1,init1\},y(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 61 "The empty solution indicates Maple could not find a solution." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "soln1n:=d solve(\{ode1,init1\},y(x),numeric);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 120 "This looks mysterious but is a procedure which will compute the numeric approximations to y(x) for specified x. Thus:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "soln1n(0.12); soln1n(0.13);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 457 "Of cours e we could use these expressions to plot the approximate solution, but fortunately the Maple procedure odeplot() understands the data retur ned by dsolve/numeric and is more efficient. Note though that the pro cedure odeplot() is defined in the plots package, and so it can be us ed in the form odeplot() only after executing the command with(plots) \+ (as we did above). However, it can always be accessed through the long form of the command by using" }{TEXT 263 90 " plots[odeplot]() (in wh ich case the plots package does not have to be loaded explicitly)." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 56 "odeplot(soln1n,[x,y(x)],0..0.14,thickness=3,color=blue);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 139 "N ote Maple knows quite a few numeric procedures for approximating the s olution to an initial value problem. Try the following help request:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "# ?dsolve/numeric" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 30 "to find out what is available." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 228 "Note M aple's DEtools package contains many useful tools for studying differe ntial equations. In particular DEplot() can be used to plot solution curves (with a direction field in the case of first order differentia l equations:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "with(DEtools):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "DEplot(ode1,[y(x)],x=0..0.09,[ [y(0)=1],[y(0)=1.1],[y (0)=1.15] ]);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 13 "Prime Numbers" }}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 53 "The isprime() procedure checks if a number is prime:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "isprime(104729); isprime(1299709); isprim e(3297703);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 176 "The Maple primality test is very quick, but it is \"pr obabilistic\" and could possibly return an incorrect answer. On the ot her hand no incorrect response has ever been observed." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 47 "The ithpr ime() procedure returns the nth prime:" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "ithprime(1); ithprime(2 ); ithprime(3); ithprime(100);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 80 "A prime pair is a an ordered pair [p ,p+2] such that p and p+2 are both prime." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "ispprime:=proc(n) " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 30 " isprime(n) and isprime(n+2); " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 70 "Here are the first few pr imes p such that [p,p+2] is a prime pair:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 67 "ispprime(3) ; ispprime(5); ispprime(11); ispprime(17); ispprime(29);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 69 "Here is a prime which is the not the first component in a prime pair:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "i sprime(31); ispprime(31);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 72 "It has been conjectured that there is an \+ infinite number of prime pairs." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 239 "In the late 1700's and early 1800's Gauss conjectured that the number of primes in an interval of length \+ dx starting at x is about 1/log(x) (natural logarithm). It follows tha t the number of primes less than or equal to x ought to be about" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "Int(1/log(t),t=0..x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 290 "This integral (which is only interestin g for x greater than 2) is divergent and should be taken in the princi pal value sense. Alternately we can change the lower limit to about 1. 4 without changing the value of integral. This makes it convergent sin ce we avoid the singular point at t = 1." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 208 "This integral is called the logar ithmic integral and is implemented in Maple as Li(). Maple can not com pute the integral exactly so Li() will return unevaluated unless the a rgument is a floating point number." }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "Li(100); evalf(%); Li(100. 0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 64 "The lower limit referred to above is found by solving Li(x) = \+ 0" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 66 "Digits:=40: fsolve(Li(x)=0,x=1..infinity, fulldigits) ; Digits:=10:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 170 "Maple is able to compute \"exactly\" the number of pr imes less than or equal to x. This function is implemented in the numt heory package, so we can test Gauss's conjecture." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "with(numthe ory):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "plot([ pi(floor(x) ), Li(x) ], x=2..300 );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 41 "Well, Gauss was certainly onto something! " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 163 "A st ronger result, proved in 1898 by de la Vall\351e Poussin and Hadamard \+ is the Prime Number Theorem which says that pi(x)/Li(x) has limit 1 as x tends to infinity. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "plot(pi(floor(x))/Li(x),x=2..5000); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 " " 0 "" {TEXT -1 8 "Problems" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 35 "Here's a few problems to play with:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 4 "" 0 "" {TEXT -1 0 "" }{TEXT 264 9 "Pr oblem 1" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 120 "Write a Maple procedure pp() such that pp(x) returns a list of al l prime pairs [p,p+2] with p+2 less than or equal to x." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 167 "Note for large x \+ the calculation of pp(x) may require a long time and may be difficul t to interrupt gracefully. Be sure to save your work before testing yo ur code." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 111 "Note you may want to make use of the ithprime() procedure and p erhaps also Maple's \"while\" control statement." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 34 "As a test pp(20) should return " }{XPPEDIT 18 0 "[[3, 5], [5, 7], [11, 13], [17, 19]];" "6#7 &7$\"\"$\"\"&7$F&\"\"(7$\"#6\"#87$\"#<\"#>" }{TEXT -1 2 " ." }}} {EXCHG {PARA 4 "" 0 "" {TEXT -1 9 "Problem 2" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 6 "Solve " }{TEXT 265 11 "numerical ly" }{TEXT -1 26 " the initial value problem" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "ode:=diff(y(x),x, x)+6*x*diff(y(x),x)-4*x^3*y(x)=0;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "init:=y(0)=0,D(y)(0)=1;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 139 "and then plot the soluti on for x=-1..2. Do not load the plots package explicitly but instea d use the plot procedure dplot() defined by" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "dplot:=plot s[odeplot];" }}}{EXCHG {PARA 4 "" 0 "" {TEXT -1 9 "Problem 3" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 6 "Solve " }{TEXT 266 12 "symbolically" }{TEXT -1 26 " the initial value problem" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "ode:=diff(y(x),x,x)+4*diff(y(x),x)+13*y(x)=exp(-2*x)*cos(3*x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "init:=y(0)=2,D(y)(0)=-1; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 39 "Then plot the solution for x=-0.25..2." }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 4 "" 0 "" {TEXT -1 9 "Problem 4" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 31 "Solve the initial va lue problem" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "ode4:=diff(T(t),t)=-k*(T(t)-A(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "A:=t->cos(2*t);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "k:=1.5;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "init4:=T(0)=0;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 283 "You can think of this problem as mo deling an insulated box heated by an external source. Here A(t) is the ambient or external temperature and T(t) is the resulting temperatu re inside the box. Plot both A(t) and T(t) for t=0..10 on a singl e plot. Note the phase shift in T(t)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {MARK "1 0 0" 12 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }