Reader small image

You're reading from  Mastering SciPy

Product typeBook
Published inNov 2015
Reading LevelIntermediate
Publisher
ISBN-139781783984749
Edition1st Edition
Languages
Right arrow
Authors (2):
Francisco Javier Blanco-Silva
Francisco Javier Blanco-Silva
author image
Francisco Javier Blanco-Silva

I will always be indebted to Bradley J. Lucier and Rodrigo Bañuelos, for being a constant inspiration, for their guidance and teachings. Special thanks to my editors, Sriram Neelakantam, Bharat Patil, Nikhil Potdukhe, and Mohammad Rizvi. Many colleagues have contributed with encouragement and fruitful discussions. In particular, I would like to mention Parsa Bakhtary, Aaron Dutle, Edsel Peña, Pablo Sprechmann, Adam Taylor, and Holly Watson. But the most special thanks go without a doubt to my wife and daughter. Grace's love and smiles alone provided all the motivation, enthusiasm and skills to overcome any difficulties encountered during the pursuit of this book, and everything life threw at me ever since she was born.
Read more about Francisco Javier Blanco-Silva

View More author details
Right arrow

Chapter 3. Differentiation and Integration

In this chapter, we will master some classical and state-of-the-arts techniques to perform the two core operations in Calculus (and, by extension, in Physics and every engineering field): differentiation and integration of functions.

Motivation


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...

Differentiation


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...

Integration


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...

Summary


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.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering SciPy
Published in: Nov 2015Publisher: ISBN-13: 9781783984749
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Francisco Javier Blanco-Silva

I will always be indebted to Bradley J. Lucier and Rodrigo Bañuelos, for being a constant inspiration, for their guidance and teachings. Special thanks to my editors, Sriram Neelakantam, Bharat Patil, Nikhil Potdukhe, and Mohammad Rizvi. Many colleagues have contributed with encouragement and fruitful discussions. In particular, I would like to mention Parsa Bakhtary, Aaron Dutle, Edsel Peña, Pablo Sprechmann, Adam Taylor, and Holly Watson. But the most special thanks go without a doubt to my wife and daughter. Grace's love and smiles alone provided all the motivation, enthusiasm and skills to overcome any difficulties encountered during the pursuit of this book, and everything life threw at me ever since she was born.
Read more about Francisco Javier Blanco-Silva