Introduction

The evaluation of special functions

The scipy.special module contains numerically stable definitions of useful functions. Most often, the straightforward evaluation of a function at a single value is not very efficient. For instance, we would rather use a Horner scheme (http://en.wikipedia.org/wiki/Horner%27s_method) than a formula to find the value of a polynomial at a point. The NumPy and SciPy modules ensure that this optimization is always guaranteed with the definition of all its functions, whether by means of Horner schemes or with more advanced techniques.

Convenience and test functions

  • All the convenience functions are designed to facilitate a computational environment where the user does not need to worry about relative errors. The functions seem to be pointless at first sight, but behind their codes, there are state-of-the-art ideas that offer faster and more reliable results.
  • We have convenience functions beyond the ones defined in the NumPy libraries to find the solutions of trigonometric functions in degrees (cosdg, sindg, tandg, and cotdg); to compute angles in radians from their expressions in degrees, minutes, and seconds (radian); common powers (exp2 for 2**x, and exp10 for 10**x); and common functions for small values of the variable (log1p for log(1 + x), expm1 for exp(x) - 1, and cosm1 for cos(x) - 1).
  • For instance, in the following code snippet, the log1p function computes the natural logarithm of 1 + x. Why not simply add 1 to the value of x and then take the logarithm instead? Let's compare.

We need to perform the following steps:

  1. Execute the following code:
import numpy
import scipy.special
a=scipy.special.exp10(-16)
numpy.log(1+a)
  1. The output is as follows:
0.0
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset