Source code of modules in Chapters
Chapter 1. Introduction
Chapter 2. Systems of linear algebraic equations
- 2.2 gaussElimin.py Gauss elimination
- 2.3 LUdecomp.py LU decomposition and solution phases
- 2.3 choleski.py Choleski’s decomposition and solution phase
- 2.3 example2_7.py program that solves Ax = B with Doolittle’s decomposition method and computes|A|
- 2.3 example2_8.py Solve the equations Ax = b by Choleski’s decomposition
- 2.4 LUdecomp3.py LU decomposition and solution phases of a tridiagonal matrix
- 2.4 example2_11.py Use the functions LUdecmp3 and LUsolve3 to solve Ax = b
- 2.4 LUdecomp5.py LU decomposes a symmetric,
pentadiagonal matrix A of the form A = [f\e\d\e\f] and find the solution (Ax = b) by LUsolve5
- 2.5 swap.py The function swapRows interchanges rows i and j of a matrix or vector v, whereas swapCols interchanges columns i and j of a matrix
- 2.5 gaussPivot.py The function gaussPivot performs Gauss elimination with row pivoting.
The elimination and solution phases are identical to gaussElimin
- 2.5 LUpivot.py LU decomposition of matrix [A] using scaled row pivoting.
Solves \(\left [ L \right ]\left [ U \right ]\left \{ x \right \}=\left \{ b \right \}\)
- 2.5 example2_13.py function that inverts a matrix using LU decomposition with pivoting and test
- 2.6 example2_14.py function that inverts a tridiagonal matrix
- 2.7 gaussSeidel.py The function gaussSeidel is an implementation of the Gauss-Seidel method with relaxation
- 2.7 conjGrad.py The function conjGrad implements the conjugate gradient algorithm
- 2.7 example2_17.py program to solve n simultaneous equations (tridiagonal) by the Gauss-Seidel method with relaxation
- 2.7 example2_18.py program to solve n simultaneous equations (tridiagonal) with the conjugate gradient method
Chapter 3. Interpolation and curve fitting
- 3.2 newtonPoly.py This module contains the two functions required for interpolation by Newton’s method
- 3.2 neville.py Neville's method of polynomial interpolation
- 3.2 example3_4.py Interpolate the
data \(f(x)=4.8cos\left ( \frac{\pi x}{20} \right )\) by Newton’s method at x = 0, 0.5, 1.0, . . . , 8.0, and compare with the
“exact” values
- 3.2 rational.py Rational function interpolation
- 3.2 example3_6.py Interpolate
data and plot the results. Use both the polynomial interpolation and the rational function interpolation
- 3.3 cubicSpline.py Interpolate by cubic spline and evaluate the interpolant at x
- 3.3 example3_9.py program that interpolates, using the module cubicSpline, between given
data points with a natural cubic spline
- 3.4 polyFit.py Sets up and solves the normal equations for
the coefficients of a polynomial of degree m. It returns the coefficients of the polynomial
- 3.4 plotPoly.py Function for plotting the data points and the fitting
polynomial
- 3.4 example3_12.py fits a polynomial of arbitrary degree m to the data points.
Use the program to determine m that best fits the data in the least-squares sense.
Chapter 4. Roots of equations
- 4.2 rootsearch.py Searches for a zero of the user-supplied function f(x) in the interval (a,b) in increments of \(\Delta\)x
- 4.2 example4_1.py compute the root of a polynomial function with four-digit accuracy
- 4.3 bisection.py Method of bisection to compute the root of f(x) = 0 that is known to lie in the interval (x1,x2)
- 4.3 example4_2.py use bisection to find the root of a polynomial function with four-digit accuracy
- 4.3 example4_3.py Find all the zeros of f(x) = x − tan x in the interval (0, 20) by the method of bisection
- 4.4 ridder.py Ridder’s method (modification of the false position method. Use if the derivative
of f(x) is impossible or difficult to compute)
- 4.4 example4_5.py Compute the zero of the function
\(f(x)=\frac{1}{(x-0.3)^{2}+0.01}- \frac{1}{(x-0.8)^{2}+0.04}\)
- 4.5 newtonRaphson.py Safe version of the Newton-Raphson method, assumes that the root to
be computed is initially bracketed in (a,b)
- 4.5 example4_8.py Find the smallest positive zero of
\(f(x)=x^{4}-6.4x^{3}+6.45x^{2}+20.538x-31.752\)
- 4.6 newtonRaphson2.py Newton-Raphson method for systems of equations, computes the Jacobian matrix using finite difference approximation and
the simultaneous equations are solved by Gauss elimination using the function gaussPivot
- 4.7 evalPoly.py Evaluates a polynomial and its derivatives
- 4.7 polyRoots.py Computes all the roots of \(P_{n}=0\) defined by its coefficient array \(a = \left [a_{0}, a_{1},...a_{n}\right ]\) using Laguerre's method
- 4.7 example4_12.py compute all the roots of \(x^{4}-5x^{3}-9x^{2}+155x-250=0\)
Chapter 5. Numerical Differentiation
- 5.2 Finite Difference Approximations
- 5.4 Derivatives by Interpolation
- 5.4 example5_4.py given a set of data compute f'(2) and f''(2) using
a natural cubic spline interpolant spanning all the data points
Chapter 6. Numerical integration
- 6.2 trapezoid.py Computes the integral evaluated with the composite trapezoidal rule
- 6.2 example6_4.py Use the recursive trapezoidal rule to evaluate
\(\int_{0}^{\pi }\sqrt{x}\:\textup{cos}\,x\:dx\) to six decimal places
- 6.3 romberg.py Romberg integration
- 6.3 example6_7.py Use Romberg integration to evaluate
\(\int_{0}^{\sqrt{\pi }}2x^{2}\,\textup{cos}\,x^{2}\:dx \)
- 6.4 gaussNodes.py Computes the nodal abscissas xi and the corresponding
weights Ai used in Gauss-Legendre quadrature over the "standard" interval
- 6.4 gaussQuad.py Uses gaussNodes to evaluate
\(\int_{a}^{b}f(x)\:dx \) with Gauss- Legendre quadrature using m nodes
- 6.4 example6_11.py Determine how many nodes are required to evaluate
\(\int_{a}^{\pi }\left ( \frac{\textup{sin}\,x}{x} \right )^{2}\:dx\) with Gauss-Legendre quadrature to six decimal places
- 6.5 gaussQuad2.py Computes \(\iint_{A}^{}f(x,y)\,dx\, dy \) over a quadrilateral
element with Gauss-Legendre quadrature of integration order m
- 6.5 example6_15.py Use gaussQuad2 to evaluate
\(\iint_{A}^{}f(x,y)\,dx\, dy \) over one quadrilateral
where \(f(x)= (x-2)^{2}(y-2)^{2} \)
- 6.5 triangleQuad.py Computes \(\iint_{A}^{}f(x,y)\,dx\, dy \) over a triangular region
using the cubic formula
- 6.5 example6_16.py evaluate
\(\iint_{A}^{}f(x,y)\,dx\, dy \) over a equilateral triangle for a given function
Chapter 7. Initial value problems
- 7.2 euler.py Euler's method for solution of initial value problems. It can handle any number of
first-order differential equations
- 7.2 printSoln.py Prints solution of initial value problem in tabular form
- 7.3 runKut4.py Integrate using the Runge-Kutta method of order
four
- 7.3 example7_4.py integrate an initial value problem using rk4 method
- 7.3 example7_5.py integrate an initial value problem using rk4 method
- 7.3 example7_6.py integrate an initial value problem using rk4 method
- 7.5 run_kut5.py Adaptive Runge-Kutta method with Dormand-Prince
coefficients
- 7.5 example7_8.py integrate an initial value problem using the adaptive Runge-Kutta method
- 7.5 example7_9.py integrate a moderately stiff problem using the adaptive Runge-Kutta method
- 7.6 midpoint.py Integration with midpoint method with Richardson extrapolation
- 7.6 bulStoer.py Integration with simplified algorithm for the Bulirsch-Stoer method
Chapter 8. Two-point boundary value problems
- 8.2 linInterp.py Finds the zero of the linear function f(x) by straight line interpolation
- 8.2 example8_1.py shooting method example for the boundary value problem y'' + 3yy' = 0 y(0) = 0 y(2) = 1
- 8.2 example8_3.py shooting method example for the third-order boundary value problem y''' = 2y'' + 6xy
y(0) = 2 y(5) = y'(5) = 0
- 8.2 example8_4.py Shooting method example for 4th order differential eqs. (supported beam)
- 8.2 example8_5.py Shooting method example for the differential equation y^(^4^) + 4/x y^3 = 0 with the boundary conditions
y(0) = y'(0) = 0 y''(1) = 0 y'''(1) = 1
- 8.3 Finite Difference Method
- 8.3 example8_6.py finite difference example for 2nd order linear diff. eqs.
- 8.3 example8_7.py finite difference example for 2nd order differential. eqs.
- 8.3 example8_8.py finite difference example for 4th order linear diff. eqs.
Chapter 9. Symmetric matrix eigenvalue problems
- 9.2 jacobi.py Jacobi method: compute all the eigenvalues λi
and eigenvectors xi of a symmetric matrix
- 9.2 sortJacobi.py Sort the eigenvalues and eigenvectors into ascending order
of eigenvalues
- 9.2 stdForm.py for matrices A and B, returns H and the transformation
matrix T = (L−1)T
- 9.3 inversePower.py Given the matrix A and the shift s, returns the eigenvalue
of A closest to s and the corresponding eigenvector
- 9.3 example9_4.py determine the largest principal eigenvalue by the power method
- 9.3 example9_5.py determine the smallest eigenvalue and the corresponding eigenvector of a matrix
- 9.3 inversePower5.py returns the smallest eigenvalue and the corresponding eigenvector of Ax = λBx, where A is a pentadiagonal
matrix and B is a sparse matrix
- 9.4 householder.py Householder reduction to tridiagonal form
- 9.4 example9_8.py use the function householder to tridiagonalize a matrix
- 9.4 sturmSeq.py Computes Sturm sequence of tridiagonal matrices
- 9.4 gerschgorin.py Computes global bounds on eigenvalues
- 9.4 lamRange.py Brackets the N smallest eigenvalues of a symmetric tridiagonal matrix
- 9.4 eigenvals3.py Finds m smallest eigenvalues of a tridiagonal matrix
- 9.4 example9_12.py use eigenvals3 to determine the three smallest eigenvalues of a 100×100 matrix
- 9.4 inversePower3.py Similar to inversePower before 9.3, but it executes
much faster because it exploits the tridiagonal structure of the matrix
- 9.4 example9_13.py compute the 10th smallest eigenvalue of the matrix A given in example 9.12
- 9.4 example9_14.py compute the three smallest eigenvalues and the corresponding eigenvectors of a matrix
Chapter 10. Introduction to optimization
- 10.2 goldSearch.py Golden section search for the minimum of a function
- 10.2 example10_1.py use goldSearch to find x that minimizes f(x) = 1.6x3 + 3x2 − 2x
subject to the constraint x >= 0
- 10.2 example10_2.py optimization of a section modulus of a beam
- 10.3 powell.py Powell's method of minimization
- 10.3 example10_3.py calculate the minimum of the function F = 100(y − x2)2 + (1 − x1)2
- 10.3 example10_4.py calculate smallest distance from the point (5, 8) to the curve xy = 5
- 10.3 example10_5.py calculate the minimization of the structural volume (weight) of a truss
- 10.4 downhill.py Downhill simplex method of minimization
- 10.4 example10_7.py calculate the minimum length of the wetted perimeter while maintaining a cross-sectional area af a channel
- 10.4 example10_8.py calculate the minimum volume of the material without violating the frequency constraint of a stepped shaft