Introduction to Scientific Programming:  Computational Problem Solving Using Mathematica and C

Joseph L. Zachary

The Blocks, Integ, and Newton package are designed to accompany Introduction to Scientific Programming.

Blocks

The Blocks package provides four functions useful for summing the even terms of the harmonic series, as discussed in Chapter 4 of Introduction to Scientific Programming.  
The even terms of the series are (1/2) + (1/4) + (1/6) + (1/8) + ...
Before the functions of the package can be used, the package must be loaded with

Needs["ISP`Blocks`"]

BlockFast

◼ BlockFast[n] sums the first n even terms of the harmonic series by exploiting the EulerGamma constant and the PolyGamma function.

◼ The parameter n must be a non-negative integer.

Examples

Needs["ISP`Blocks`"]

BlockFast[15]

BlockFloat

◼ BlockFloat[n] sums the first n even terms of the harmonic series using floating-point arithmetic.

◼ The parameter n must be a non-negative integer.

Examples

Needs["ISP`Blocks`"]

BlockFloat[15]

BlockPrecision

◼ BlockPrecision[n, p] sums the first n even terms of the harmonic  series from left to right if n is non-negative.
◼ BlockPrecision[n,p] sums the first |n| even terms of the harmonic series from right to left if n is negative.

◼ The parameter n must be an integer.
◼ The parameter p must be a positive integer.
◼ If p is between 1 and 10, inclusive, BlockPrecision uses simulated floating-point arithmetic with p-digit mantissas.
◼ If p is larger than $MachinePrecision, BlockPrecision uses arbitrary floating-point arithmetic with a precision of p.
◼ Otherwise, BlockPrecision uses floating-point arithmetic.

Examples

Needs["ISP`Blocks`"]

BlockPrecision[100,  3]

BlockPrecision[-100,  3]

BlockFloat[100,  16]

BlockPrecision[100,  20]

BlockRat

◼ BlockRat[n] sums the first n even terms of the harmonic series using rational arithmetic.

◼ The parameter n must be a non-negative integer.

Examples

Needs["ISP`Blocks`"]

BlockRat[15]

Integ

The Integ package provides two functions useful for visualizing numerical integration, as discussed in Chapter 15 of Introduction to Scientific Programming.
Before the functions can be used, the package must be loaded with

\(\(
Needs["ISP`Integ`"]\)\)

AnimateRectangular

◼ AnimateRectangular[g, a, b, n] produces an animation with n frames illustrating the use of the rectangular method to approximte the integral of g[x] between x=a and x=b.

◼ The parameter g must be a single-parameter, real-valued function.
◼ The parameters a and b must be real-valued, with a < b.
◼ The paramter n must be a positive integer.

Examples

Needs["ISP`Integ`"]

f[x_]  :=  Sin[x] + 2

AnimateRectangular[f,  0,  8,  3]

AnimateTrapezoidal

◼ AnimateTrapezoidal produces an animation with n frames illustrating the use of the trapezoidal method to approximte the integral of g[x] between x=a and x=b.

◼ The parameter g must be a single-parameter, real-valued function.
◼ The parameters a and b must be real-valued, with a < b.
◼ The parameter n must be a positive integer.

Examples

Needs["ISP`Integ`"]

f[x_]  :=  Sin[x] + 2

AnimateTrapezoidal[f,  0,  8,  3]

Newton

The Newton package provides a function useful for visualizing Newton's method, as discussed in Chapter 14 of Introduction to Scientific Programming.
Before the functions can be used, the package must be loaded with

Needs["ISP`Newton`"]

AnimateNewton

◼ AnimateNewton[f, guess, n, {a,b}] produces an animation with n+1 frames illustrating the use of Newton's method to find the root of f[x] beginning with a guess of x=guess.  The x-axis between a and b is shown.

◼ The parameter f must be a single-parameter, real-valued function.
◼ The parameter guess must be a real number.
◼ The parameter n must be a positive integer.
◼ The parameters a and b must be real-valued with a < b.

Examples

Needs["ISP`Newton`"]

g[x_]  :=  x^3  -  9*x

AnimateNewton[g,  1.3,  3,  {-3.5,  3.5}]