solve

paddle.linalg. solve ( x, y, name=None ) [source]

Computes the solution of a square system of linear equations with a unique solution for input ‘X’ and ‘Y’. Let \(X\) be a sqaure matrix or a batch of square matrices, \(Y\) be a vector/matrix or a batch of vectors/matrices, the equation should be:

\[Out = X^-1 * Y\]

Specifically, this system of linear equations has one solution if and only if input ‘X’ is invertible.

Parameters
  • x (Tensor) – A square matrix or a batch of square matrices. Its shape should be [*, M, M], where * is zero or more batch dimensions. Its data type should be float32 or float64.

  • y (Tensor) – A vector/matrix or a batch of vectors/matrices. Its shape should be [*, M, K], where * is zero or more batch dimensions. Its data type should be float32 or float64.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

The solution of a square system of linear equations with a unique solution for input ‘x’ and ‘y’. Its data type should be the same as that of x.

Return type

Tensor

Examples

>>> # a square system of linear equations:
>>> # 2*X0 + X1 = 9
>>> # X0 + 2*X1 = 8

>>> import paddle

>>> x = paddle.to_tensor([[3, 1],[1, 2]], dtype="float64")
>>> y = paddle.to_tensor([9, 8], dtype="float64")
>>> out = paddle.linalg.solve(x, y)

>>> print(out)
Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
[2., 3.])