{VERSION 1 0 "X11/Motif" "1.0"}{GLOBALS 3 1}{FONT 0 "-adobe-helve
tica-bold-r-normal--*-140-*" "helvetica" "Helvetica-Bold" 8 14 0 
"Helvetica-Bold" 12}{FONT 1 "-adobe-helvetica-medium-r-normal--*-
180-*-*-*-*-*-*" "helvetica" "Helvetica" 4 18 0 "Helvetica" 18}
{FONT 2 "-adobe-courier-medium-r-normal--*-140-*" "courier" "Cour
ier" 4 14 192 "Courier" 12}{SCP_R 1 0 48{COM_R 2 0{TEXT 1 167 "\0
15                             Maple Midterm Project #1\015      \+
                               Euler's Method\015\015(Solving a d
ifferential equation via the direction field.)\015"}}{SEP_R 3 0}
{COM_R 4 0{TEXT 1 48 "\015First, re-initialize all variables in M
aple...\015"}}{INP_R 5 0 "> "{TEXT 0 9 "restart;\012"}}{SEP_R 6 0
}{COM_R 7 0{TEXT 1 154 "\015Part a) Write a Maple Program which t
akes a given function f, \015initial conditions, and h,\012and th
en generates a sequence of points, \015which it then plots.\015"}
}{SEP_R 8 0}{COM_R 9 0{TEXT 1 32 "\015Given a differential equati
on:\015"}}{INP_R 10 0 "> "{TEXT 0 25 "diff ( y(x), x) = f(x,y);"}
}{OUT_R 11 0 10{DAG =3(3n4\`diff`,3(3n3\`y`,2n3\`x`pA(3n3\`f`,3pA
p7}}{COM_R 12 0{TEXT 1 24 "and initial conditions:\015"}}{INP_R 
13 0 "> "{TEXT 0 11 "y(x0) = y0;"}}{OUT_R 14 0 13{DAG =3(3n3\`y`,
2n3\`x0`n3\`y0`}}{SEP_R 15 0}{COM_R 16 0{TEXT 1 45 "\015Define th
e right hand side of the equation:\015"}}{INP_R 17 0 "> "{TEXT 0 
40 "f := proc (x,y)\012          y;\012      end:\012"}}{SEP_R 18
 0}{COM_R 19 0{TEXT 1 34 "\015Define the number of points, N, \01
5"}}{INP_R 20 0 "> "{TEXT 0 10 "N := 100:\012"}}{COM_R 21 0{TEXT 
1 21 "and the stepsize, h:\015"}}{INP_R 22 0 "> "{TEXT 0 11 "h :=
 0.01:\012"}}{SEP_R 23 0}{COM_R 24 0{TEXT 1 42 "\015Define the in
itial conditions\015x0 and y0:\015"}}{INP_R 25 0 "> "{TEXT 0 18 "
x0 := 0:\012y0 := 1:\012"}}{SEP_R 26 0}{COM_R 27 0{TEXT 1 49 "\01
5Set x[0] and y[0] to be the initial conditions:\015"}}{INP_R 28 
0 "> "{TEXT 0 24 "x[0] := x0:\012y[0] := y0:\012"}}{SEP_R 29 0}
{COM_R 30 0{TEXT 1 36 "\015Now begin loop for \015x[n] and y[n]:\
015"}}{INP_R 31 0 "> "{TEXT 0 84 "for n from 0 to N do\012   x[n+
1] := x[n] + h;\012   y[n+1] := y[n] + h*f(x[n],y[n]);\012od:\012
"}}{SEP_R 32 0}{COM_R 33 0{TEXT 1 27 "\015Finally, plot the point
s:\015"}}{INP_R 34 0 "> "{TEXT 0 46 "pts := [ [ x[i], y[i] ] $i=0
..N ]:\012plot(pts);\012"}}{SEP_R 35 0}{COM_R 36 0{TEXT 1 124 "\0
15Part b) Calculate the error, and investigate how it depends on \+
initial\015conditions, f, and h.\015\015Define the solution, yexa
ct,\015"}}{INP_R 37 0 "> "{TEXT 0 22 "yexact := x -> exp(x);"}}
{OUT_R 38 0 37{DAG :3n4\`yexact`n3\`exp`}}{SEP_R 39 0}{COM_R 40 0
{TEXT 1 22 "\015Calculate the error:\015"}}{INP_R 41 0 "> "{TEXT 
0 60 "for n from 0 to N do\012   error[n] := yexact(x[n]) - y[n];
\012od:"}}{COM_R 42 0{TEXT 1 0 ""}}{SEP_R 43 0}{COM_R 44 0{TEXT 1
 25 "\015Graph the error, vs. x:\015"}}{INP_R 45 0 "> "{TEXT 0 69
 "err := [ [ x[i], error[i] ] $i=0..N ]:\012plot(err,title=`error
 vs x`);\012"}}{SEP_R 46 0}{COM_R 47 0{TEXT 1 36 "\015Graph the l
og of the error, vs. x:\015"}}{INP_R 48 0 "> "{TEXT 0 89 "logerr \+
:= [ [ x[i], log(abs(error[i])) ] $i=1..N ]:\012plot(logerr,title
=`log error vs x`);\012"}}{SEP_R 49 0}}{END}
