{VERSION 2 3 "DEC ALPHA UNIX" "2.3" }
{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 Input" 2 19 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 }
{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 14 0 0 0 0 2 2 2 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 6 6 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 "R3 Font 0"
-1 256 1 {CSTYLE "" -1 -1 "Helvetica" 1 14 0 0 0 0 2 1 2 0 0 0 0 0 0 }
0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "R3 Font 2" -1 257 1 {CSTYLE
"" -1 -1 "Courier" 1 14 0 0 0 0 2 2 2 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0
0 0 0 0 -1 0 }{PSTYLE "R3 Font 3" -1 258 1 {CSTYLE "" -1 -1 "Courier"
1 16 0 0 0 0 2 2 2 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }
{PSTYLE "R3 Font 4" -1 259 1 {CSTYLE "" -1 -1 "Courier" 1 16 0 0 0 0
2 1 2 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }}
{SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 24 "Simple Numerical Methods
" }}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 12 "Introduction" }}{PARA 0 ""
0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 339 "This worksheet show
s how to use Maple to run really simple numerical methods for approxim
ating solutions to ordinary differential equations. It is an almost c
riminal misuse of Maple's power. On the other hand, it takes the drud
gery out of the usual pencil and paper introductions to numerical meth
ods, while keeping the key steps clear. " }}{PARA 0 "" 0 "" {TEXT -1
0 "" }}{PARA 0 "" 0 "" {TEXT -1 20 "Filename: euler1.ms" }}}{SECT 0
{PARA 3 "" 0 "" {TEXT -1 7 "Example" }}{PARA 0 "" 0 "" {TEXT -1 73 "St
art with a simple example. We are going to approximate the solution to
" }{XPPEDIT 19 1 "dy/dx + 2*y = cos(x)" "/,&*&%#dyG\"\"\"%#dxG!\"\"F&
*&\"\"#F&%\"yGF&F&-%$cosG6#%\"xG" }{TEXT -1 31 " starting at the initi
al point " }{XPPEDIT 19 1 "y(0) = -4" "/-%\"yG6#\"\"!,$\"\"%!\"\"" }
{TEXT -1 1 "." }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 49 "Start by defining
the righthand side of the ODE. " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 27
"f := (x,y) -> cos(x) - 2*y;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 27 "D
efine the initial point. " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "x[0] \+
:= 0; y[0] := -4;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 65 "Choose the \+
stepsize and the number of steps for Euler's method. " }}{PARA 0 "> \+
" 0 "" {MPLTEXT 1 0 19 "h := 0.2; N := 10;" }}}{PARA 0 "" 0 "" {TEXT
-1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 50 "Here's the Maple impleme
ntation of Euler's method." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 275 "eule
r_pts := [ x[0], y[0] ]:\nfor n from 0 to N-1 do\n x[n+1] := x[n] + \+
h;\n y[n+1] := y[n] + h*f(x[n],y[n]);\n new_pt := [ x[n+1], y[n+1] ]
;\n euler_pts := euler_pts, new_pt;\n print( new_pt );\nod:\neuler_p
lot := plot( [euler_pts], style=POINT, color=GREEN, symbol=DIAMOND ):
" }}{PARA 0 "" 0 "" {TEXT -1 99 "Note that the solution points will ap
pear as green diamonds when we display the plot in a minute. " }}}
{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 176 "F
or this problem, you can find the exact solution and then compare the \+
exact solution with the Euler approximation obtained above. We'll us
e dsolve to generate the solution. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }
}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "ode1 := diff(Y(t),t) = f(t,Y(t));
" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "sol1 := dsolve(\{ode1,Y
(0)=-4\},Y(t));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "exact_so
l1 := rhs(sol1);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "exact_p
lot := plot( exact_sol1, t=0..2):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}
{PARA 0 "" 0 "" {TEXT -1 164 "You have stored the plot for the exact s
olution in exact_plot and the plot for the Euler approximation in eule
r_plot. Now use the display command to look at them. " }}}{PARA 0 ""
0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 ">
" 0 "" {MPLTEXT 1 0 12 "with(plots):" }}{PARA 0 "> " 0 "" {MPLTEXT 1
0 101 "display( \{euler_plot,exact_plot\},\n title=`Exac
t Solution and the Euler Approximation`);" }}}{PARA 0 "" 0 "" {TEXT
-1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 205 "Just for fun, take a look at w
hat happens when you do the approximation on a longer interval. Not
e that I removed the print command from the Euler block so that I don'
t have to read all of the points. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }
}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "N := 100;" }}}{EXCHG {PARA
0 "> " 0 "" {MPLTEXT 1 0 256 "euler_pts := [ x[0], y[0] ]:\nfor n fro
m 0 to N-1 do\n x[n+1] := x[n] + h;\n y[n+1] := y[n] + h*f(x[n],y[n]
);\n new_pt := [ x[n+1], y[n+1] ];\n euler_pts := euler_pts, new_pt;
\nod:\neuler_plot := plot( [euler_pts], style=POINT, color=GREEN, symb
ol=DIAMOND ):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "exact_plot
:= plot( exact_sol1, t=0..20):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT
1 0 114 "with(plots):display( \{euler_plot,exact_plot\},\n \+
title=`Exact Solution and the Euler Approximation`);\n" }}{PARA 0 "
" 0 "" {TEXT -1 58 "It's a pretty good approximation for such a simple
method!" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{EXCHG {PARA 0 "" 0 ""
{TEXT -1 28 "END OF WORKSHEET: euler1.ms" }}}}{MARK "3 0 0" 14 }
{VIEWOPTS 1 1 0 1 1 1803 }