{VERSION 5 0 "SUN SPARC SOLARIS" "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 442 "#Dr. Gustafson,\n#I am in your 2250-4 class and am continually struggling with the codes \+ for\n#the problems in section 2.4, 2.5, and 2.6. Actually 2.5 (Improv ed Euler)\n#seems to be going pretty well, but I can't get very good \+ results for 2.4\n#(Euler) or 2.6 (Runge-Kutta Idea). Is there a websi te where I may be able\n#to find help and/or codes on these sections, \+ as nothing I type in for my\n#codes will seem to work? Thanks for you r time.\n\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 844 "# ========= ================================\n# Can't copy with the mouse? A work- around:\n# ========================================\n# Run the applica tion \"xclipboard &\" to capture the mouse copies of this\n# file. Kee p xclipboard near the xmaple window. Go to the netscape\n# window, cop y with the mouse. Switch to the xclipboard window. Copy\n# with the mo use from the xclipboard. Then paste with mouse button 2 or\n# mouse bu tton 3 into xmaple.\n# =========================================\n# Ma ple code doesn't work? Read this:\n# ================================= =======\n# To type in a group, hold shift then press return, except\n# for the last line of group, in which case use just return.\n# If you \+ copy multiple groups with the mouse, then split\n# them using key F3 w ith the cursor placed at the front of\n# a line where the split is to \+ happen.\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 314 "# Warning: These snips of code made for y'=1-x-y, y(0)=3.\n# Code compu tes approx values for y(0.1) to y(1.0).\n# 'Dots' is the list of dots \+ for connect-the-dots graphics.\n# ==================================== ====\n# Euler. Group 1, initialize.\n f:=(x,y)->1-x-y:\n x0:=0:y0:=3 :h:=0.1:Dots:=[x0,y0]:n:=10:\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 127 "# Group 2, repeat 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 77 "# Group 3, display dot s and plot.\n seq(Dots[j],j=1..n+1);\n plot([Dots]);\n\n " }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 135 "# ========================= ===============\n # Heun. Group 1, initialize.\n f:=(x,y)->1-x-y:\n \+ x0:=0:y0:=3:h:=0.1:Dots:=[x0,y0]:n:=10:\n " }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 161 "# Group 2, repeat n times. Heun method.\n for i fr om 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 77 "# Group 3, display dots and plot.\n seq(Dots[ j],j=1..n+1);\n plot([Dots]);\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 134 "# ========================================\n # RK4. \+ Group 1, initialize.\n f:=(x,y)->1-x-y:\n x0:=0:y0:=3:h:=0.1:Dots:=[ x0,y0]:n:=10:\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 228 "# Grou p 2, repeat n times. 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:=D ots,[x0,y0];\n od:\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 86 "# \+ Group 3, display some dots and plot.\n Dots[1],Dots[2],Dots[n+1];\n \+ plot([Dots]);\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 315 "# Co de snips for exact/error reports 2.4-#5\n # ========================== ===============\n # Making multiple curves on one plot\n # =========== =============================\n Exact:=x->2+x-exp(x); \+ # An exact solution for 2.4-5\n plot(\{Exact(x),[Dots]\},x=0..1/2); \+ # plot exact and approx solutions\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 232 "# ========================================\n # How t o create a Dots table for the exact 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 percentage 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 E uler approx y-value for x=0.5\n P(ExactVal),ApproxVal); # prin t 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,a pprox));\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 272 "# ========= ================================\n # Printing results and tables\n # M ake tables with a pencil, it saves time.\n # ========================= ===============\n # To extract and print items 1,101,201,1001 from a l ist:\n Dots1:=Dots[1],Dots[101],Dots[201],Dots[1001];\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 333 "# ================================ =========\n # Loop control\n # ======================================= =\n # To automate the production of a Dots list,\n # enclose the desir ed code between 1 and 2 below.\n # 1. for k from 1 to 10 do\n # 2. o d:\n #\n # Keyword \"od:\" is short for \"end do:\"\n # Use \":\" to s top loop results from printing.\n\n " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 387 "# =========================================\n # Debu g\n # ========================================\n # To remove loop cont rol and do it by hand, insert\n # pound (#) signs as follows:\n # 1. \+ # for k from 1 to 10 do\n # 2. # od:\n # The hand-done loop is made b y placing the mouse cursor\n # in the group, then press return. Repeat for each loop step,\n # which is 10 times for the loop above.\n " }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "# the end" }}}}{MARK "7 0 0" 56 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }