jax.scipy.linalg.companion

Contents

jax.scipy.linalg.companion#

jax.scipy.linalg.companion(a)[source]#

Construct a companion matrix.

JAX implementation of scipy.linalg.companion().

Given polynomial coefficients \(a = [a_0, a_1, \ldots, a_{n-1}]\) with \(a_0 \neq 0\), the companion matrix is the \((n-1) \times (n-1)\) matrix whose first row is \(-[a_1, a_2, \ldots, a_{n-1}] / a_0\) and whose first sub-diagonal is filled with ones.

Parameters:

a (ArrayLike) – array of shape (..., N) with N >= 2 specifying the polynomial coefficients.

Returns:

A companion matrix of shape (..., N - 1, N - 1).

Return type:

Array

Note

Unlike scipy.linalg.companion(), this function does not check at runtime that a[..., 0] is non-zero; if the leading coefficient is zero, the result will contain inf or nan entries.

Examples

>>> jax.scipy.linalg.companion(jnp.array([1., -10., 31., -30.]))
Array([[ 10., -31.,  30.],
       [  1.,   0.,   0.],
       [  0.,   1.,   0.]], dtype=float32)