Solve the equation a x = b for x.
Parameters : | a : array_like, shape (M, M)
b : array_like, shape (M,)
|
---|---|
Returns : | x : array, shape (M,) |
Raises : | LinAlgError :
|
Notes
linalg.solve is a wrapper to the LAPACK http://www.netlib.org/lapack routines dgesv and zgesv. The solution to the system of linear equations is computed using an LU decomposition with partial pivoting and row interchanges.
Examples
Solve the system of equations 3 * x0 + x1 = 9 and x0 + 2 * x1 = 8:
>>> a = np.array([[3,1], [1,2]])
>>> b = np.array([9,8])
>>> x = np.linalg.solve(a, b)
>>> x
array([ 2., 3.])
Check that the solution is correct:
>>> (np.dot(a, x) == b).all()
True