Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Mathematics and Algorithms > Matrices and Linear Algebra > Linear Systems >

LinearSolve

LinearSolve[m, b]
finds an x which solves the matrix equation m.xEqualb.
LinearSolve[m]
generates a LinearSolveFunction[...] which can be applied repeatedly to different b.
  • The argument b can be either a vector or a matrix.  »
  • The matrix m can be square or rectangular.  »
  • For underdetermined systems, LinearSolve will return one of the possible solutions; Solve will return a general solution.  »
  • LinearSolve[m, b, ZeroTest->test] evaluates test[m[[i, j]]] to determine whether matrix elements are zero. The default setting is ZeroTest->Automatic.
  • A Method option can also be given. Settings for exact and symbolic matrices include "CofactorExpansion", "DivisionFreeRowReduction" and "OneStepRowReduction". Settings for approximate numerical matrices include "Cholesky", and for sparse arrays "Multifrontal" and "Krylov". The default setting of Automatic switches among these methods depending on the matrix given.
Find the solution x to m.x = b with exact arithmetic:
Find the solution using numerical methods with machine numbers:
Find the solution using numerical methods with 20-digit arithmetic:
Find a solution even when the matrix is singular:
In this case there is no solution:
Find a solution for a rectangular matrix:
Solve m.x = b for x when b is a matrix:
When no right-hand side b for m.x = b is given, a LinearSolveFunction is returned:
This contains data to solve the problem quickly for a given value of b:
Sparse methods are used for sparse matrices:
s is a large sparse matrix:
Solve s.x = b using a direct multifrontal method:
Solve s.x = b using an iterative Krylov subspace method:
Find the solution x to m.x = b modulo 47:
Verify the solution.
Newton's method for finding a root of a multivariate function:
Approximately solve the boundary value problem u_(xx) + u = f; u(0) = u(1) = 0:
Show the error compared with the exact solution:
m is a 3×3 matrix:
A system of linear equations:
The solution computed by Solve:
The solution computed by LinearSolve:
Verify they are the same:
If m is nonsingular, the solution x of m.x = b is the inverse of m when b is the identity matrix:
In this case there is no solution to m.x=b:
Use LeastSquares to minimize ||m.x-b||:
Compare to general minimization:
There are multiple solutions to m.x=0:
Use NullSpace to get the complete spanning set of solutions:
Solution found for an underdetermined system is not unique:
All solutions found by Solve:
With ill-conditioned matrices, numerical solutions may not be very good:
The solution is resolved better if sufficient precision is used:
Solve 100,000 equations using direct methods:
Solve a million equations using iterative methods:
New in 1 | Last modified in 5
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team