"FILE, RIEMANN.MTH" EVAL(y,a):=ITERATE(y,x,a,1) ALL_AUX(l,m,dx):=[l,l+dx,m,l+dx/2,(2*m+l+dx/2)/3] BOX(a,b,c,d):=[[a,0],[a,c],[b,d],[b,0]] BOXES(y,a,b,h,z,w):=[y,VECTOR(BOX(p,p+h,EVAL(y,p+z*h),EVAL(y,p+w*h)),p,a,b-h,h~ )] BASIC(y,a,h,k,n):=h*SUM(EVAL(y,a+i*h),i,k,n) VLINES(y,a,b,h):=VECTOR([i,EVAL(y,i)*t_],i,a,b,h) TOPCURVES(y,a,b,hh):=VECTOR([i+hh*t_,t_*(2*t_-1)*EVAL(y,i+hh)+4*t_*(1-t_)*EVAL~ (y,i+hh/2)+(t_-1)*(2*t_-1)*EVAL(y,i)],i,a,b-hh,hh) "########################" "USER FUNCTIONS" LEFT(y,a,b,n):=BASIC(y,a,(b-a)/n,0,n-1) RIGHT(y,a,b,n):=BASIC(y,a,(b-a)/n,1,n) MID(y,a,b,n):=BASIC(y,a-(b-a)/(2*n),(b-a)/n,1,n) TRAP(y,a,b,n):=(b-a)/(2*n)*(EVAL(y,b)-EVAL(y,a))+LEFT(y,a,b,n) SIMP(y,a,b,n):=(2*MID(y,a,b,n)+TRAP(y,a,b,n))/3 LPIC(y,a,b,n):=BOXES(y,a,b,(b-a)/n,0,0) RPIC(y,a,b,n):=BOXES(y,a,b,(b-a)/n,1,1) MPIC(y,a,b,n):=BOXES(y,a,b,(b-a)/n,1/2,1/2) TPIC(y,a,b,n):=BOXES(y,a,b,(b-a)/n,0,1) ALL(y,a,b,n):=ALL_AUX(LEFT(y,a,b,n),MID(y,a,b,n),(b-a)/n*(EVAL(y,b)-EVAL(y,a))) SPIC(y,a,b,n):=[y,VLINES(y,a,b,(b-a)/n),TOPCURVES(y,a,b,2*(b-a)/n)] "#######################" "INSTRUCTIONS" "LEFT(y,a,b,n) calculates a left-hand Riemann sum" " for y=f(x) on the interval [a,b] using n subintervals" "RIGHT(y,a,b,n) calculates a right-hand sum" "MID(y,a,b,n) calculates the midpoint rule" "TRAP(y,a,b,n) calculates the trapezoidal rule" "SIMP(y,a,b,n) calculates Simpson's rule" "ALL(y,a,b,n) returns [LEFT, RIGHT, MID, TRAP, SIMP]" "" "LPIC(y,a,b,n) makes a picture for LEFT(y,a,b,n)" "RPIC(y,a,b,n) makes a picture for RIGHT(y,a,b,n)" "MPIC(y,a,b,n) makes a picture for MID(y,a,b,n)" "TPIC(y,a,b,n) makes a picture for TRAP(y,a,b,n)" "FOR THE FOUR FUNCTIONS ABOVE, THE GRAPHICS SETTINGS MUST BE SET TO" " Options State Rectangular Connected Small" "SPIC(y,a,b,n) makes a picture for SIMP(y,a,b,n). This plot is parametric." " You must set the parameter domain to MIN:0 MAX:1" " Use to accept parameter domain." "###################################" "EXAMPLE 1" "approX the following expression to get all 5 approximations" " ([LEFT, RIGHT, MID, TRAP, SIMP]) for y=cosx" " on [-2, 2] using 6 subintervals." ALL(COS(x),-2,2,6) "EXAMPLE 2" "approX and Plot the following expression to make a picture" " of the left hand sum for y=cosx on [-2,2] using 6 subintervals." " From the Plot window, execute Options State Rectangular Connected Small" LPIC(COS(x),-2,2,6) "EXAMPLE 3" "approX and Plot the following expression to make a picture" " of Simpson's rule for y=cosx on [-2,2] using 6 subintervals." " Set the parameter domain to MIN:0 MAX:1 and use ," SPIC(COS(x),-2,2,6) "#######################" "SEE INSTRUCTIONS ABOVE" "#########################"