{VERSION 3 0 "SUN SPARC SOLARIS" "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 } {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 "Heading 1" 0 3 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 0 0 0 0 0 0 0 }1 0 0 0 8 4 0 0 0 0 0 0 -1 0 }{PSTYLE "" 3 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 "" 3 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 }} {SECT 0 {PARA 256 "" 0 "" {TEXT -1 28 "Section 8.1 - Euler's Method" } }{PARA 257 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 78 "Here i s a procedure for using the Euler method. It takes as input a functio n " }{XPPEDIT 18 0 "f(t,y);" "6#-%\"fG6$%\"tG%\"yG" }{TEXT -1 0 "" } {TEXT -1 19 ", an initial value " }{XPPEDIT 18 0 "y[0];" "6#&%\"yG6#\" \"!" }{TEXT -1 0 "" }{TEXT -1 5 " for " }{XPPEDIT 18 0 "y;" "6#%\"yG" }{TEXT -1 0 "" }{TEXT -1 18 ", an initial time " }{XPPEDIT 18 0 "t[0]; " "6#&%\"tG6#\"\"!" }{TEXT -1 1 " " }{TEXT -1 4 "(so " }{XPPEDIT 18 0 "y(t[0]) = y[0];" "6#/-%\"yG6#&%\"tG6#\"\"!&F%6#F*" }{TEXT -1 0 "" } {TEXT -1 15 "), a step size " }{XPPEDIT 18 0 "h;" "6#%\"hG" }{TEXT -1 0 "" }{TEXT -1 20 ", a number of steps " }{XPPEDIT 18 0 "n;" "6#%\"nG " }{TEXT -1 0 "" }{TEXT -1 15 ", and a number " }{XPPEDIT 18 0 "m;" "6 #%\"mG" }{TEXT -1 0 "" }{TEXT -1 35 " so that results are printed ever y " }{TEXT -1 0 "" }{TEXT -1 93 " steps. This procedure is a bit diff erent from the one in Differential Equations with Maple." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 " eule r_method := proc(f,y0,t0,h,n,m)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 248 " y(t0) := evalf(y0);\n for i from 1 to n\n do\n \+ y(t0+i*h) := y(t0+(i-1)*h)+ h*f(t0+(i-1)*h,y(t0+(i-1)*h)); \+ if type(i/m,integer)='true' then \+ print(t0+i*h,y(t0+i*h)) fi;\n od;\nend;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 50 "Let's try it on the \+ function in Problem 1, p. 392." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "f := (t,y) -> 2*y-1;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "euler_method(f,1,0,.1,4,1); \n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 " euler_method(f,1,0,. 05,8,2);\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "euler_method( f,1,0,.025,16,4);\n" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 131 "Here is the exact solution. I gave the solution a new \+ name so Maple wouldn't confuse it with the result of the previous calc ulation" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "dsolve(\{diff(z(t),t)=2*z(t)-1,z(0)=1\},z(t));\n" }}} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 26 " I'll ren ame the solution " }{XPPEDIT 18 0 "z;" "6#%\"zG" }{TEXT -1 1 " " } {TEXT -1 12 "(instead of " }{XPPEDIT 18 0 "z(t);" "6#-%\"zG6#%\"tG" } {TEXT -1 0 "" }{TEXT -1 39 ")--this reduces problems evaluating it." } }{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "z := rhs(%);" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 111 " Here is the exact solution evaluated at several point s. Notice that we have to substitute the desired value of" }{XPPEDIT 18 0 "t;" "6#%\"tG" }{TEXT -1 1 " " }{TEXT -1 5 "into " }{XPPEDIT 18 0 "z;" "6#%\"zG" }{TEXT -1 0 "" }{TEXT -1 60 " before evaluating. Als o, we have to use evalf to evaluate " }{XPPEDIT 18 0 "z(t);" "6#-%\"zG 6#%\"tG" }{TEXT -1 1 " " }{TEXT -1 28 "as a floating point number.\n" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "evalf(subs(t=.1,z));\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "evalf(subs(t=.2,z)); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "evalf(subs(t=.3,z));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "evalf(subs(t=.4,z));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" } }}}{MARK "28" 0 }{VIEWOPTS 1 1 0 1 1 1803 }