{VERSION 4 0 "IBM INTEL NT" "4.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 227 " # Warning: These s nips of code made for y'=1-x-y, y(0)=3.\n # Code computes app rox values for y(0.1) to y(1.0).\n # 'Dots' is the list of dots for co nnect-the-dots graphics.\n # ======================================== \n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 93 "# Euler. Group 1, in itialize.\n f:=(x,y)->1-x-y:\n x0:=0:y0:=3:h:=0.1:Dots:=[x0,y0]:n:=2 00:\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 127 "# Group 2, repea t n times. Euler's method\n for i from 1 to n do\n Y:=y0+h*f(x0,y0); \n x0:=x0+h:y0:=Y:Dots:=Dots,[x0,y0];\n od:\n " }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 330 "# Group 3, display relevant dots and plot.\n \+ Exact:=x->2-x+exp(-x);m:=40:\n P:=unapply(evalf(100*abs(exact-approx )/abs(exact)),(exact,approx)):\n print(\"Dots\"),seq(Dots[1+m*j],j=1. .n/m);\n print(\"Exact\"),seq(Exact(Dots[1+m*j][1]),j=0..n/m);\n pri nt(\"Error\"),seq(P(Exact(Dots[1+m*j][1]),Dots[1+m*j][2]),j=0..n/m);\n plot([Dots]);\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 136 "# == ======================================\n # Heun. Group 1, initialize. \n f:=(x,y)->1-x-y:\n x0:=0:y0:=3:h:=0.1:Dots:=[x0,y0]:n:=200:\n " } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 161 "# Group 2, repeat n times . Heun method.\n for i from 1 to n do\n Y1:=y0+h*f(x0,y0);\n Y:=y0+h *(f(x0,y0)+f(x0+h,Y1))/2:\n x0:=x0+h:y0:=Y:Dots:=Dots,[x0,y0];\n od: \n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 108 "# Group 3, display \+ relevant dots and plot.\n Dots[1],Dots[2],seq(Dots[1+40*j],j=1..n/40) ;\n plot([Dots]);\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 135 "# ========================================\n # RK4. Group 1, initiali ze.\n f:=(x,y)->1-x-y:\n x0:=0:y0:=3:h:=0.1:Dots:=[x0,y0]:n:=100:\n \+ " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 228 "# Group 2, repeat n ti mes. RK4 method.\n for i from 1 to n do\n k1:=h*f(x0,y0):\n k2:=h*f( x0+h/2,y0+k1/2):\n k3:=h*f(x0+h/2,y0+k2/2):\n k4:=h*f(x0+h,y0+k3):\n Y:=y0+(k1+2*k2+2*k3+k4)/6:\n x0:=x0+h:y0:=Y:Dots:=Dots,[x0,y0];\n o d:\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 86 "# Group 3, display some dots and plot.\n Dots[1],Dots[2],Dots[101];\n plot([Dots]);\n \n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 297 "# Code snips for ex act/error reports\n # =========================================\n # Ma king multiple curves on one plot\n # ================================= =======\n Exact:=x->2-x+exp(-x); # An exact solution\n \+ plot(\{Exact(x),[Dots]\},x=0..1/2); # plot exact and approx soluti ons\n\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 234 " # ============ ============================\n # How to create a Dots table for the ex act solution\n # ========================================\n Exact:= x \+ -> 2-x+exp(-x):n:=10:\n ExactDots:=seq([Dots[j][1],Exact(Dots[j][1])], j=1..n+1);\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 416 "# ===== ===================================\n # How to define and print percen tage relative error:\n # ========================================\n \+ P:=unapply(evalf(100*abs(exact-approx)/abs(exact)),(exact,approx));\n \+ ExactVal:=ExactDots[11][2]: # Pick off exact y-value for x=0.5\n \+ ApproxVal:=Dots[11][2]: # Get Euler approx y-value for x=0.5\n \+ P(ExactVal),ApproxVal); # print percent relative error\n\n " } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 278 "# ======================= =================\n # How to create a Dots table for percentage error \n # ========================================\n P:=unapply(evalf(100 *abs(exact-approx)/abs(exact)),(exact,approx));\n Pdots:=seq([Dots[j ][1],P(ExactDots[j][2],Dots[j][2])],j=1..11);\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 270 "# ======================================== =\n # Printing results and tables\n # Make tables with a pencil, it sa ves time.\n # ========================================\n # To extract \+ and print items 1,101,201,1001 from a list:\n Dots1:=Dots[1],Dots[101] ,Dots[201],Dots[1001];\n" }}}}{MARK "14 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }