scipy.linalg.solve(a, b, sym_pos=False, lower=False, overwrite_a=False, overwrite_b=False, debug=False)[source]

Solve the equation a x = b for x.

Parameters :

a : array_like, shape (M, M)

A square matrix.

b : array_like, shape (M,) or (M, N)

Right-hand side matrix in a x = b.

sym_pos : bool

Assume a is symmetric and positive definite.

lower : boolean

Use only data contained in the lower triangle of a, if sym_pos is true. Default is to use upper triangle.

overwrite_a : bool

Allow overwriting data in a (may enhance performance). Default is False.

overwrite_b : bool

Allow overwriting data in b (may enhance performance). Default is False.

Returns :

x : array, shape (M,) or (M, N) depending on b

Solution to the system a x = b.

Raises :

LinAlgError :

If a is singular.


Given a and b, solve for x:

>>> a = np.array([[3,2,0],[1,-1,0],[0,5,1]])
>>> b = np.array([2,4,-1])
>>> x = linalg.solve(a,b)
>>> x
array([ 2., -2.,  9.])
>>>, x) == b
array([ True,  True,  True], dtype=bool)

Previous topic


Next topic