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\) andx2
equal \(B\). If the promoted data type ofx1
andx2
is real-valued, let \(\mathbb{K}\) be the set of real numbers \(\mathbb{R}\), and, if the promoted data type ofx1
andx2
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/orx2
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
. Ifx2
has shape(M,)
,x2
is equivalent to an array having shape(..., M, 1)
. Ifx2
has shape(..., M, K)
, each columnk
defines a set of ordinate values for which to compute a solution, andshape(x2)[:-2]
must be compatible withshape(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. Ifx2
has shape(M,)
, the returned array must have shape equal toshape(x1)[:-2] + shape(x2)[-1:]
. Otherwise, ifx2
has shape(..., M, K)`
, the returned array must have shape equal to(..., M, K)
, where...
refers to the result of broadcastingshape(x1)[:-2]
andshape(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.