List of programs by chapter

The file names of the application programs contain the complete information on their location within the folder structure descending from the root folder /INP/. The general format of the file names is Pnn-name.py or Pnn-name.cpp, whereby nn indicates the chapter folder /INP/Chnn/ and the extension indicates the respective subfolder, that is, /INP/Chnn/Python/ or /INP/Chnn/C/.

Download here the entire archive INP.zip.

2 Basic Programming Techniques

Listing File Output
2.1
2.2
P02-Fact_global.py
P02-Fact_global.cpp
Factorial with global variables.
2.3
2.4
P02-Fact_comb.py
P02-Fact_comb.cpp
Combinations using a factorial function.
P02-Fact_recur.py
P02-Fact_recur.cpp
Factorial based on recursivity.
2.7
2.9
2.10
P02-Swap.py
P02-Swap.c
P02-Swap.cpp
Returning swapped arguments from a function.
2.8 P02-Swap_list.py Returning swapped list elements from a function.
2.18
2.19
P02-MatOp.py
P02-MatOp.cpp
Check of identity (A B)T = BT AT for random arrays A and B.

3 Elements of Scientific Graphics

Listing File Output
3.1 P03-Tk.py Creating a Tk root widget.
3.2 P03-Tk_Label.py Creating a tkinter Label widget.
3.3 P03-Tk_Canvas0.py Creating a Tkinter Canvas widget.
3.4 P03-Tk_Canvas.py Tkinter Canvas widget with simple graphic elements.
3.5 P03-Tk_Clock0.py Python clock application built with Tkinter.
3.6 P03-Tk_Clock.py Python clock using callback function.
3.7 graphlib0.py Minimal Python library based on Tkinter for plotting functions.
3.8 P03-Plot0.py Plotting a function of one variable.
P03-Plots.py
P03-Plots.cpp
Plotting a function of one variable with different styles.
3.10
3.17
P03-MultiPlot.py
P03-MultiPlot.cpp
Plotting two functions on the same graph.
3.11
3.18
P03-Contour.py
P03-Contour.cpp
Contour plot of a function of two variables.
3.12 P03-PlotParticles.py 3D rendering of a molecule.
3.13 P03-PlotStruct.py 3D rendering of an airplane.
3.15 P03-Histogram.py Histogram of a sequence of random numbers.

3.16
P03-Plot.py
P03-Plot.cpp
Plotting a function of one variable.

4 Sorting and Indexing

Listing File Output
4.2 P04-Sort0.py
P04-Sort0.cpp
Generic use of sorting routines.
4.7 P04-Sort1.py
P04-Sort1.cpp
Ascending sorting and indexing of an array.
4.9 P04-Sort2.py
P04-Sort2.cpp
Ascending indexing of two correlated arrays.
4.12
4.13
P04-SortQuart.py
P04-SortQuart.cpp
Sorting the elements of an array into quartiles.
4.15
4.16
P04-Sort3.py
P04-Sort3.cpp
Sorting and indexing of a random sequence using direct insertion.
P04-SortComp0.py
P04-SortComp0.cpp
Comparison of operation counts for sorting methods.
P04-SortComp1.py
P04-SortComp1.cpp
Comparison of operation counts for sorting methods (graphic).

5 Evaluation of Functions

Listing File Output
5.2 P05-Poly.py
P05-Poly.cpp
Elementary operations with polynomials.
P05-Exp.py
P05-Exp.cpp
Evaluates the exponential from its power-series and continued fraction representations.
P05-TanPlot.py
P05-TanPlot.cpp
Plots the tangent function using the continued fraction representation.
5.12
5.13
P05-PolyPlot.py
P05-PolyPlot.cpp
Plots a polynomial and its derivative
5.16
5.17
P05-SpherYPlot.py
P05-SpherYPlot.cpp
Plots squared spherical harmonics.
5.18
5.19
P05-SpherY.py
P05-SpherY.cpp
Checks the addition theorem for spherical harmonics.
P05-CBessPlot.py
P05-CBessPlot.cpp
Cylindrical Bessel and Neumann functions, based on the corresponding spherical functions.
P05-RadProbH.py
P05-RadProbH.cpp
Radial probability densities for the hydrogen atom.

6 Algebraic and Transcendental Equations

Listing File Output
6.2
6.16
P06-Bisect.py
P06-Bisect.cpp
Real roots of a real function by the bisection method.
6.5 P06-Iter.py
P06-Iter.cpp
Real root of a real function by the method of successive approximations.
P06-Newton.py
P06-Newton.cpp
Real roots of a real function by the Newton-Raphson method.
6.11 P06-BirgeVieta.py
P06-BirgeVieta.cpp
Real roots of a polynomial by the Birge-Vieta method.
6.14 P06-NewtonSys.py
P06-NewtonSys.cpp
Real roots of systems of nonlinear equations by the Newton-Raphson method.
P06-CompareZeros.py
P06-CompareZeros.cpp
Compare solvers for algebraic and transcendental equations.
6.17 P06-Kepler.py
P06-Kepler.cpp
Solution of Kepler’s equation.
6.18 P06-Fraunhofer.py
P06-Fraunhofer.cpp
Intensity distribution for Fraunhofer diffraction.
6.19 P06-Planck.py
P06-Planck.cpp
Planck’s law of black body radiation.
6.20 P06-NewtonSys1.py
P06-NewtonSys1.cpp
Intersection points of a circle and a parabola.
6.21 P06-NewtonSys2.py
P06-NewtonSys2.cpp
System of three nonlinear equations.

7 Systems of Linear Equations

Listing File Output
7.2 P07-Gauss.py
P07-Gauss.cpp
Solution of a linear system by Gaussian elimination.
7.6 P07-GaussJordan.py
P07-GaussJordan.cpp
Solution of a matrix equation by Gauss-Jordan elimination.
7.11 P07-MatInv.py
P07-MatInv.cpp
Check of matrix inversion based on LU factorization.
7.18 P07-TriDiagSys.py
P07-TriDiagSys.cpp
Solution of linear system with tridiagonal matrix by LU factorization.
P07-GaussSeidel.py
P07-GaussSeidel.cpp
Solution of linear system by the Gauss-Seidel method.
7.21
7.22
P07-GaussJordan1.py
P07-GaussJordan1.cpp
Solution of a matrix equation by Gauss-Jordan elimination.
7.23
7.24
P07-LUFactor.py
P07-LUFactor.cpp
Solution of multiple linear systems by LU factorization.
7.25 P07-TriDiagSys1.py
P07-TriDiagSys1.cpp
Solution of system with tridiagonal matrix by LU factorization.
7.26 P07-MatDetIdent.py
P07-MatDetIdent.cpp
Check of identity for determinant of matrix product.
7.27 P07-MatInvIdent.py
P07-MatInvIdent.cpp
Check of identity for inverse of matrix product.
7.28 P07-MatSymInv.py
P07-MatSymInv.cpp
Inversion of symmetric positive-definite matrix by Cholesky factorization.
7.29 P07-Wavelet.py
P07-Wavelet.cpp
Solution of linear system for Daubechies D4 wavelet.

8 Eigenvalue problems

Listing File Output
8.3 P08-Jacobi.py
P08-Jacobi.cpp
Eigenvalues and eigenvectors of symmetric matrices by the Jacobi method.
8.6
8.7
P08-EigInvMat.py
P08-EigInvMat.cpp
Eigenvalues and eigenvectors of the inverse of a symmetric matrix.
8.8
8.9
P08-String.py
P08-String.cpp
Normal modes of a loaded string with fixed ends.
8.11 P08-MomInert.py
P08-MomInert.cpp
Rotation of a molecule to the system of principal axes.
8.12 P08-Airplane.py
P08-Airplane.cpp
Rotation of an airplane.
8.13 P08-Hueckel.py
P08-Hueckel.cpp
Application of the Hueckel method for the benzene molecule.
8.15 P08-Roothaan.py
P08-Roothaan.cpp
H2O.dat
Solution of the Roothaan equation for the H2O molecule.

9 Modeling of Tabulated Functions

Listing File Output
9.3 P09-Lagrange0.py
P09-Lagrange0.cpp
Interpolation using the Lagrange polynomial.
P09-Lagrange.py
P09-Lagrange.cpp
Lagrange interpolation for a sequence of arguments.
P09-Lagrange1.py
P09-Lagrange1.cpp
Lagrange interpolation for a list of arguments.
9.5 P09-Neville0.py
P09-Neville0.cpp
Interpolation using Neville’s method.
9.7 P09-Spline0.py
P09-Spline0.cpp
Interpolation using cubic splines.
9.7 P09-SplineLJ.py
P09-SplineLJ.cpp
Cubic spline interpolation of Lennard-Jones potential.
P09-LinFit0.py
P09-LinFit0.cpp
Linear fit of a model to observed data points.
9.10 P09-MultiFit0.py
P09-MultiFit0.cpp
Application of multilinear regression.
9.14 P09-MarqFit0.py
P09-MarqFit0.cpp
fit.dat
Nonlinear regression using the Levenberg-Marquardt method.
9.18
9.19
P09-Neville.py
P09-Neville.cpp
Lagrange interpolation and Neville’s method for uniformly distributed data points and equally spaced abscissas of the data points.
9.20 P09-Spline.py
P09-Spline.cpp
Interpolation using cubic splines.
9.21 P09-LinFit.py
P09-LinFit.cpp
Linear fit by the least-squares method.
9.23 P09-Halides.py
P09-Halides.cpp
halides.dat
Absorption maximum of halides by linear and nonlinear regression.
P09-PolFit.py
P09-PolFit.cpp
Polynomial fit by the least-squares method.
9.24 P09-MultiFit.py
P09-MultiFit.cpp
Multilinear fit by the least-squares method.
P09-MultiFit_pol.py
P09-MultiFit_pol.cpp
Polynomial fit using multilinear algorithm.
9.26 P09-MarqFit.py
P09-MarqFit.cpp
fit2.dat
Nonlinear fit by the Levenberg-Marquardt method.
9.28 P09-Tides.py
P09-Tides.cpp
tides.dat
Tidal analysis based on Levenberg-Marquardt and multilinear fits.
9.29 P09-Fourier.py
P09-Fourier.cpp
Fourier analysis of simple signals based on multilinear fit.

10 Integration of Functions

Listing File Output
10.1 P10-qTrapz.py
P10-qTrapz.cpp
Function integration using the trapezoidal rule.
10.6 P10-qAdapt.py
P10-qAdapt.cpp
Application of adaptive quadratures based on the trapezoidal rule, Simpson's rule, and Romberg's method.
10.9 P10-qImprop.py
P10-qImprop.cpp
Improper integrals of the first and second kind.
10.15 P10-qGauss.py
P10-qGauss.cpp
Gauss-Legendre and Gauss-Laguerre quadratures.
10.19 P10-Integ3D.py
P10-Integ3D.cpp
3D integral over toroidal domain using Cartesian coordinates.
10.22 P10-IntegSph.py
P10-IntegSph.cpp
3D integral in spherical coordinates.
10.24 P10-qAdapt3D.py
P10-qAdapt3D.cpp
Adaptive 3D integration on spherical domain.
10.26 P10-qTrapSimpConv.py
P10-qTrapSimpConv.cpp
Convergence study of the trapezoidal and Simpson rules applied to the sine function.
P10-qTrapSimpConv1.py
P10-qTrapSimpConv1.cpp
Convergence study of the trapezoidal and Simpson rules applied to the norm of Legendre functions.
P10-qSpherY.py
P10-qSpherY.cpp
Check of norm of associated Legendre functions (Romberg's method) and spherical harmonics (angular Simpson quadrature).
10.28
10.29
P10-Fresnel.py
P10-Fresnel.cpp
Fresnel integrals and Cornu spiral.
10.30 P10-ElecProbRad.py
P10-ElecProbRad.cpp
Radial localization probability of the electron in the H atom.
10.31 P10-ElecProb.py
P10-ElecProb.cpp
Total localization probability of the electron in the H atom.
10.32 P10-IntegCyl.py
P10-IntegCyl.cpp
3D integral in cylindrical coordinates.
10.34 P10-Integ3D1.py
P10-Integ3D1.cpp
3D integral over toroidal domain using Cartesian coordinates.
10.35
10.36
P10-qAdapt3DTor.py
P10-qAdapt3DTor.cpp
Adaptive 3D integration on toroidal domain.

11 Monte Carlo Method

Listing File Output
11.1 P11-MC-1D.py
P11-MC-1D.cpp
1D Monte Carlo integration of a function.
11.2 P11-MC-1Ds.py
P11-MC-1Ds.cpp
1D Monte Carlo integration of a function with importance sampling.
P11-MC-1Dg.py
P11-MC-1Dg.cpp
Convergence study of the 1D Monte Carlo integration of a function with/without importance sampling.
11.3 P11-MC-2D.py
P11-MC-2D.cpp
2D Monte Carlo evaluation of the unit circle area.
P11-MC-2Dg.py
P11-MC-2Dg.cpp
Convergence study of the 2D Monte Carlo evaluation of the unit circle area.
11.4 P11-MC-2Ds.py
P11-MC-2Ds.cpp
2D Monte Carlo integration with uniform and Gaussian sampling.
11.5 P11-MC-3D.py
P11-MC-3D.cpp
3D Monte Carlo evaluation of the mass center of a torus.
11.11 P11-MC-1Dx.py
P11-MC-1Dx.cpp
Convergence study of the 1D Monte Carlo integration of a Gaussian function with/without importance sampling.
11.12 P11-MC-2Dx.py
P11-MC-2Dx.cpp
Convergence study of the 2D Monte Carlo integration with uniform, Gaussian, and exponential sampling.
11.13 P11-RandUni.py
P11-RandUni.cpp
Generation of random numbers with uniform distribution.
11.14 P11-RandNrm.py
P11-RandNrm.cpp
Generation of random numbers with normal distribution.

12 Ordinary Differential Equations

Listing File Output
12.2 P12-ODE.py
P12-ODE.cpp
Solution of Cauchy problem for a system of two first-order ODEs by Euler’s method.
12.4 P12-PendulumRK.py
P12-PendulumRK.cpp
Angular motion of a nonlinear pendulum by the Runge-Kutta method.
12.7 P12-RKFehlberg.py
P12-RKFehlberg.cpp
Adaptive step size control for a system of two first-order ODEs.
P12-RKFehlberg_g.py
P12-RKFehlberg_g.cpp
Adaptive step size control for a system of two first-order ODEs with graphic output.
12.11 P12-PendulumEC.py
P12-PendulumEC.cpp
Angular motion of a nonlinear pendulum by the Euler-Cromer method.
P12-ThrowPC.py
P12-ThrowPC.cpp
Oblique throw of an object with drag using Euler's predictor-corrector method.
P12-ThrowEC.py
P12-ThrowEC.cpp
Oblique throw of an object with drag using the Euler-Cromer method.
12.12 P12-ThrowV.py
P12-ThrowV.cpp
Oblique throw of an object with drag using the velocity Verlet method.
12.15 P12-LegendreSH.py
P12-LegendreSH.cpp
Solution of the differential equation of the Legendre polynomials by the shooting method.
12.17 P12-OscillatorSH.py
P12-OscillatorSH.cpp
Eigenstates of the quantum oscillator by the shooting algorithm based on the Numerov method.
12.19 P12-LegendreBL.py
P12-LegendreBL.cpp
Solution of the differential equation of the Legendre polynomials by the finite-difference method.
12.21 P12-ODEg.py
P12-ODEg.cpp
Cauchy problem for a second-order ODE solved by the Euler and Euler predictor-corrector methods.
P12-ThrowECg.py
P12-ThrowECg.cpp
Hammer throw using the Euler-Cromer method.
12.22 P12-ThrowPCg.py
P12-ThrowPCg.cpp
Hammer throw using Euler’s predictor-corrector method.
12.22 P12-ThrowVg.py
P12-ThrowVg.cpp
Hammer throw using the velocity Verlet method.
12.23 P12-ChargePC.py
P12-ChargePC.cpp
Charged particle orbiting about a fixed charge using Euler’s predictor-corrector method.
12.24 P12-ChargeEC.py
P12-ChargeEC.cpp
Charged particle orbiting about a fixed charge using the Euler-Cromer method.
12.25 P12-ChargeV.py
P12-ChargeV.cpp
Charged particle orbiting about a fixed charge using the velocity Verlet method.
12.26 P12-PendulumRKg.py
P12-PendulumRKg.cpp
Angular motion of a nonlinear pendulum by the Runge-Kutta method.
12.27 P12-PendulumRKT.py
P12-PendulumRKT.cpp
Angular motion of a nonlinear pendulum by the Runge-Kutta method.
P12-PendulumECg.py
P12-PendulumECg.cpp
Angular motion of a nonlinear pendulum by the Euler and Euler-Cromer methods.
12.28 P12-PlanetsV.py
P12-PlanetsV.cpp
Orbital motions of the Earth and Moon by the velocity Verlet method.
12.30 P12-SqWellSHg.py
P12-SqWellSHg.cpp
Quantum eigenstates of a finite square quantum well by the shooting algorithm based on the Numerov method.
P12-OscillatorSHg.py
P12-OscillatorSHg.cpp
Eigenstates of the quantum harmonic oscillator by the shooting algorithm based on the Numerov method.
12.31 P12-LegChebSH.py
P12-LegChebSH.cpp
Legendre and Chebyshev polynomials by the shooting method.
12.32 P12-LegChebBL.py
P12-LegChebBL.cpp
Legendre and Chebyshev polynomials by the finite-difference method.

13 Partial Differential Equations

Listing File Output
13.3 P13-PoissonXY.py
P13-PoissonXY.cpp
Solution of the 2D Poisson equation in a rectangular domain.
13.5 P13-HeatDisk0.py
P13-HeatDisk0.cpp
Solution of the static heat problem of a conducting disk in Cartesian coordinates.
13.7 P13-Diffusion0.py
P13-Diffusion0.cpp
Finite-difference solution of the 1D diffusion equation.
13.11 P13-Diffusion1.py
P13-Diffusion1.cpp
Finite-difference solution of the 1D diffusion equation with spatially variable diffusion coefficient.
13.14 P13-ScatterQTD0.py
P13-ScatterQTD0.cpp
Scattering of a quantum wave packet using a tridiagonal solver for the 1D Schrödinger equation.
13.15 P13-ScatterQGS0.py
P13-ScatterQGS0.cpp
Scattering of a quantum wave packet using a Gauss-Seidel solver for the 1D Schrödinger equation.
13.17 P13-Wave0.py
P13-Wave0.cpp
Solution of the 1D classical wave equation by the explicit finite-difference method.
13.19 P13-Poisson0.py
P13-Poisson0.cpp
Solution of the 2D Poisson equation in a square domain (Poisson0).
13.20 P13-Poisson1.py
P13-Poisson1.cpp
Solution of the 2D Poisson equation in a rectangular domain (PoissonXY).
P13-Poisson2.py
P13-Poisson2.cpp
Solution of the 2D Poisson equation in a square domain (PoissonXY).
P13-HeatSquare0.py
P13-HeatSquare0.cpp
Steady-state temperature distribution in a thin square conducting plate.
P13-HeatSquare.py
P13-HeatSquare.cpp
Steady-state temperature distribution in a thin square conducting plate.
13.21 P13-HeatDisk.py
P13-HeatDisk.cpp
Steady-state temperature distribution in a thin conducting disk.
13.22 P13-HeatTriangle.py
P13-HeatTriangle.cpp
Steady-state temperature distribution in a thin triangular conducting plate.
13.23 P13-Diffusion2.py
P13-Diffusion2.cpp
Solution of the diffusion equation for spatially variable diffusion coefficient.
13.24 P13-ScatterQTD1.py
P13-ScatterQTD1.cpp
Scattering of a quantum wave packet by a potential barrier using a tridiagonal solver (real-time graphics).
P13-ScatterQGS1.py
P13-ScatterQGS1.cpp
Scattering of a quantum wave packet by a potential barrier using a Gauss-Seidel solver (real-time graphics).
13.25 P13-Wave.py
P13-Wave.cpp
Solution of the 1D classical wave equation by the explicit finite-difference method for two wave number interval widths (∆k = 0.5 and ∆k = 5).

Appendix C: Embedding Python in C/C++

Listing File Output
C.1 operations.py Module operations.py containing functions called from the C/C++ programs C.2, C.3, and C.4.
C.2 PyEmbed1.cpp Calling Python functions with scalar arguments from C++ code.
C.3 PyEmbed2.cpp Calling Python functions with vector arguments from C++ code.
C.4 PyEmbed3.cpp Calling Python functions via C++ wrapper classes.