# This worksheet implements the blocks package used in Chapter 4 of # Introduction to Scientific Programming by Joseph L. Zachary. -------------------------------------------------------------------------------- # # Create an empty package. # > blocks := table(); -------------------------------------------------------------------------------- # # Compute maximum extension for "n" blocks using floating-point # arithmetic. # > blocks[blockFloat] := proc (n)\ local total, i;\ total := 0.0;\ for i from 1 to n do\ total := total + 1.0/(2.0*i);\ od;\ RETURN(total);\ end; -------------------------------------------------------------------------------- # # Compute maximum extension for "n" blocks using rational arithmetic. # > blocks[blockRat] := proc (n)\ local total, i;\ total := 0;\ for i from 1 to n do\ total := total + 1/(2*i);\ od;\ RETURN(total);\ end; -------------------------------------------------------------------------------- # # Compute maximum extension for "n" blocks using Psi function and # gamma constant. # > blocks[blockFast] := proc (n)\ RETURN(.5 * evalf(Psi(n+1)+gamma));\ end; -------------------------------------------------------------------------------- > \