solve¶
- solve(x1: array, x2: array, /) array¶
Returns the solution of a square system of linear equations with a unique solution.
Let
x1equal \(A\) andx2equal \(B\). If the promoted data type ofx1andx2is real-valued, let \(\mathbb{K}\) be the set of real numbers \(\mathbb{R}\), and, if the promoted data type ofx1andx2is 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
x1is invertible is implementation-defined.When
x1and/orx2is a stack of matrices, the function must compute a solution for each matrix in the stack.- Parameters:
x1 (array) – coefficient array
Ahaving 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. Ifx2has shape(M,),x2is equivalent to an array having shape(..., M, 1). Ifx2has shape(..., M, K), each columnkdefines 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 = Bfor each square matrix. Ifx2has shape(M,), the returned array must have shape equal toshape(x1)[:-2] + shape(x2)[-1:]. Otherwise, ifx2has 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.
Changed in version 2024.12: Clarified broadcasting semantics and the shape of the output array.