Numerical Methods

Dennis Silverman
Mathematical Physics 212 A
Department of Physics and Astronomy
U. C. Irvine

\(Some\ of\ the\ examples\ are\ taken\ from\ 
      "Guide to Standard Mathematica Packages", 
Version\ 2.2, \ 
    Wolfram\ Research\)

Interpolation

\(There\ are\ two\ ways\ to\ input\ 
      \(data : 
		
        \((1)\)\ \ If\ equally\ spaced\ xi\ integers\ starting\ at\ 1\), \ 
    only\ need\ to\ give\ data\ points\ fi.
		\((2)\)\ \ If\ at\ various\ 
      xi, \ have\ to\ give\ set\ of\ pairs\  - 

      	{{x1, f1}, \ {x2, f2}, \ ...}\)\(Ex.\ Least\ squares\ fit\ in\ x\ using\ given\ functions\ 1, x, \ x^2

    \)

data  =  Table[n^2,  {n,  1,  7}]

Fit[data,  {1, x, x^2}, x]

\(\(?? Fit
\)\)

InterpolatingPolynomial[{{1, 4}, {2, 5}, {4, 6}}, x]

?? InterpolatingPolynomial

\(\(?? Interpolation
\)\)

Rational Interpolation or Pade Approximant with numerator of degree m and denominator of degree k.

<< NumericalMath`Approximations`

\(\(?? RationalInterpolation
\)\)

ri1 = 
      RationalInterpolation[Exp[x], {x, 2, 4}, {0, 1/3, 2/3, 1, 4/3, 5/3, 2}]

Plot[ri1 - Exp[x],  {x, 0, 2}]

Instead,  
    we can let Mathematica choose the interpolation points.

ri2 = RationalInterpolation[Exp[x], {x, 2, 4}, {x, 0, 2}]

Plot[ri2 - Exp[x], {x, 0, 2}]

To minimize the maximum error over the entire range of 
      interpolation,  use

?MiniMaxApproximation

mmlist  =  MiniMaxApproximation[Exp[x], {x, {0, 2}, 2, 4}]

To extract just the rational approximation

mmfunc  =  mmlist[[2, 1]]

Plot[1 - mmfunc/Exp[x], {x, 0, 2}]

Roots

?FindRoot

FindRoot[gam == Sinh[gam], {gam, 1}]

FindRoot[gam == 0.5  Cosh[gam], {gam, 0}]

Integrating Numerical Data

<< NumericalMath`ListIntegrate`

?ListIntegrate

This integrates a collection of interpolating polynomials of 
      degree k.

data  =  Table[n^2,  {n, 0, 7}]

ListIntegrate[data, 1]

ListIntegrate[data, 1, 2]

ListIntegrate[data, 1, 3]

Integrate[x^2,  {x, 0,  7}]

Gaussian Quadrature

<< NumericalMath`GaussianQuadrature`

?GaussianQuadratureWeights

GaussianQuadratureWeights[2, -1, 1]

GaussianQuadratureError[2, f, -1, 1]