API reference

exampy

exampy.square(x)[source]

The square of a number

Parameters:x (float) – Number to square
Returns:Square of x
Return type:float
exampy.cube(x)[source]

The cube of a number

Calculates and returns the cube of any floating-point number; note that, as currently written, the function also works for arrays of floats, ints, arrays of ints, and more generally, any number or array of numbers.

Parameters:x (float) – Number to cube
Returns:Cube of x
Return type:float
Raises:No exceptions are raised.

See also

exampy.square()
Square of a number
exampy.Pow()
a number raised to an arbitrary power

Notes

Implements the standard cube function

\[f(x) = x^3\]

History:

2020-03-04: First implementation - Bovy (UofT)

References

[1]A. Mathematician, “x to the p-th power: squares, cubes, and their general form,” J. Basic Math., vol. 2, pp. 2-3, 1864.
class exampy.Pow(p=2.0)[source]

A class to compute the power of a number

__init__(p=2.0)[source]

Initialize a PowClass instance

Parameters:p (float, optional) – Power to raise x to
Pow.__call__(x)[source]

Evaluate x^p

Parameters:x (float) – Number to raise to the power p
Returns:x^p
Return type:float

exampy.integrate

exampy.integrate.riemann(func, a, b, n=10)[source]

A simple Riemann-sum approximation to the integral of a function

Parameters:
  • func (callable) – Function to integrate, should be a function of one parameter
  • a (float) – Lower limit of the integration range
  • b (float) – Upper limit of the integration range
  • n (int, optional) – Number of intervals to split [a,b] into for the Riemann sum
Returns:

Integral of func(x) over [a,b]

Return type:

float

exampy.integrate.simps(func, a, b, n=10)[source]

Integrate a function using Simpson’s rule

Parameters:
  • func (callable) – Function to integrate, should be a function of one parameter
  • a (float) – Lower limit of the integration range
  • b (float) – Upper limit of the integration range
  • n (int, optional) – Number of major intervals to split [a,b] into for the Simpson rule
Returns:

Integral of func(x) over [a,b]

Return type:

float

Notes

Applies Simpson’s rule as

\[ \begin{align}\begin{aligned}\int_a^b \mathrm{d}x f(x) \approx \frac{(b-a)}{6n}\,\left[f(a)+4f(a+h/2)+2f(a+h)+4f(a+3h/2)+\\\ldots+2f(b-h)+4f(b-h/2)+f(b)\right]\end{aligned}\end{align} \]

See also

exampy.integrate.riemann()
Integrate a function with a simple Riemann sum