{VERSION 5 0 "SUN SPARC SOLARIS" "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 Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 3 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Warning" 2 7 1 {CSTYLE "" -1 -1 " " 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 } {PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Plot" 0 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 256 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 257 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {PARA 256 "" 0 "" {TEXT -1 9 "Math 2250" }}{PARA 257 "" 0 "" {TEXT -1 22 "Numerical Computations" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }{PARA 0 "" 0 "" {TEXT -1 843 " In this handout we will study nume rical methods for approximating solutions to first order differential \+ equations. (The fact is, most differential equations do NOT have simp le formulas for their solutions, despite all the examples you've seen \+ in which they do. In the case that no nice formula exists for the sol ution one must approximate it numerically.) A month from now we will \+ see how higher order differential equations can be converted into firs t order systems of differential equations, and that there is a natural way to generalize what we are doing now in the context of a single fi rst order differential equation to this more complicated setting. So \+ understanding today's material will be an important step in understand ing numerical solutions to higher order differential equations and to \+ systems of differential equations." }}{PARA 0 "" 0 "" {TEXT -1 86 " \+ We will be working through selected material from sections 2.4-2.6 o f the text. " }}{PARA 0 "" 0 "" {TEXT -1 960 " The most basic met hod of approximating solutions to differential equations is called Eul er's method, after the 1700's mathematician who first formulated it. \+ If you want to approximate the solution to the initial value problem d y/dx = f(x,y), y(x0)=y0, first pick a step size ``h''. Then for x bet ween x0 and x0+h, use the constant slope f(x0,y0). At x-value x1:=x0+ h your y-value will therefore be y1:=y0 + f(x0,y0)h. Then for x betwe en x1 and x1+h you use the constant slope f(x1,y1), so that at x2:=x1+ h your y-value is y2:=y1+f(x1,y1)h. You continue in this manner. It \+ is easy to visualize if you understand the slope field concept we've b een talking about; you just use the slope field where you are at the e nd of each step to get a slope for the next step. It is straightforwa rd to have a programmable calculator or computer software do this sort of tedious computation for you. In Euler's time such computations wo uld have been done by hand!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 467 " A good first example to illustrate Euler' s method is our favorite DE from the time of Calculus, namely dy/dx =y , say with initial value y(0)=1, so that y=exp(x) is the solution. Le t's take h=0.2 and try to approximate the solution of the x-interval [ 0,1]. Since the approximate solution will be piecewise affine, we onl y need to know the approximations at the discrete x values x=0,0.2,0.4 ,0.6,0.8,1. Here's a simple ``do loop'' to make these computations. \+ " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 46 "restart: #clear any memory from earlier work " }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 100 "x0:=0.0; xn:=1.0; y0:=1.0; \+ n:=5; h:=(xn-x0)/n; \n #specify initial values, number of steps, and \+ size" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%#x0G$\"\"!F&" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%#xnG$\"#5!\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6#>%#y0G$\"#5!\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG\"\"&" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"hG$\"+++++?!#5" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 100 "f:=(x,y)->y; #this is the slope functio n f(x,y) \n #in dy/dx = f(x,y), in our example dy/dx = y." }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fGf*6$%\"xG%\"yG6\"6$%)operatorG%&arrowG F)9%F)F)F)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "x:=x0; y:=y0; #initialize x,y for the do loop" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# >%\"xG$\"\"!F&" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"yG$\"#5!\"\"" }} }{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "print('x','y','exp(x)');" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "for i from 1 to n do" }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 63 " k:= f(x,y): #current slope, use : t o suppress output" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 45 " y:= \+ y + h*k: #new y value via Euler" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 " x:= x + h: #updated x-value:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 55 " print(x,y,exp(x)); #display current values , " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 54 " #and c ompare to exact solution." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 47 " od : #``od'' ends a do loop " }}{PARA 11 "" 1 "" {XPPMATH 20 "6%%\"xG%\"yG-%$expG6#F#" }}{PARA 11 "" 1 "" {XPPMATH 20 " 6%$\"+++++A!\"*$\"+1P3IuF%$\"+*\\8]-*F%" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++C!\"*$\"+Z/5;*)F%$\"+QwJ-6!\")" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++E!\"*$\"+a?$*p5!\")$\"+/QPY8F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++G!\"*$\"+l%=RG\"!\")$\"+xYYW;F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++I!\"*$\"+e@qS:!\")$\"+#p`&3?F(" }}} {PARA 0 "" 0 "" {TEXT -1 318 "Notice your approximations are all a lit tle too small, in particular your final approximation 2.488... is shor t of the exact value of exp(1)=e=2.71828.. The reason for this is tha t because of the form of our f(x,y) our approximate slope is always le ss than the actual slope. We can see this graphically using plots: " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "with(plots):with(linalg): " }}{PARA 7 "" 1 "" {TEXT -1 80 "Warning, the protected names norm and trace have been redefined and unprotected\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 "xval:=vector(n+1);yval:=vector(n+1); #to collec t all our points" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%%xvalG-%&arrayG6 $;\"\"\"\"\"'7\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%%yvalG-%&arrayG6 $;\"\"\"\"\"'7\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "xval[1] :=x0; yval[1]:=y0; #initial values" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%%xvalG6#\"\"\"$\"\"!F)" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%%yvalG6#\"\"\"$\"#5!\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 " #paste in the previous work, and modify fo r plotting:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "for i from 1 to n do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " x:=xval[i]: \+ #current x" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " y:=yval[i]: #current y" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 37 " k:= f(x,y ): #current slope" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 55 " yva l[i+1]:= y + h*k: #new y value via Euler" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 50 " xval[i+1]:= x + h: #updated x-value:" } }{PARA 0 "> " 0 "" {MPLTEXT 1 0 57 " od: # ``od'' ends a do loop " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 " approxsol:=pointplot(\{seq([xval[i],yval[i]], i=1..n+1)\}):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "exactsol:=plot(exp(t),t=0..1 ,`color`=`black`): " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 " \+ #used t because x was already used above" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "display(\{approxsol,exactsol\});" }}{PARA 13 "" 1 "" {GLPLOT2D 349 262 262 {PLOTDATA 2 "6&-%'CURVESG6$7S7$$\"\"!F)$\"\" \"F)7$$\"3dmmm;arz@!#>$\"3)y_2wWO?-\"!#<7$$\"3[LL$e9ui2%F/$\"3aNdbY\\g T5F27$$\"3nmmm\"z_\"4iF/$\"3#=fT9tfS1\"F27$$\"3[mmmT&phN)F/$\"3;Hr`&G_ r3\"F27$$\"3BLLe*=)H\\5!#=$\"3L^LEiEj56F27$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