{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 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 "" -1 258 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 259 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 260 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE " " 18 261 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 262 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 263 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 264 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" 18 265 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 266 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 267 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 268 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 269 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE " " -1 270 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 271 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 272 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 273 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 274 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 275 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 276 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 277 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 278 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE " " 18 279 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 280 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 281 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 282 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 } {CSTYLE "" 18 283 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 284 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 285 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 286 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 287 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE " " -1 288 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" 18 289 "" 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 "" 18 291 "" 1 18 0 0 0 0 0 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 "" 18 293 "" 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 "" 18 295 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 296 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE " " -1 297 "" 1 18 0 0 0 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 298 "" 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 }{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 39 "NUMERICAL APPROXIMATION: \+ EULER'S METHOD" }}{PARA 19 "" 0 "" {TEXT -1 12 "by Dr. Fadyn" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 258 228 "This worksheet shows how Euler's method for obtaining an approxim ate numerical solution to a first-order differential equation can be i mplemented in Maple. We assume that we have a first-order initial val ue problem of the form " }{XPPEDIT 259 0 "diff(y(t),t) = f(t,y);" "6#/ -%%diffG6$-%\"yG6#%\"tGF*-%\"fG6$F*F(" }{TEXT -1 2 " " }{TEXT 260 4 " , y(" }{XPPEDIT 261 0 "t[0];" "6#&%\"tG6#\"\"!" }{TEXT -1 0 "" }{TEXT 262 4 ") = " }{XPPEDIT 263 0 "y[0];" "6#&%\"yG6#\"\"!" }{TEXT -1 1 " \+ " }{TEXT 264 43 ". Recall that Euler's method says that: " } {XPPEDIT 265 0 "y[n];" "6#&%\"yG6#%\"nG" }{TEXT -1 2 " " }{TEXT 266 3 "= " }{XPPEDIT 267 0 "h*f(t[n-1],y[n-1])+y[n-1];" "6#,&*&%\"hG\"\" \"-%\"fG6$&%\"tG6#,&%\"nGF&\"\"\"!\"\"&%\"yG6#,&F.F&\"\"\"F0F&F&&F26#, &F.F&\"\"\"F0F&" }{TEXT -1 2 " " }{TEXT 268 32 ", where h is the \"s tep-size\" , " }{XPPEDIT 269 0 "t[n] = t[0]+n*h;" "6#/&%\"tG6#%\"nG,&& F%6#\"\"!\"\"\"*&F'F,%\"hGF,F," }{TEXT -1 2 " " }{TEXT 270 7 ", and \+ " }{XPPEDIT 271 0 "y[n];" "6#&%\"yG6#%\"nG" }{TEXT -1 2 " " }{TEXT 272 46 "is the Euler approximation to the exact value " }{XPPEDIT 273 0 "y(t[n]);" "6#-%\"yG6#&%\"tG6#%\"nG" }{TEXT -1 1 " " }{TEXT 274 154 ". One way to implement Euler's method in Maple is to define a proced ure which will execute the steps for us. Let's consider the initial v alue problem: " }{XPPEDIT 275 0 "diff(y(t),t) = t*y;" "6#/-%%diffG6$- %\"yG6#%\"tGF**&F*\"\"\"F(F," }{TEXT -1 0 "" }{TEXT 276 146 " , y(0) = 1. The following Maple procedure is adopted from Abell and Braselton . It uses the \"remember\" option, so that in order to compute, say \+ " }{XPPEDIT 279 0 "y[4];" "6#&%\"yG6#\"\"%" }{TEXT -1 0 "" }{TEXT 278 64 " , Maple does not need to recompute all of the preceding values " }{XPPEDIT 281 0 "y[3],y[2];" "6$&%\"yG6#\"\"$&F$6#\"\"#" }{TEXT -1 0 " " }{TEXT 280 6 ", and " }{XPPEDIT 283 0 "y[1];" "6#&%\"yG6#\"\"\"" } {TEXT -1 0 "" }{TEXT 282 34 ". We will use a step size of 0.1:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 111 "f:=(t,y)->t*y:\n h:=0.1:\n t:=n->n*h:\n y:=proc(n) option re member;\n\011y(n-1)+h*f(t(n-1),y(n-1))\n\011end:\n y(0):=1:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "eulr:=[seq([t(n),y(n)],n=0.. 10)]:array(eulr);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 284 459 " A little explanation of the Maple code presented above may be in order . The first line of the code defines f as a function of the two variab les t and y appropriate to this problem: f(t,y) = t*y. The second lin e sets the step size as h = 0.1. Line 3 defines t to be a function of n, and defines t(n) = n*h. The next three lines define the actual Ma ple procedure named y, so that y(n) will generate the Euler approximat ion. It obviously uses the formula for " }{XPPEDIT 286 0 "y[n];" "6#&% \"yG6#%\"nG" }{TEXT -1 0 "" }{TEXT 285 276 " given at the beginning of this worksheet. Next we define the initial condition y(0) = 1. Next we generate some output from the procedure by using the sequence comm and, seq. Finally, the array command followed by the semicoln displa ys the output in a pleasing column form." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 277 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 287 360 "You should also know that Mapl e has a built-in procedure which implements Euler's method. It is an \+ option of the dsolve command. We use: type= numeric, method=classica l[foreuler], stepsize=h . For the remainder of this worksheet we wil l use this built-in procedure to generate approximations from Euler's \+ method. Here is the example we've been working on:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }} }{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 =numeric,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 257 73 "Let's loo k at a plot of the approximate solution given by Euler's method:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "with(plots):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 83 "point plot(\{seq([i/10.,Yeuler(i/10)],i=0..10)\},style=point,symbol=circle,c olor=red);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 256 89 "Now let's see what the exact solution to the I.V.P. look s like (you should 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(s olexact);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "for i from 0 t o 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 which compares the exact solution and the approximation gen erated by using 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 90 "peuler:=pointplot(\{seq([i/10.,Yeuler(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 25 "display(\{peuler,pexact\}) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 302 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 303 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 96 "A:=evalf(seq([i/10,Yeuler (i/10),subs(t=i/10,Yexact),subs(t=i/10,Yexact)-Yeuler(i/10)],i=0..10)) :" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "B:=[[t,Euler,Exact,Err or],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 298 152 "Let's continue our analysis of this problem by halving \+ the step size several times. First, let's use h = 0.05 and name the r esulting output soleuler05:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "h:=0.05;" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 89 "soleuler05:=dsolve(\{eqn,y(0)=1\},y(t),type= numeric,method=classical[foreuler],stepsize=h);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 51 "for i from 0 to 10 do print (soleuler05(i/10.) ) od;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "Yeuler05:=ceuler-> subs(soleuler05(ceuler),y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "for i from 0 to 10 do print (Yeuler05(i/10.)) od;" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 78 "A:=e valf(seq([i/10,Yeuler(i/10),Yeuler05(i/10),subs(t=i/10,Yexact)],i=0..1 0)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "B:=[[t,Euler1,Euler 05,Exact],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 56 "Now let's use h = 0.025 and call the result soleuler0 25:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "h:=0.025;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "soleuler025:=dsolve(\{eqn,y(0)=1\},y(t),t ype=numeric,method=classical[foreuler],stepsize=h);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "for i from 0 to 10 do print (soleuler025( i/10.)) od;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "Yeuler025:=c euler->subs(soleuler025(ceuler),y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "for i from 0 to 10 do print (Yeuler025(i/10.)) od;" } }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 94 "A:=evalf(seq([i/10,Yeuler(i/10),Yeuler05(i/10),Yeuler025(i/10),s ubs(t=i/10,Yexact)],i=0..10)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "B:=[[t,Euler1,Euler05,Euler025,Exact],A]:" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 9 "array(B);" }}}{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 -1 0 "" }{TEXT 300 92 "Finally, \+ let's half the step size again and use h = 0.0125 and name the output \+ soleuler0125:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "h:=0.0125;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 91 "soleuler0125:=dsolve(\{eqn,y(0)=1\},y(t),type=numeric ,method=classical[foreuler],stepsize=h);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "for i from 0 to 10 do print (soleuler0125(i/10.)) od; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "Yeuler0125:=ceuler->sub s(soleuler0125(ceuler),y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "for i from 0 to 10 do print (Yeuler0125(i/10.)) od;" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 111 "A:= evalf(seq([i/10,Yeuler(i/10),Yeuler05(i/10),Yeuler025(i/10),Yeuler0125 (i/10),subs(t=i/10,Yexact)],i=0..10)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "B:=[[t,Euler1,Euler05,Euler025,Euler0125,Exact],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 301 41 "Next we'll look at a plot of our results:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 6 "n:=10;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "peuler:=pointplot(\{seq([i/10.,Yeuler(i/10)],i=0..n) \},style=point,symbol=circle,color=red):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 94 "peuler05:=pointplot(\{seq([i/10.,Yeuler05(i/10)],i=0. .n)\},style=point,symbol=cross,color=blue):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 97 "peuler025:=pointplot(\{seq([i/10.,Yeuler025(i/10)] ,i=0..n)\},style=point,symbol=box,color=magenta):" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 102 "peuler0125:=pointplot(\{seq([i/10.,Yeuler01 25(i/10)],i=0..n)\},style=point,symbol=diamond,color=orange):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "pexact:=plot(Yexact,t=0..n/1 0,color=black):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "display( \{peuler,peuler05,peuler025,peuler0125,pexact\});" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }{TEXT 288 86 "Our first example above p ainted a rosy picture of Euler's method. At every value of " } {XPPEDIT 289 0 "t[n];" "6#&%\"tG6#%\"nG" }{TEXT -1 3 " " }{TEXT 290 141 "in our table, decreasing the step size h reduced the error in the approximation so much so that it appears that as h decreases the valu e of " }{XPPEDIT 291 0 "t[n];" "6#&%\"tG6#%\"nG" }{TEXT -1 2 " " } {TEXT 292 34 "seems to approach the exact value " }{XPPEDIT 293 0 "y(t [n]);" "6#-%\"yG6#&%\"tG6#%\"nG" }{TEXT -1 1 " " }{TEXT 294 143 ". Ho wever, it is not difficult to find examples where Euler's method prove s to be inadequate. Let's consider next the initial value problem " }{XPPEDIT 295 0 "diff(y(t),t) = y*cos(t);" "6#/-%%diffG6$-%\"yG6#%\"tG F**&F(\"\"\"-%$cosG6#F*F," }{TEXT -1 1 " " }{TEXT 296 11 ", y(0) = 1: " }}{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(\{eqn,y(0)=1\},y(t),type=numeric,method=class ical[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(soleuler(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 "" {MPLTEXT 1 0 12 "wit h(plots):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 84 "pointplot(\{se q([i/10.,Yeuler(i/10)],i=0..200)\},style=point,symbol=circle,color=red );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "solexact:=dsolve(\{eq n,y(0)=1\},y(t));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }{TEXT 256 168 "That last command above told Mapl e to find the exact solution. By the way, you should be able to verif y the result and find the exact solution using hand calculations." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{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 -1 0 "" }{TEXT 257 169 "The next command will define a function \"Yexactf\" wh ich is just the exact solution function of the differential equation. \+ We do this by using Maple's \"unapply\" command:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "Yexactf:=un apply(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 107 "The graphs which follow will point out t he inadequacy of Euler's method with stepsize 0.1 on this problem." } }{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "n:=200;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "peuler:=poi ntplot(\{seq([i/10.,Yeuler(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 25 "display(\{peuler,pexact\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "n:=400;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 " peuler:=pointplot(\{seq([i/10.,Yeuler(i/10)],i=0..n)\},style=point,sym bol=circle,color=red):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "p exact:=plot(Yexact,t=0..n/10,color=black):" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "display(\{peu ler,pexact\});" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } {TEXT 297 203 "Notice that as we get farther from the initial value t= 0 the approximation gets worse and worse. Decreasing the step size he re will help, but clearly we need to consider more accurate numerical \+ methods." }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{MARK "16 0 0" 49 } {VIEWOPTS 1 1 0 1 1 1803 }