{VERSION 3 0 "IBM INTEL NT" "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 Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 23 "Courier" 1 10 0 0 0 0 0 0 0 0 0 0 3 0 0 }{CSTYLE "" -1 256 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 257 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 258 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 259 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 260 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 261 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 262 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 263 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" 18 264 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 265 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 266 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 267 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 268 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE " " -1 269 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 286 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 290 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 291 "" 1 18 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 292 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 294 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 299 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 300 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 301 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE " " -1 302 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 303 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 312 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 313 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 314 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 315 "" 1 18 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 316 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 317 "" 1 18 0 0 0 0 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 "Title" 0 18 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 1 0 0 0 0 0 0 }3 0 0 -1 12 12 0 0 0 0 0 0 19 0 }{PSTYLE "Author" 0 19 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 8 8 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 49 "NUMERICAL APPROXIMATION I I--IMPROVED EULER METHOD" }}{PARA 19 "" 0 "" {TEXT -1 12 "by Dr. Fadyn " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } {TEXT 256 147 "We are going to look at ways to implement the improved \+ Euler method in Maple. Assume that we have a first-order initial valu e problem of the form:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 257 0 " " }{XPPEDIT 256 0 "diff(y(t),t) = f(t,y);" "6#/-%%diffG6$-%\"yG6#%\"tG F*-%\"fG6$F*F(" }{TEXT -1 2 " " }{TEXT 257 4 ", y(" }{XPPEDIT 258 0 " t[0];" "6#&%\"tG6#\"\"!" }{TEXT -1 0 "" }{TEXT 259 4 ") = " }{XPPEDIT 260 0 "y[0];" "6#&%\"yG6#\"\"!" }{TEXT -1 1 " " }{TEXT 261 68 ". In t he improved Euler method with step size h, we first compute " } {XPPEDIT 264 0 "u[n] = y[n-1]+h*f(t[n-1],y[n-1]);" "6#/&%\"uG6#%\"nG,& &%\"yG6#,&F'\"\"\"\"\"\"!\"\"F-*&%\"hGF--%\"fG6$&%\"tG6#,&F'F-\"\"\"F/ &F*6#,&F'F-\"\"\"F/F-F-" }{TEXT -1 2 " " }{TEXT 265 36 ". Then the i mproved Euler estimate " }{XPPEDIT 266 0 "y[n];" "6#&%\"yG6#%\"nG" } {TEXT -1 2 " " }{TEXT 267 14 "is given by: " }{XPPEDIT 268 0 "y[n] = y[n-1]+h*[f(t[n-1],y[n-1])+f(t[n],u[n])]/2;" "6#/&%\"yG6#%\"nG,&&F%6# ,&F'\"\"\"\"\"\"!\"\"F,*&*&%\"hGF,7#,&-%\"fG6$&%\"tG6#,&F'F,\"\"\"F.&F %6#,&F'F,\"\"\"F.F,-F56$&F86#F'&%\"uG6#F'F,F,F,\"\"#F.F," }{TEXT -1 2 " " }{TEXT 269 36 ". Recall that h is the step-size , " }{XPPEDIT 257 0 "t[n] = t[0]+n*h;" "6#/&%\"tG6#%\"nG,&&F%6#\"\"!\"\"\"*&F'F,%\"h GF,F," }{TEXT -1 2 " " }{TEXT 258 7 ", and " }{XPPEDIT 259 0 "y[n]; " "6#&%\"yG6#%\"nG" }{TEXT -1 2 " " }{TEXT 260 46 "is the Euler appro ximation to the exact value " }{XPPEDIT 261 0 "y(t[n]);" "6#-%\"yG6#&% \"tG6#%\"nG" }{TEXT -1 1 " " }{TEXT 262 154 ". One way to implement E uler's method in Maple is to define a procedure which will execute the steps for us. Let's consider the initial value problem: " } {XPPEDIT 257 0 "diff(y(t),t) = t*y;" "6#/-%%diffG6$-%\"yG6#%\"tGF**&F* \"\"\"F(F," }{TEXT -1 0 "" }{TEXT 258 146 " , y(0) = 1. The following Maple procedure is adopted from Abell and Braselton. It uses the \"r emember\" option, so that in order to compute, say " }{XPPEDIT 260 0 " y[4];" "6#&%\"yG6#\"\"%" }{TEXT -1 0 "" }{TEXT 259 64 " , Maple does n ot need to recompute all of the preceding values " }{XPPEDIT 262 0 "y[ 3],y[2];" "6$&%\"yG6#\"\"$&F$6#\"\"#" }{TEXT -1 0 "" }{TEXT 261 6 ", a nd " }{XPPEDIT 264 0 "y[1];" "6#&%\"yG6#\"\"\"" }{TEXT -1 0 "" }{TEXT 263 34 ". We will use a step size of 0.1:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 163 "restart:\n f:=( t,y)->t*y:\n h:=0.1:\n t:=n->n*h:\n y:=proc(n) option remember;\n \011y(n-1)+h/2*(f(t(n-1),y(n-1))+\n\011\011f(t(n),y(n-1)+h*f(t(n-1),y( n-1))))\n\011end:\n y(0):=1:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 54 "im peuler:=[seq([t(n),y(n)],n=0..10)]:\narray(impeuler);" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 286 0 "" }{TEXT -1 0 "" }{TEXT 256 530 "A little explanation of the Maple code \+ presented above may be in order. After restarting to clear all previou s definitions of any variables, the first line of the code defines f a s a function of the two variables t and y appropriate to this problem: f(t,y) = t*y. The second line sets the step size as h = 0.1. Line 3 defines t to be a function of n, where t(n) = n*h. The next four lin es define the actual Maple procedure named y, so that y(n) will genera te the improved Euler approximation. It obviously uses the formula for " }{XPPEDIT 258 0 "y[n];" "6#&%\"yG6#%\"nG" }{TEXT -1 0 "" }{TEXT 257 265 " given at the beginning of this worksheet. Next we specify \+ the initial condition y(0) = 1. Then we generate some output from the procedure by using the sequence command \"seq\" and store the results in a variable called \"impeuler\". By the way, we could have used " }{TEXT 291 3 "any" }{TEXT 290 144 " variable name here in place of \"i mpeuler\". Finally, the array command followed by the semicoln displ ays the output in a pleasing column form." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 256 384 "You should also know that Maple has a built-in procedure which implements the improved Euler method. It is an optio n of the dsolve command. We use: type= numeric, method=classical[heu nform], stepsize=h . For the remainder of this worksheet we will use this built-in procedure to generate approximations from the improved \+ Euler method. Here is the example we've been working with:" }}{PARA 0 "" 0 "" {TEXT 292 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "res tart:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "eqn:=diff(y(t),t)= t*y(t);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "h:=0.1;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "solimpeuler:=dsolve(\{eqn,y( 0)=1\},y(t),type=numeric,method=classical[heunform],stepsize=h);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "solimpeuler(0.5);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "for i from 0 to 10 do print \+ (solimpeuler(i/10.)) od;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "Yimpeuler:=c->subs(solimpeuler(c),y(t));" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 50 "for i from 0 to 10 do print (Yimpeuler(i/10.)) od; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 257 73 "Let's look at a plot of the approximate solution g iven by Euler's method:" }}{PARA 0 "" 0 "" {TEXT 294 0 "" }{TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "with(plots):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 86 "pointplot(\{seq([i/10.,Yimpe uler(i/10)],i=0..10)\},style=point,symbol=circle,color=red);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 256 89 "N ow let's see what the exact solution to the I.V.P. looks like (you sho uld already know):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "solexact:=dsolve(\{eqn,y(0)=1\},y(t));" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Yexact:=rhs(solexact);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "for i from 0 to 10 do print( evalf(subs(t=i/10.,Yexact))) od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 256 119 "Now we will look at a graph whi ch compares the exact solution and the approximation generated by usin g Euler's method:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 6 "n:=10;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 96 "pimpeuler:=pointplot(\{seq([i/10.,Yimpeuler(i/10)],i=0..n)\},s tyle=point,symbol=circle,color=red):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "pexact:=plot(Yexact,t=0..n/10,color=black):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "display(\{pimpeuler,pexact\} );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 258 43 "Here are some values of the exact solution:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 69 "for i from 0 to 10 do print ([i/10.,evalf(subs(t=i/10.,Yexact))] ) od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 259 77 "Here is a comparison of Euler's method an d exact values along with the error:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 102 "A:=evalf(seq([i/10,Yimpe uler(i/10),subs(t=i/10,Yexact),subs(t=i/10,Yexact)-Yimpeuler(i/10)],i= 0..10)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "B:=[[t,ImpEuler ,Exact,Error],A]:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "array(B );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 299 139 "It is instructive to compare these results wit h results obtained from Euler's method. Here is Euler's method applie d to this same problem:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "eqn:=diff(y(t),t)=t*y(t);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "h:=0.1;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 87 "soleuler:=dsolve(\{eqn,y(0)=1\},y(t),type=num eric,method=classical[foreuler],stepsize=h);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "soleuler(0.5);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "for i from 0 to 10 do print (soleuler(i/10.)) od;" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 44 "Yeuler:=ceuler->subs(soleul er(ceuler),y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "for i \+ from 0 to 10 do print (Yeuler(i/10.)) od;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 300 165 "First le t's compare the plots. Euler's method points are the blue boxes, impr oved Euler's method points are the red circles. The exact solution is the black curve:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 88 "peuler:=pointplot(\{seq([i/10.,Yeuler(i/10)] ,i=0..n)\},style=point,symbol=box,color=blue):" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 96 "pimpeuler:=pointplot(\{seq([i/10.,Yimpeuler(i/ 10)],i=0..n)\},style=point,symbol=circle,color=red):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "pexact:=plot(Yexact,t=0..n/10,color=black ):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "display(\{peuler,pimpeuler,pexact\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 301 117 "So the improved Euler method does actually produce an improve ment in this problem! Now lets look at a table of data:" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 148 "A:= evalf(seq([i/10,Yeuler(i/10),Yimpeuler(i/10),subs(t=i/10,Yexact),subs( t=i/10,Yexact)-Yeuler(i/10),subs(t=i/10,Yexact)-Yimpeuler(i/10)],i=0.. 10)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "B:=[[t,Euler,ImpEu ler,Exact,EulerError,ImpEulerError],A]:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "array(B);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } {TEXT 302 668 "As you can see, the improvement is dramatic in this cas e. Of course you might argue that the improved Euler method with h=0. 1 in this problem requires 20 function evaluations whereas the Euler m ethod only requires 10, so for extra work you expect improved results. This is quite true. However as we will show below, the improved Eul er method with h=0.1 is actually more accurate (in this problem) than \+ the Euler method with h=0.001. The Euler method with h=0.001 requires 1000 function evaluations! So the improved Euler method with h=0.1 p rovides greater accuracy with only about 2% of the work of Euler's met hod. Let's verify that these statements are correct:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "h:=0.001; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "soleuler001:=dsolve(\{e qn,y(0)=1\},y(t),type=numeric,method=classical[foreuler],stepsize=h); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "Yeuler001:=ceuler->subs (soleuler001(ceuler),y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 154 "A:=evalf(seq([i/10,Yeuler001(i/10),Yimpeuler(i/10),subs(t=i/10,Ye xact),subs(t=i/10,Yexact)-Yeuler001(i/10),subs(t=i/10,Yexact)-Yimpeule r(i/10)],i=0..10)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 63 "B:=[ [t,Euler001,ImpEuler,Exact,Euler001Error,ImpEulerError],A]:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "array(B);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 303 51 "Next we'll look at the new initia l value problem: " }{XPPEDIT 257 0 "diff(y(t),t) = y*cos(t);" "6#/-%% diffG6$-%\"yG6#%\"tGF**&F(\"\"\"-%$cosG6#F*F," }{TEXT -1 1 " " }{TEXT 258 110 ", y(0) = 1. We'll apply both Euler's method and the improved Euler method with h=0.1 and compare the results." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "eqn:=diff(y (t),t)=y(t)*cos(t);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "h:=0. 1;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 87 "soleuler:=dsolve(\{eq n,y(0)=1\},y(t),type=numeric,method=classical[foreuler],stepsize=h);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "solimpeuler:=dsolve(\{eqn ,y(0)=1\},y(t),type=numeric,method=classical[heunform],stepsize=h);" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "Yeuler:=c->subs(soleuler(c ),y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "Yimpeuler:=d->s ubs(solimpeuler(d),y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "solexact:=dsolve(\{eqn,y(0)=1\},y(t));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 256 168 "That las t command above told Maple to find the exact solution. By the way, yo u should be able to verify the result and find the exact solution usin g hand calculations." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Yexact:=rhs(solexact);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 256 169 "The next command will define a function \"Yexactf\" which is just the exact solution function of the differential equation. We do this by using Maple's \"unapply\" command:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "Yexactf:=unapply(Yexact,t);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "Yexactf(1.0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 258 419 "The graphs whi ch follow will point out the inadequacy of Euler's method with stepsi ze 0.1 on this problem. On the other hand, the improved Euler method \+ points seem to follow the periodic solution curve quite well even for \+ values of t which are quite far away from the initial point t=0. T he Euler points are the blue boxes and the improved Euler points are t he red circles. The exact solution is the black curve." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "n:=200; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 88 "peuler:=pointplot(\{seq ([i/10.,Yeuler(i/10)],i=0..n)\},style=point,symbol=box,color=blue):" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 96 "pimpeuler:=pointplot(\{seq ([i/10.,Yimpeuler(i/10)],i=0..n)\},style=point,symbol=circle,color=red ):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "pexact:=plot(Yexact,t =0..n/10,color=black):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "d isplay(\{peuler,pimpeuler,pexact\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "n:=400;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 88 " peuler:=pointplot(\{seq([i/10.,Yeuler(i/10)],i=0..n)\},style=point,sym bol=box,color=blue):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 96 "pim peuler:=pointplot(\{seq([i/10.,Yimpeuler(i/10)],i=0..n)\},style=point, symbol=circle,color=red):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "pexact:=plot(Yexact,t=0..n/10,color=black):" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 35 "display(\{peuler,pimpeuler,pexact\});" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 312 0 "" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }{TEXT 313 39 "Next let's look at some numerical data: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 140 "A:=evalf(seq([5*i,Yeuler(5*i),Yimpeuler(5*i),subs(t= 5*i,Yexact),subs(t=5*i,Yexact)-Yeuler(5*i),subs(t=5*i,Yexact)-Yimpeule r(5*i)],i=0..10)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "B:=[[ t,Euler,ImpEuler,Exact,EulerError,ImpEulerError],A]:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "array(B);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }{TEXT 314 712 "Observe that in this table the Eu ler error is erratic (ranging from a low of about 0.032 to a high of a bout 1.58 for the sampled points) but generally seems to be getting wo rse as t increases. For most values of t larger than about 10 or 15 t he approximation seems to be quite poor. On the other hand the improv ed Euler error, although still a bit erratic, never exceeds about 0.00 57 in absolute value for the sampled points. Of course you should rea lize that we haven't actually established bounds for the errors here s ince we've just sampled ten of the available 5000 approximations. How ever, the graphical and numerical evidence presented above should conv ince you that the improved Euler method actually " }{TEXT 315 2 "is" } {TEXT 316 24 " quite an improvement! " }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 317 737 "One final note...The re are many other numerical methods that are considerably more accurat e than the improved Euler method. The improved Euler method may simpl y take too many steps in certain problems to achieve a high degree of \+ accuracy. One such method easily accessible to undergraduate mathemati cs students is the Runge-Kutta method. You'll surely find some materia l in your textbook on this method. In addition, improved methods cont inue to be discovered. For example if no \"method\" option is specif ied in Maple's numeric dsolve, Maple uses a default \"method=rkf45, wh ich is a Fehlberg fourth-fifth order Runge-Kutta method\", according t o Maple \"help\". This method was published in 1971. The reference g iven in Maple help is: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 23 250 " Subroutine RKF45 appearing in \"Computer Method s for Mathematical\n Computations\" by G.E. Forsythe, M.A. Malcolm, and C.B. Moler.\n \"Numerical Initial Value Problems in Ordinary Di fferential Equations\"\n by C.W. Gear, Prentice-Hall, 1971.\n \"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 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 " " }}}{MARK "91" 0 }{VIEWOPTS 1 1 0 1 1 1803 }