{VERSION 3 0 "APPLE_PPC_MAC" "3.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 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 }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 }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 }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 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 0 258 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT -1 11 "Math 2250-3" }}{PARA 257 "" 0 "" {TEXT -1 22 "Numerical Computations" }}{PARA 258 "" 0 "" {TEXT -1 25 "Wednesday, Sept 13, 2000" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 843 " In this handout we will study numerical methods for approxim ating solutions to first order differential equations. (The fact is, \+ most differential equations do NOT have simple formulas for their solu tions, despite all the examples you've seen in which they do. In the \+ case that no nice formula exists for the solution one must approximate it numerically.) A month from now we will see how higher order diffe rential equations can be converted into first order systems of differe ntial equations, and that there is a natural way to generalize what we are doing now in the context of a single first order differential equ ation to this more complicated setting. So understanding today's mate rial will be an important step in understanding numerical solutions to higher order differential equations and to systems of differential eq uations." }}{PARA 0 "" 0 "" {TEXT -1 86 " We will be working throu gh selected material from sections 2.4-2.6 of the text. " }}{PARA 0 " " 0 "" {TEXT -1 343 " The most basic method of approximating solut ions to differential equations is called Euler's method, after the 170 0's mathematician who first formulated it. If you want to approximate the solution to the initial value problem dy/dx = f(x,y), y(x0)=y0, f irst pick a step size ``h''. Then for x between x0 and x0+h, use the \+ constant slope" }}{PARA 0 "" 0 "" {TEXT -1 616 "f(x0,y0). At x-value \+ x1:=x0+h your y-value will therefore be y1:=y0 + f(x0,y0)h. Then for \+ x between 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 manne r. It is easy to visualize if you understand the slope field concept \+ we've been talking about; you just use the slope field where you are a t the end of each step to get a slope for the next step. It is straig htforward to have a programmable calculator or computer software do th is sort of tedious computation for you. In Euler's time such computat ions would 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 solutio n. Let's take h=0.2 and try to approximate the solution of the x-inte rval [0,1]. Since the approximate solution will be piecewise affine, \+ we only 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 computat ions. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{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\"\"!" }}{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 function f(x ,y) \n #in dy/dx = f(x,y), in our example dy/dx = y." }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fGR6$%\"xG%\"yG6\"6$%)operatorG%&arrowGF)9%F)F )F)" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{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 47 "x:=x0; y:=y0; #initialize x,y for the do loop" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>% \"yG$\"#5!\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "for i fro m 1 to n do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 63 " k:= f(x,y) : #current slope, use : to 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-v alue:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 55 " print(x,y,exp(x) ); #display current values, " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 54 " \+ #and compare to exact solution." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 47 " od: #``od'' ends a do loop \+ " }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++?!#5$\"+++++7!\"*$\"+eFS@7 F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++S!#5$\"++++S9!\"*$\"+)pC =\\\"F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++g!#5$\"++++G " 0 "" {MPLTEXT 1 0 25 "with( plots):with(linalg):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 "xva l:=vector(n+1);yval:=vector(n+1); #to collect 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#\" \"\"\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%%yvalG6#\"\"\"$\"#5!\" \"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 " #paste in \+ the previous work, and modify for 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 " yval[i+1]:= y + h*k: #new y v alue 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(\{app roxsol,exactsol\});" }}{PARA 13 "" 1 "" {GLPLOT2D 349 262 262 {PLOTDATA 2 "6&-%'POINTSG6(7$$\"+++++!)!#5$\"+++gt?!\"*7$$\"+++++5F,$ \"+++K)[#F,7$$\"+++++gF)$\"++++G&\\P*R8FS7$$\"1nm\"z*ev:JF`o$\"1KG 01]dl8FS7$$\"1LLL347TLF`o$\"19H.#p*p'R\"FS7$$\"1LLLLY.KNF`o$\"1Lbfo2iB 9FS7$$\"1++D\"o7Tv$F`o$\"1ZdFH**eb9FS7$$\"1LLL$Q*o]RF`o$\"12/UDl[%[\"F S7$$\"1++D\"=lj;%F`o$\"1;8&[1^o^\"FS7$$\"1++vV&R'=e\"FS7$$\"1LLeR\"3Gy%F`o$\"1.c]c%)H8;FS 7$$\"1nm;/T1&*\\F`o$\"1!fh)zw!zk\"FS7$$\"1mm\"zRQb@&F`o$\"1,G!GGVYo\"F S7$$\"1***\\(=>Y2aF`o$\"16+U5yG<jrpbKv\"FS7$ $\"1+++]y))GeF`o$\"1!=v7P07z\"FS7$$\"1****\\i_QQgF`o$\"1OlB#\\E\"H=FS7 $$\"1***\\7y%3TiF`o$\"1fT_<6em=FS7$$\"1****\\P![hY'F`o$\"1V)H1Jn!4>FS7 $$\"1LLL$Qx$omF`o$\"1[cmrs1[>FS7$$\"1+++v.I%)oF`o$\"1RAPIze!*>FS7$$\"1 mm\"zpe*zqF`o$\"1MeRd*=*H?FS7$$\"1+++D\\'QH(F`o$\"1i'*f?z!Q2#FS7$$\"1K Le9S8&\\(F`o$\"1+43Q,(f6#FS7$$\"1***\\i?=bq(F`o$\"1?.C'Qe4;#FS7$$\"1LL L3s?6zF`o$\"1(p,G?ne?#FS7$$\"1++DJXaE\")F`o$\"1vYezG)QD#FS7$$\"1nmmm*R RL)F`o$\"19U**za6,BFS7$$\"1mm;a<.Y&)F`o$\"1^n_#[T/N#FS7$$\"1LLe9tOc()F `o$\"1g*=(>KS+CFS7$$\"1+++]Qk\\*)F`o$\"1'G]\"H'[sW#FS7$$\"1LL$3dg6<*F` o$\"1i$4Z;k?]#FS7$$\"1mmmmxGp$*F`o$\"1[Xr/78_DFS7$$\"1++D\"oK0e*F`o$\" 15')HYrh1EFS7$$\"1++v=5s#y*F`o$\"1>xB3j&)fEFS7$FK$\"1X!f%G=G=FFS-%'COL OURG6&%$RGBGFBFBFB-%+AXESLABELSG6$Q\"t6\"%!G-%%VIEWG6$;FBFK%(DEFAULTG " 1 2 0 1 0 2 9 1 4 2 1.000000 45.000000 45.000000 0 }}}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 443 "If you connect the Euler dots in your mind, th e picture above is like the one in figure 2.4.3, on page 109 of the te xt. The upper graph is of the exponential function, the lower graph i s of your Euler approximation. The reason that the dots lie below the true graph is that as y increases the slope f(x,y)=y should also be i ncreasing, but in the Euler approximation you use the slope at each (l ower ) point to get to the next (higher) point." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 424 " It should be that as your step size ``h'' gets smaller, your approximations get better to \+ the actual solution. This is true if your computer can do exact math \+ (which it can't), but in practice you don't want to make the computer \+ do too many computations because of problems with round-off error and \+ computation time, so for example, choosing h=0.0000001 would not be pr actical. But, trying h=0.01 should be instructive:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 248 " Since the width of \+ our x-interval is 1, we stepsize h=0.01 by taking an n-value of subint ervals to be100. We keep the other data the same as in our first exam ple. The following code only prints out approximations when h is a mu ltiple of 0.1:" }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "x0:=0.0; xn:=1.0; y0:=1.0; n:=100; h:=(xn-x0)/n;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%#x0G\"\"!" }}{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!#6" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "x:=x0; y:=y0;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"yG$\"#5!\"\" " }}}{EXCHG {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 20 "for i from 1 to n do" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 " k:= f(x,y): #current slo pe" }}{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 25 " \+ if frac(i/10)=0" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 38 " \+ then print(x,y,exp(x));" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 60 " \+ fi; #use the ``if'' test to decide when to print;" }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 60 " #the command ``frac'' computes \+ the remainder " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 59 " #o f a quotient, it will be zero for us if i " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 37 " #is a multiple of 10. " }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 23 " od: " }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++5!#5$\"+F@i/6!\"*$\"+=4<06F(" }}{PARA 11 "" 1 " " {XPPMATH 20 "6%$\"+++++?!#5$\"+T+>?7!\"*$\"+eFS@7F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++I!#5$\"+;*[yM\"!\"*$\"+3)e)\\8F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++S!#5$\"+NP'))[\"!\"*$\"+)pC=\\\"F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++]!#5$\"+B=jW;!\"*$\"+r7s[;F( " }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++g!#5$\"+*p'p;=!\"*$\"++)=@ #=F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++q!#5$\"+qLw1?!\"*$\"+2 Fv8?F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++!)!#5$\"+?_r;A!\"*$ \"+G4aDAF(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++!*!#5$\"+yEj[C! \"*$\"+6JgfCF(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++5!\"*$\"+MQ \"[q#F%$\"+G=G=FF%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 33 "We can also see this graphically:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 70 "x val:=vector(n+1);yval:=vector(n+1); #to collect all \n #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#>&%%xv alG6#\"\"\"\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>&%%yvalG6#\"\"\"$ \"#5!\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 64 " #pa ste in the previous work, and modify for 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 " yval[i+1]:= y + h*k: #new y v alue 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 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "display(\{approxsol,exactsol\});" }}{PARA 13 "" 1 "" {GLPLOT2D 349 262 262 {PLOTDATA 2 "6&-%'CURVESG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G {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 566 " Actually, considering how many computations you d id with n=100 you are not so close to the exact solution. In more comp licated problems it is a very serious issue to find relatively efficie nt ways of approximating solutions. An entire field of mathematics, ` `numerical analysis'' deals with such issues for a variety of mathemat ical problems. The book talks about some improvements to Euler in s ections 2.5 and 2.6. If you are interested in this important field \+ of mathematics you should read 2.5 and 2.6 carefully. Let's summarize \+ some highlights below." }}{PARA 0 "" 0 "" {TEXT -1 98 " For any t ime step h the fundamental theorem of calculus asserts that, since dy/ dx = f(x,y(x)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "y(x+h)=y(x) + Int(dy/dt,t= x..x+h);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/-%\"yG6#,&%\"xG\"\"\"%\"h GF),&-F%6#F(F)-%$IntG6$*&%#dyG\"\"\"%#dtG!\"\"/%\"tG;F(F'F)" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "y(x+h)=y(x) + Int(f(t,y(t)), t=x..x+h);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/-%\"yG6#,&%\"xG\"\"\"% \"hGF),&-F%6#F(F)-%$IntG6$-%\"fG6$%\"tG-F%6#F4/F4;F(F'F)" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 743 "The problem with Euler is that we always approximated this integral by h*f(x,y(x)), i.e. we used the left-hand endpoint as our approximation of the ``average height''. The improve ments to Euler depend on better approximations to that integral. ``Im proved Euler'' uses an approximation to the Trapezoid Rule to approxim ate the integral. The trapezoid rule for the integral approximation w ould be (1/2)*h*(f(x,y(x))+f((x+h),y(x+h)). Since we don't know y(x+h ) we approximate it using unimproved Euler, and then feed that into th e trapezoid rule. This leads to the improved Euler do loop below. Of course before you use it you must make sure you initialize everything correctly. We'll compare it when n=5, to our first (unimproved) attem pt." }}{PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 69 "x0:=0; y0:=1;xn:=1.0;n:=5;\nh:=(xn-x0)/n; \nx:=x0; y:=y0; \nf:=( x,y)->y;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%#x0G\"\"!" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>%#y0G\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6# >%#xnG$\"#5!\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG\"\"&" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"hG$\"+++++?!#5" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#>%\"xG\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"yG \"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"fGR6$%\"xG%\"yG6\"6$%)op eratorG%&arrowGF)9%F)F)F)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "for i from 1 to n do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 41 " k1: =f(x,y): #left-hand slope" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 59 " k2:=f(x+h,y+h*k1): #approximation to right-hand slope" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 56 " k:= (k1+k2)/2: #approxima tion to average slope" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 48 " y:= y+ h*k: #improved Euler update" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 34 " x:= x+h: #update x" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 22 " print(x,y,exp(x));" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 5 "od: " }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++?!#5$\"++++?7! \"*$\"+eFS@7F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++S!#5$\"+++S) [\"!\"*$\"+)pC=\\\"F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++g!#5$ \"++![e\"=!\"*$\"++)=@#=F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++ !)!#5$\"+gXL:A!\"*$\"+G4aDAF(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"++ +++5!\"*$\"+j\"3Fq#F%$\"+G=G=FF%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 100 "Notice we al most did as well with improved Euler when n=5 as we did with n=100 in \+ unimproved Euler. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 337 " One can also use Taylor approximation methods to im prove upon Euler; by differentiating the equation dy/dx = f(x,y) one c an solve for higher order derivatives of y in terms of the lower order ones, and then use the Taylor approximation for y(x+h) in terms of y( x). See the book for more details of this method, we won't do it here ." }}{PARA 0 "" 0 "" {TEXT -1 207 " In the same vein as ``improved Euler'' we can use the Simpson approximation for the integral instead of the Trapezoid one, and this leads to the Runge-Kutta method which \+ is widely used in real software." }}{PARA 0 "" 0 "" {TEXT -1 470 " (Yo u may or may not have talked about Simpson's Rule in Calculus, it is b ased on a quadratic approximation to the function f, whereas the Trape zoid rule is based on a first order approximation.) Here is the code \+ for the Runge-Kutta method. The text explains it in section 2.6. Simp son's rule approximates an integral in terms of the integrand values a t each endpoint and at the interval midpoint. Runge-Kutta uses two di fferent approximations for the midpoint value." }}{PARA 0 "" 0 "" {TEXT -1 2 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 1 "." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "x:=x0; y:=y0; n:=5; h: =(xn-x0)/n;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"xG\"\"!" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"yG\"\"\"" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"nG\"\"&" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"hG$\"+++++?!# 5" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "for i from 1 to n do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 45 " k1:=f(x,y): #lef t-hand slope" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 57 " k2:=f(x+h/2,y+h *k1/2): #1st guess at midpoint slope" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 60 " k3:=f(x+h/2,y+h*k2/2): #second guess at midpoint slope" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 55 " k4:=f(x+h,y+h*k3): #gue ss at right-hand slope" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 70 " k:=(k 1+2*k2+2*k3+k4)/6: #Simpson's approximation for the integral" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 " x:=x+h: #x upd ate" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 38 " y:=y+h*k: \+ #y update" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 59 " print(x,y,exp(x)) ; #display current values" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 7 " od: " }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++?!#5$\"+++S@ 7!\"*$\"+eFS@7F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++S!#5$\"+gz \"=\\\"!\"*$\"+)pC=\\\"F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++++g !#5$\"+ck5A=!\"*$\"++)=@#=F(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\"+++ ++!)!#5$\"+D3_DA!\"*$\"+G4aDAF(" }}{PARA 11 "" 1 "" {XPPMATH 20 "6%$\" +++++5!\"*$\"+O6D=FF%$\"+G=G=FF%" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 74 "Notice how cl ose Runge-Kutta gets you to the correct value of e, with n=5." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 207 "Even wit h code like Runge-Kutta there are subtleties and problems which partic ular problems will cause. We will not go into those here; there are g ood examples in sections 2.4-2.6 and the homework problems." }}}} {MARK "36 10 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 }