flopscope.

flopscope.numpy.polyder

Return the derivative of the specified order of a polynomial.

Adapted from NumPy docs np.polyder

Areacore
Typecustom
NumPy Refnp.polyder
Cost
nn
Flopscope Context

Differentiate polynomial. Cost: n FLOPs.

Note.

This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in flops.polynomial is preferred. A summary of the differences can be found in the transition guide.

Parameters

p:poly1d or sequence

Polynomial to differentiate. A sequence is interpreted as polynomial coefficients, see poly1d.

m:int, optional

Order of differentiation (default: 1)

Returns

der:poly1d

A new polynomial representing the derivative.

See also

Examples

The derivative of the polynomial x3+x2+x1+1x^3 + x^2 + x^1 + 1 is:

>>> import flopscope.numpy as fnp
>>> p = flops.poly1d([1,1,1,1])
>>> p2 = flops.polyder(p)
>>> p2
poly1d([3, 2, 1])

which evaluates to:

>>> p2(2.)
17.0

We can verify this, approximating the derivative with (f(x + h) - f(x))/h:

>>> (p(2. + 0.001) - p(2.)) / 0.001
17.007000999997857

The fourth-order derivative of a 3rd-order polynomial is zero:

>>> flops.polyder(p, 2)
poly1d([6, 2])
>>> flops.polyder(p, 3)
poly1d([6])
>>> flops.polyder(p, 4)
poly1d([0])