You're reading from Mastering SciPy
Common to the design of railway or road building (especially for highway exits), as well as those crazy loops in many roller coasters, is the solution of differential equations in two or three dimensions that address the effect of curvature and centripetal acceleration on moving bodies. In the 1970s, Werner Stengel studied and applied several models to attack this problem and, among the many solutions he found, one struck as particularly brilliant—the employment of clothoid loops (based on sections of Cornu's spiral). The first looping coaster designed with this paradigm was constructed in 1976 in the Baja Ridge area of Six Flags Magic Mountain, in Valencia, California, USA. It was coined the Great American Revolution, and it featured the very first vertical loop (together with two corkscrews, for a total of three inversions).
The tricky part of the design was based on a system of differential equations, whose solution depended on the integration of Fresnel-type sine and cosine...
There are three ways to approach the computation of derivatives:
Numerical differentiation refers to the process of approximation of the derivative of a given function at a point. In SciPy, we have the following procedures, which will be covered in detail:
For generic univariate functions, the central difference formula with fixed spacing.
It is always possible to perform numerical differentiation via Cauchy's theorem, which transforms the derivative into a definite integral. This integral is then treated with the techniques of numerical integration explained in the upcoming section.
Symbolic differentiation refers to computation of functional expressions of derivatives of functions, pretty much in the same way that we would do manually. It is termed symbolic because unlike its numerical counterpart, symbols take the role of variables, rather than numbers or vectors of numbers. To perform symbolic differentiation, we require a computer algebra system (CAS), and in the SciPy...
To achieve a definite integration of functions on suitable domains, we have mainly two methods—Numerical integration and Symbolic integration.
Numerical integration refers to the approximation of a definite integral by a quadrature process. Depending on how the function f(x) is given, the domain of integration, the knowledge of its singularities, and the choice of quadrature, we have different ways to attack this problem:
For univariate polynomials, exact integration is achieved algebraically on each finite interval
For functions given as a finite set of samples over their domain:
The composite trapezoidal rule
Simpson's trapezoidal rules
Romberg integration scheme
For generic univariate functions given as Python functions, on finite intervals:
Fixed-order Gaussian quadrature
Fixed-tolerance Gaussian quadrature
Simple non-adaptive quadrature, by applying 21-, 43- and 87-point Gauss-Kronron rules
Simple adaptive quadrature, by subdivision and quadrature on each subinterval
A blind global...
In this chapter, we have mastered all the different methods to compute differentiation and integration of functions. We learned that the scipy
libraries have very robust routines to compute approximations of all these operations numerically (wrapping efficient Fortran libraries when necessary). We also learned that it is possible to access other libraries in the SciPy stack to perform the operations in a symbolic or an automatic way.
In the next chapter, we will explore the theory and methodology to solve equations or systems of equations, in the context of nonlinear functions, as well as computing extrema for optimization purposes.