Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.linalg.solve

numpy.linalg.solve(a,b)[source]

Solve a linear matrix equation, or system of linear scalar equations.

Computes the “exact” solution,x, of the well-determined, i.e., fullrank, linear matrix equationax = b.

Parameters:

a : (..., M, M) array_like

Coefficient matrix.

b : {(..., M,), (..., M, K)}, array_like

Ordinate or “dependent variable” values.

Returns:

x : {(..., M,), (..., M, K)} ndarray

Solution to the system a x = b. Returned shape is identical tob.

Raises:

LinAlgError

Ifa is singular or not square.

Notes

New in version 1.8.0.

Broadcasting rules apply, see thenumpy.linalg documentation fordetails.

The solutions are computed using LAPACK routine _gesv

a must be square and of full-rank, i.e., all rows (or, equivalently,columns) must be linearly independent; if either is not true, uselstsq for the least-squares best “solution” of thesystem/equation.

References

[R48]G. Strang,Linear Algebra and Its Applications, 2nd Ed., Orlando,FL, Academic Press, Inc., 1980, pg. 22.

Examples

Solve the system of equations3*x0+x1=9 andx0+2*x1=8:

>>>a=np.array([[3,1],[1,2]])>>>b=np.array([9,8])>>>x=np.linalg.solve(a,b)>>>xarray([ 2.,  3.])

Check that the solution is correct:

>>>np.allclose(np.dot(a,x),b)True

Previous topic

numpy.trace

Next topic

numpy.linalg.tensorsolve

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp