{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 12 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 "Heading 2" 3 4 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0
0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 4 4 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 "He
lvetica" 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 "Times_bolditalic24" 1 24 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 }{PSTYLE "R3 Font 5" -1 260 1 {CSTYLE "
" -1 -1 "Helvetica" 1 12 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 6" -1 261 1 {CSTYLE "" -1 -1 "Helveti
ca" 1 12 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 7" -1 262 1 {CSTYLE "" -1 -1 "Times" 1 12 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 8"
-1 263 1 {CSTYLE "" -1 -1 "Helvetica" 1 12 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 9" -1 264 1 {CSTYLE
"" -1 -1 "Times" 1 12 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 10" -1 265 1 {CSTYLE "" -1 -1 "Helvetica
" 1 12 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 11" -1 266 1 {CSTYLE "" -1 -1 "Helvetica" 1 12 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 {PARA 18 "" 0 "" {TEXT -1 38 "Euler's Method for Second-Order \+
ODE's\n" }}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 12 "Introduction" }}{PARA
0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 271 "You have seen \+
how to use Euler's method to obtain quick approximate solutions for fi
rst-order ordinary differential equations. The method extends easily \+
to second-order equations as soon as you rewrite the second-order equa
tion as a system of two first-order equation. " }}}{SECT 0 {PARA 3 "
" 0 "" {TEXT -1 9 "Examples " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{SECT
0 {PARA 4 "" 0 "" {TEXT -1 10 "EXAMPLE #1" }}{PARA 0 "" 0 "" {TEXT -1
53 "Begin with an example that you know how to solve. \n\n" }
{XPPEDIT 19 1 "d^2 x / dt^2 + 4*x = 0, x(0) = 1, (dx/dt)(0) = 0 " "6
%/,&*(%\"dG\"\"#%\"xG\"\"\"*$%#dtG\"\"#!\"\"F)*&\"\"%F)F(F)F)\"\"!/-F(
6#F0\"\"\"/-*&%#dxGF)F+F-6#F0F0" }{TEXT -1 3 " " }}{PARA 0 "" 0 ""
{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 59 "Start by rewriting this \+
as a system in a standard form\n\n " }{XPPEDIT 19 1 "dx/dt = v(t), \+
dv/dt = -4*x(t)" "6$/*&%#dxG\"\"\"%#dtG!\"\"-%\"vG6#%\"tG/*&%#dvGF&F'F
(,$*&\"\"%F&-%\"xG6#F,F&F(" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0
"" 0 "" {TEXT -1 90 "You can \"standardize\" your solution block by de
fining the righthandside of the equation. " }}{EXCHG {PARA 0 "> " 0 "
" {MPLTEXT 1 0 18 "f := (t,x,v) -> v;" }}}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 23 "g := (t,x,v) -> - 4*x;" }}}{PARA 0 "" 0 "" {TEXT -1
68 "Now add initial conditions, the stepsize, and the number of steps.
" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "t[0] := 0; x[0] := 1;
v[0] := 0;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "h := 0.5; \+
N := 10;" }}}{PARA 0 "" 0 "" {TEXT -1 189 "Here's the Maple implement
ation of Euler's method.\n\nThe solution points will be stored in thre
e vectors. This is useful later on when you want to look at the solut
ion in different ways. \n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0
30 "euler_pts := [ x[0], v[0] ]:" }}}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 30 "euler_ptsx := [ t[0], x[0] ]:" }}}{EXCHG {PARA 0 "> \+
" 0 "" {MPLTEXT 1 0 30 "euler_ptsv := [ t[0], v[0] ]:" }}}{PARA 0 ""
0 "" {TEXT -1 136 "\nNow build the solution one step at a time. Every
step for x and v is just \n\n (new value) = (old value) + (old slo
pe) *(time-step) \n" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "for n
from 0 to N-1 do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 23 " t[n+1] := \+
t[n] + h;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 " x[n+1] := x[n] + h*
f(t[n],x[n],v[n]);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 " v[n+1] := \+
v[n] + h*g(t[n],x[n],v[n]);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " n
ew_pt := [ x[n+1], v[n+1] ]; " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " \+
new_ptx := [ t[n+1], x[n+1] ];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "
new_ptv := [ t[n+1], v[n+1] ];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0
34 " euler_pts := euler_pts, new_pt;" }}{PARA 0 "> " 0 "" {MPLTEXT
1 0 37 " euler_ptsx := euler_ptsx, new_ptx;" }}{PARA 0 "> " 0 ""
{MPLTEXT 1 0 37 " euler_ptsv := euler_ptsv, new_ptv;" }}{PARA 0 "> \+
" 0 "" {MPLTEXT 1 0 3 "od:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{PARA
0 "" 0 "" {TEXT -1 104 " This loop will collect the approximate soluti
on. You can also just print the points now, if you wish: " }}{EXCHG
{PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "print(euler_ptsx);" }}}{PARA 0 ""
0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 34 "Time to start plotti
ng points. . " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> "
0 "" {MPLTEXT 1 0 12 "with(plots):" }}}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 90 "euler_plotx := plot( [euler_ptsx],\n st
yle=POINT, color=RED, symbol=CIRCLE ):" }}}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 60 "display(euler_plotx,title=`Eulers Approximation: Posi
tion`);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 99 "euler_plotv := p
lot( [euler_ptsv],\n style=POINT, color=GREEN, sym
bol=DIAMOND ):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "display(e
uler_plotv,title=`Eulers Approximation: Velocity`);" }}}{PARA 0 "" 0 "
" {TEXT -1 67 "You can plot the solution curve in the phase plane just
as easily. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0
"" {MPLTEXT 1 0 95 "euler_plot := plot( [euler_pts],\n \+
style=POINT, color=RED, symbol=DIAMOND ):" }}}{PARA 0 "" 0 ""
{TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 68 "display(eule
r_plot,title=`Eulers Approximation in the Phase Plane`);" }}}{PARA 0 "
" 0 "" {TEXT -1 174 "Finally, it is interesting to compare the Euler a
pproximation to the exact solution. It is especially interesting beca
use you find that the approximation is not very good. " }}{EXCHG
{PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "exact_plot := plot(cos(2*t),t=0..5)
:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 96 "display(\{exact_plot,e
uler_plotx\},\n title=`Exact Solution and Eulers Approximation: Posi
tion`);" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 25 "Improve the Approxim
ation" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 191
"You get a better approximation by simply adding more points. Decrea
se the stepsize and increase the number of points to get a better grap
h. Remember to reinitialize the solution vectors. " }}{EXCHG {PARA
0 "> " 0 "" {MPLTEXT 1 0 21 "h := 0.05; N := 100;" }}}{EXCHG {PARA 0
"> " 0 "" {MPLTEXT 1 0 30 "euler_pts := [ x[0], v[0] ]:" }}}{EXCHG
{PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "euler_ptsx := [ t[0], x[0] ]:" }}}
{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "euler_ptsv := [ t[0], v[0] \+
]:" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 ""
{MPLTEXT 1 0 22 "for n from 0 to N-1 do" }}{PARA 0 "> " 0 "" {MPLTEXT
1 0 23 " t[n+1] := t[n] + h;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "
x[n+1] := x[n] + h*f(t[n],x[n],v[n]);" }}{PARA 0 "> " 0 ""
{MPLTEXT 1 0 40 " v[n+1] := v[n] + h*g(t[n],x[n],v[n]);" }}{PARA 0 "
> " 0 "" {MPLTEXT 1 0 33 " new_pt := [ x[n+1], v[n+1] ]; " }}{PARA
0 "> " 0 "" {MPLTEXT 1 0 33 " new_ptx := [ t[n+1], x[n+1] ];" }}
{PARA 0 "> " 0 "" {MPLTEXT 1 0 33 " new_ptv := [ t[n+1], v[n+1] ];"
}}{PARA 0 "> " 0 "" {MPLTEXT 1 0 34 " euler_pts := euler_pts, new_pt
;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 37 " euler_ptsx := euler_ptsx, n
ew_ptx;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 37 " euler_ptsv := euler_p
tsv, new_ptv;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 3 "od:" }}{PARA 0 ""
0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "euler_
plotx := plot( [euler_ptsx],\n style=POINT, color=RED, s
ymbol=CIRCLE ):" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> \+
" 0 "" {MPLTEXT 1 0 36 "exact_plot := plot(cos(2*t),t=0..5):" }}}
{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 96 "display(\{exact_plot,euler_p
lotx\},\n title=`Exact Solution and Eulers Approximation: Position`)
;" }}}{PARA 0 "" 0 "" {TEXT -1 250 "Better, but still not great. You
could make the approximation better by adding more points. An alter
native would be to use a better method, something like Heun's method o
r a Runge-Kutta type method. You just have to modify the code a littl
e bit!" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}}{EXCHG
{PARA 0 "" 0 "" {TEXT -1 16 "end of euler2.ms" }}}}{MARK "3 0 0" 5 }
{VIEWOPTS 1 1 0 1 1 1803 }