solve

solve(x1: array, x2: array, /) array

Returns the solution of a square system of linear equations with a unique solution.

Let x1 equal \(A\) and x2 equal \(B\). If the promoted data type of x1 and x2 is real-valued, let \(\mathbb{K}\) be the set of real numbers \(\mathbb{R}\), and, if the promoted data type of x1 and x2 is complex-valued, let \(\mathbb{K}\) be the set of complex numbers \(\mathbb{C}\).

This function computes the solution \(X \in\ \mathbb{K}^{m \times k}\) of the linear system associated to \(A \in\ \mathbb{K}^{m \times m}\) and \(B \in\ \mathbb{K}^{m \times k}\) and is defined as

\[AX = B\]

This system of linear equations has a unique solution if and only if \(A\) is invertible.

Note

Whether an array library explicitly checks whether x1 is invertible is implementation-defined.

When x1 and/or x2 is a stack of matrices, the function must compute a solution for each matrix in the stack.

Parameters:
  • x1 (array) – coefficient array A having shape (..., M, M) and whose innermost two dimensions form square matrices. Must be of full rank (i.e., all rows or, equivalently, columns must be linearly independent). Should have a floating-point data type.

  • x2 (array) – ordinate (or “dependent variable”) array B. If x2 has shape (M,), x2 is equivalent to an array having shape (..., M, 1). If x2 has shape (..., M, K), each column k defines a set of ordinate values for which to compute a solution, and shape(x2)[:-2] must be compatible with shape(x1)[:-2] (see Broadcasting). Should have a floating-point data type.

Returns:

out (array) – an array containing the solution to the system AX = B for each square matrix. If x2 has shape (M,), the returned array must have shape equal to shape(x1)[:-2] + shape(x2)[-1:]. Otherwise, if x2 has shape (..., M, K)`, the returned array must have shape equal to (..., M, K), where ... refers to the result of broadcasting shape(x1)[:-2] and shape(x2)[:-2]. The returned array must have a floating-point data type determined by Type Promotion Rules.

Notes

Changed in version 2022.12: Added complex data type support.