In this chapter we apply the approximation theory we presented in chapter 3 to find solutions of linear and nonlinear equations and to perform integration of general functions. Both subjects are classical, but they serve as basic tools in scientific computing operations and in solving systems of ordinary and partial differential equations. With regards to root finding, we consider both scalar as well as systems of nonlinear equations. We present different versions of the Newton-Raphson method, the steepest descent method, and the conjugate gradient method; we will revisit the latter in chapter 9. With regards to numerical integration we present some basic quadrature approaches, but we also consider advanced quadrature rules with singular integrands or in unbounded domains.
On the programming side, we first introduce the concept of passing a function to a function; in the previous chapter we were passing variables. This allows an easy implementation of recursion, which is so often encountered in scientific computing. We offer several C++ examples from root finding and numerical integration applications that make use of recursion, and show an effective use of classes and overloaded operators. We also address parallel programming with emphasis on domain decomposition, specifically the concept of reduction operations. We introduce the MPI commands MPI_Reduce and MPI_Allreduce for accomplishing reduction operations among a collection of processes.
- Section 4.1: double SquareRoot(double value, double guess, int interation) function definition
- Section 4.1.4: double NewtonRaphson(double x0, double (*func)(double), double (*func_der)(double), int max_iter, int multiplicity) function definition
- Section 4.1.4: double NewtonRaphson(double x0, double (*func)(double), double (*func_der)(double), int max_iter) function definition
- Section 4.1.4: double NewtonRaphson(double x0, double (*func)(double), double(*func_der)(double),double *(func_secondder)(double), int max_iter, int multiplicity) function definition
- Section 4.1.7: SCVector ConjugateGradient(SCMatrix A, SCVector b, SCVector x0) function definition
- Section 4.2.1: double MidpointRule(int level, double xleft, double xright, double (*func)(double)) function definition
- Section 4.2.1: double TrapezoidRule(int level, double xleft, double xright, double (*func)(double)) function definition
- Section 4.2.1: double Romberg(int m, int k, double xleft, double xright, double (*func)(double)) function definition
- Section 4.2.2: double JacobiPoly(int degree, double x, double alpha, double beta) function definition
- Section 4.2.2: double JacobiPolyDerivative(int degree, double x, double alpha, double beta) function definition
- Section 4.2.2: void JacobiZeros(int degree, double *z, double alpha, double beta) function definition
- Section 4.2.2: void JacobiZW(int degree, double *z, double *w, double alpha, double beta) function definition
- Section 4.2.2: double LaguarrePoly(int degree, double x, double alpha, double beta) function definition
- Section 4.2.2: double LaguarrePolyDerivative(int degree, double x, double alpha, double beta) function definition
- Section 4.2.2: void LaguarreZeros(int degree, double *z, double alpha, double beta) function definition
- Section 4.2.2: void Laguarre ZW(int degree, double *z, double *w, double alpha, double beta) function definition
- Section 4.2.2: double HermitePoly(int degree, double x, double alpha, double beta) function definition
- Section 4.2.2: double HermitePolyDerivative(int degree, double x, double alpha, double beta) function definition
- Section 4.2.2: void HermiteZeros(int degree, double *z, double alpha, double beta) function definition
- Section 4.2.2: void HermiteZW(int degree, double *z, double *w, double alpha, double beta) function definition
Go to the file SCchapter4.h for function/class declarations
Go to the file SCchapter4.cpp for function/class definitionsIn the case that an entire program (meaning that a main() function is provided) is presented in the text, we classify this as a driver program. Unlike the functions/classes above, driver programs are complete C++ programs which can be compiled and executed. As you read through the book, you will see that driver programs are often times created by using functions/classes which are in the SCchapter files. We denote driver programs which are explicitly given in the text of the book in red. In some chapters, we present very few driver programs explicitly in the text, however we provide some example driver programs which demonstrate how to use the functions/classes with in SCchapter files. Such driver programs are denoted in black.
Section 4.1.4: Newton-Raphson root finding with function passing | chapter4c0.cpp |
Section 4.1.7: Conjugate Gradient example program | chapter4c1.cpp |
Section 4.2.1: Example program using the Midpoint, Trapezoidal, and Simpson's rules | chapter4c2.cpp |
Section 4.2.1: Example program which passes a function to the Trapezoidal Rule function | chapter4c3.cpp |
Section 4.2.2: Example program for computing the zeros and weights for Legendre, Hermite, and Laguerre quadrature | chapter4c4.cpp |
Section 4.3: MPI - Program demonstrating the use of MPI_Reduce | chapter4c5P.cpp |