solve#

ivy.solve(x1, x2, /, *, adjoint=False, out=None)[source]#

Return the solution x to the system of linear equations represented by the well- determined (i.e., full rank) linear matrix equation Ax = B.

Parameters:
  • x1 (Union[Array, NativeArray]) – 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 (Union[Array, NativeArray]) – ordinate (or “dependent variable”) array B. If x2 has shape (M,1), 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)[:-1] must be compatible with shape(x1)[:-1] (see Broadcasting). Should have a floating-point data type.

  • adjoint (bool, default: False) – specifies whether the system should be solved for x1 or adjoint(x1)

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

  • ret – an array containing the solution to the system AX = B (or adjoint(A)X = B) for each square matrix. The returned array must have the same shape as x2 (i.e., the array corresponding to B) and must have a floating-point data type determined by Type Promotion Rules.

  • This function conforms to the `Array API Standard

  • <https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)

  • `docstring <https (//data-apis.org/array-api/latest/)

  • extensions/generated/array_api.linalg.solve.html>`_

  • in the standard.

  • Both the description and the type hints above assume an array input for simplicity,

  • but this function is nestable, and therefore also accepts ivy.Container

  • instances in place of any of the arguments.

Examples

With class:ivy.Array input: >>> A = ivy.array([[1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3]]), >>> B = ivy.array([[1.1], [2.1], [3.1]]), >>> x = ivy.solve(A,B); >>> print(x) ivy.array([[1],

[0], [0]])

>>> print(x.shape)
(1,3)

With shape(A) = (2,3,3) and shape(B) = (2,3,1): >>> A = ivy.array([[[11.1, 11.2, 11.3],[12.1, 12.2, 12.3],[13.1, 13.2, 13.3]], [[21.1, 21.2, 21.3],[22.1, 22.2, 22.3],[23.1, 23.2, 23.3]]]), >>> B = ivy.array([[[11.1],

[12.1], [13.1]],

[[21.1],

[22.1], [23.1]]]),

>>> x = ivy.solve(A,B);
>>> print(x)
ivy.array([[[1],
            [0],
            [0]],
           [[1],
            [0],
            [0]]])
>>> print(x.shape)
(2,1,3)

With shape(A) = (3,3) and shape(B) = (3,2): >>> A = ivy.array([[1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3]]), >>> B = ivy.array([[1.1, 2.2], [2.1, 4.2], [3.1, 6.2]]), >>> x = ivy.solve(A,B); >>> print(x) ivy.array([[[1],

[0], [0]],

[[2],

[0], [0]]])

>>> print(x.shape)
(2,1,3)

With class:ivy.Container input: >>> A = ivy.array([[1.1, 1.2, 1.3], [2.1, 2.2, 2.3], [3.1, 3.2, 3.3]]), >>> B = ivy.container(B1 = ivy.array([[1.1], [2.1], [3.1]]),

B2 = ivy.array([[2.2], [4.2], [6.2]]))

>>> x = ivy.solve(A,B);
>>> print(x)
{
    B1:([[1],[0],[0]]),
    B2:([[2],[0],[0]])
}
Array.solve(self, x2, /, *, adjoint=False, out=None)[source]#
Return type:

Array

Container.solve(self, x2, /, *, adjoint=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
Return type:

Container