# Code snips for exact/error reports 2.4-#5 # ========================================= # Making multiple curves on one plot # ======================================== Exact:=x->2+x-exp(x); # An exact solution for #5 plot({Exact(x),[Dots]},x=0..1/2); # plot exact and approx solutions # ======================================== # How to create a Dots table for the exact solution # ======================================== Exact:= x -> 2+x-exp(x): ExactDots:=seq([Dots[j][1],Exact(Dots[j][1])],j=1..11); # ======================================== # How to define and print percentage error: # ======================================== Perr:=(exact,approx)->evalf(100*abs(exact-approx)/abs(exact)); ExactVal:=ExactDots[11][2]: # Pick off exact y-value for x=0.5 ApproxVal:=Dots[11][2]: # Get Euler approx y-value for x=0.5 Perr(ExactVal),ApproxVal); # print percent relative error # ======================================== # How to create a Dots table for percentage error # ======================================== Perr:=(exact,approx)->evalf(100*abs(exact-approx)/abs(exact)); PerrDots:=seq([Dots[j][1],Perr(ExactDots[j][2],Dots[j][2])],j=1..11); # ========================================= # Printing results and tables # Make tables with a pencil, it saves time. # ======================================== # To extract and print items 1,101,201,1001 from a list: Dots1:=Dots[1],Dots[101],Dots[201],Dots[1001]; # =========================================