{VERSION 5 0 "IBM INTEL LINUX" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{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 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 145 "#This worksheet does a simple appr oximation of solutions of a first-order linear\n#differential equation of the for y'=f(x,y) using Euler's method" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 22 "#Enter function below:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 14 "f:=(x,y)->x+y;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 289 "#The following procedure does the actual approximati on. To find an approximate \n#solution of the differential equation\n# y' = f(x,y)\n# \+ y(x0) = y0\n#with stepsize h on the interval [x0, x0+n*h], ent er eulermethod(f, x0, y0, h, n)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 230 "eulermethod:=proc(f, x0, y0, h, n)\n local x, y, i, dydx;\n \+ x:=x0: y:=y0;\n for i from 1 to n do\n dydx:=f(x,y);\n printf( \"Step=%d, x=%6.2f, y=%6.2f, y'=%6.2f\\n\", i-1, x, y, dydx);\n x:= x+h: y:=y+dydx*h;\n od;\n return;\nend;" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 26 "eulermethod(f,0,1,0.2,16);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 82 "#F or your interest, here is the exact solution of the above differential equation:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 42 "dsolve([D(y)( x)=f(x,y(x)), y(0)=1], y(x));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "g:=unapply(op(2,%),x);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 104 "#And for comparison's sake, here is a procedure to print the va lue of this #solution at the same points:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 141 "valuetable:=proc(g, x0, h, n)\n local i;\n for i from 0 to n-1 do\n printf(\"x=%6.2f, y=%6.2f\\n\", x0+i*h, g(x0+ i*h));\n od;\n return;\nend;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "valuetable(g,0,0.2,15);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 204 "#Experiment wit h different functions and stepsizes. Try an initial value which leads \+ to an equilibrium solution. If you are having fun, try a few of the pa thological examples in the exercises in FHMW 1.4." }}}}{MARK "16" 0 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }