scipy
01 Dec 2016scipy is a specialist library for dealing with mathematical, science and engineering problems. According to their website:
The SciPy library, a collection of numerical algorithms and domain-specific toolboxes, including signal processing, optimization, statistics and much more.
The library itself is such a broad topic, so for the purposes of today’s article I just want to focus on a few items (from numpy) listed in their basic functions area covering polynomials and then finish up with the integration library.
Polynomials
A quick brush-up on some high school math (thanks wikipedia) tells us that a polynomial is an expression of more than two algebraic terms; these are normally variables (or indeterminates) and co-efficients.
Our polynomial with just one variable:
Let’s get scipy to represent this for us:
This gives us an output of:
Derivative
Lets derive this function, to find the formula that defines its instantaneous rate of change:
We can get scipy to this for us using the deriv function:
Confirming everything for us, we now receive the derivative:
Integral
We’ll integrate the same function now, providing us with the ability to calculate the area under the curve that the original polynomial would provide:
We can simply use the integ function to do this for us, again:
Providing us with the following answer:
General integration
Now that we’ve done some basic calculus with polynomials, we’ll get scipy to perform the integration for us. Using quad we specify the function that produces our values a maxima and minima value and then we’re given the integrated values.
We’ll simplify with x²
.
We’re then given the following:
To my eye, the answer is ⅓
, and performing the basic subtraction I’m given: 0.33333333333332965
. Pretty close?
This has been a really light-on tour of Scipy!