linalg.solve
Description
Solve a linear matrix equation, or system of linear scalar equations.
It computes the "exact" solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.
Mandatory Input Parameters
Parameter |
Type |
Description |
|---|---|---|
a |
(…,M,M) array_like |
Coefficient matrix |
b |
{(…,M,),(…,M,K)}, array_like |
Ordinate or dependent variable values |
Optional Input Parameters
None
Return Value
Type |
Description |
|---|---|
{(…, M,), (…, M, K)} ndarray |
Solution to the system ax = b. The returned shape is identical to b. |
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | >>> import numpy as np >>> # Solve the system of equations x0 + 2*x1 = 1, 3*x0 + 5*x1 = 2. >>> a = np.array([[1,2],[3,5]]) >>> a array([[1, 2], [3, 5]]) >>> b = np.array([1,2]) >>> b array([1, 2]) >>> >>> x = np.linalg.solve(a, b) >>> x array([-1., 1.]) >>> >>> np.allclose(np.dot(a,x), b) True >>> |
Parent topic: Linear Algebra Functions