LinearAlgebra - Maple Programming Help

Home : Support : Online Help : Mathematics : Linear Algebra : LinearAlgebra Package : Solvers : LinearAlgebra/LinearSolve

LinearAlgebra

 LinearSolve
 solve the linear equations A . x = b

 Calling Sequence LinearSolve(A, B, m, t, c, ip, options, methopts)

Parameters

 A - Matrix or list B - (optional) Matrix or column Vector m - (optional) equation of the form method = name where name is one of 'none', 'solve', 'subs', 'Cholesky', 'LU', 'QR', 'hybrid', 'modular', 'SparseLU', 'SparseDirect', or 'SparseIterative'; method to use t - (optional) equation of the form free = name; base name to use for free variables in parametrized solutions c - (optional) BooleanOpt(conjugate); specifies whether to use the Hermitian transpose in the case of Cholesky or QR decomposition methods ip - (optional) BooleanOpt(inplace); specifies if output overwrites the second argument B options - (optional); constructor options for the result object methopts - (optional) equation of the form $\mathrm{methodoptions}=\mathrm{list}$; options to control the solution method

Description

 • The LinearSolve function returns the Vector or Matrix x that satisfies the linear system $A\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}x=B$.
 If B is included in the calling sequence as a Matrix or a Vector, then the returned object is of the same type.
 If B is omitted, then the linear system is interpreted from the first argument, which is taken to be the augmented linear system A|B, where B is a column Vector.
 The dimensions of the returned object agree with the Matrix equation $A\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}x=B$. If A is m x n and B is m x p, then the solution x will be n x p.
 If the solution x is computed inplace upon B, then n must be at least as large as m.
 • If method='subs' is specified in the calling sequence, then the first argument must be a Matrix with triangular shape. If it is upper triangular, then the Matrix is assumed to be in upper echelon form and back substitution is performed by using BackwardSubstitute. If the Matrix is lower triangular, then forward substitution is performed by using ForwardSubstitute.
 • If the first argument is a list, then the elements of the list are taken as the Matrix factors of the Matrix A, due to some prefactorization. These factors are interpreted, uniquely, as follows:
 *   A list of Vector, Matrix items, $\left[\mathrm{ipiv},\mathrm{LU}\right]$, is interpreted as the result of calling LUDecomposition with the output='NAG' option. The first member is taken as the pivot Vector and the second member as the superimposed LU factors. The implied option is method=LU.
 *   A list of Matrix, Matrix, Matrix items, $\left[P,L,U\right]$, is interpreted as the result of calling LUDecomposition with the $\mathrm{output}=\left['P','L','U'\right]$ option. The implied option is method=LU.
 *   A list of a Matrix item, $\left[L\right]$, is interpreted as the result of a Cholesky decomposition. The data is taken as the lower triangle of the Matrix. The implied option is $\mathrm{method}=\mathrm{Cholesky}$.
 *   A list of Matrix, Vector items, $\left[\mathrm{QR},\mathrm{\tau }\right]$, is interpreted as the result of calling QRDecomposition with the output='NAG' option. The implied option is method=QR.
 *   A list of Matrix, Matrix items, $\left[Q,R\right]$, is interpreted as the result of calling QRDecomposition with the $\mathrm{output}=\left['Q','R'\right]$ option. The implied option is method=QR.
 The sparse methods cannot be used with prefactored input.
 • The $\mathrm{method}='\mathrm{SparseIterative}'$ option is compatible with real symmetric or complex hermitian Matrices having storage mode sparse[lower] or sparse[upper].  It is also compatible with real nonsymmetric or complex nonhermitian Matrices which are square and have storage mode sparse.  This is the default method when such a matrix is specified. The method='SparseDirect' option is compatible with real, square Matrices having storage mode sparse.
 • The method='hybrid' option provides a LU based solver which operates in part in both hardware and software float modes. This can be a more efficient solver at high settings of Digits. It computes the LU decomposition in hardware floating-point mode and then does iterative refinement in software floating-point mode.
 • The use of the method='modular' option invokes the LinearAlgebra[Modular][IntegerLinearSolve] routine. It can compute rational solutions for an integer input Matrix. The system is solved $\mathrm{mod}'p'$ for a machine size prime and p-adic lifting is used to construct the rational solutions.
 • The inplace option (ip) determines where the result is returned. In the case of a non-augmented system, if inplace=true is specified in the calling sequence, the computation is performed directly on the second argument. The inplace option is not allowed for an augmented system, or with method='solve'.
 The inplace=true condition can be abbreviated to inplace.
 The inplace option must be used with caution since, if the operation fails, the original argument may be corrupted.
 • The conjugate option (c) specifies whether to use HermitianTranspose in the solution of a system using Cholesky or QRDecomposition methods. The default is true. The conjugate=true condition can be abbreviated as conjugate.
 • The constructor options provide additional information (readonly, shape, storage, order, datatype, and attributes) to the Vector or Matrix constructor that builds the result. These options may also be provided in the form outputoptions=[...], where [...] represents a Maple list.  If a constructor option is provided in both the calling sequence directly and in an outputoptions option, the latter takes precedence (regardless of the order).
 • The methodoptions option (methopts) provides ways to control the behavior of the solution method.  Currently, the only options available are used with $\mathrm{method}=\mathrm{SparseIterative}$.  For more information, see Sparse Iterative Solver Options.
 • The inplace and constructor options are mutually exclusive.
 • This function is part of the LinearAlgebra package, and so it can be used in the form LinearSolve(..) only after executing the command with(LinearAlgebra). However, it can always be accessed through the long form of the command by using LinearAlgebra[LinearSolve](..).

Examples

 > $\mathrm{with}\left(\mathrm{LinearAlgebra}\right):$
 > $M≔⟨⟨1,1,1,4⟩|⟨1,1,-2,1⟩|⟨3,1,1,8⟩|⟨-1,1,-1,-1⟩|⟨0,1,1,0⟩⟩:$
 > $\mathrm{M_sol}≔\mathrm{LinearSolve}\left(M\right)$
 ${\mathrm{M_sol}}{≔}\left[\begin{array}{c}\frac{{25}}{{6}}\\ \frac{{4}}{{3}}\\ {-}\frac{{5}}{{2}}\\ {-}{2}\end{array}\right]$ (1)
 > ${M}_{1..-1,1..-2}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{M_sol}={M}_{1..-1,-1}$
 $\left[\begin{array}{r}{0}\\ {1}\\ {1}\\ {0}\end{array}\right]{=}\left[\begin{array}{r}{0}\\ {1}\\ {1}\\ {0}\end{array}\right]$ (2)
 > $A≔⟨⟨1,0,0⟩|⟨2,1,0⟩|⟨1,0,0⟩|⟨-1,-1,-3⟩⟩:$
 > $b≔⟨2,-1,-9⟩:$
 > $\mathrm{LinearSolve}\left(A,b,\mathrm{method}='\mathrm{subs}',\mathrm{free}='s'\right)$
 $\left[\begin{array}{c}{1}{-}{{s}}_{{1}}\\ {2}\\ {{s}}_{{1}}\\ {3}\end{array}\right]$ (3)
 > $P≔⟨⟨4,2,-1⟩|⟨2,4,3⟩|⟨-1,3,5⟩⟩:$
 > $z≔⟨1,0,0⟩:$
 > $\mathrm{LinearSolve}\left(P,z,\mathrm{method}='\mathrm{Cholesky}',\mathrm{inplace}\right)$
 $\left[\begin{array}{c}\frac{{11}}{{8}}\\ {-}\frac{{13}}{{8}}\\ \frac{{5}}{{4}}\end{array}\right]$ (4)
 > $z$
 $\left[\begin{array}{c}\frac{{11}}{{8}}\\ {-}\frac{{13}}{{8}}\\ \frac{{5}}{{4}}\end{array}\right]$ (5)
 > $S≔\mathrm{Matrix}\left(\left[\left[5,0,0,0,0,0\right],\left[0,2,-1,2,0,0\right],\left[0,0,3,0,0,0\right],\left[-2,0,0,1,1,0\right],\left[1,0,0,1,2,3\right],\left[1,1,0,0,0,6\right]\right],\mathrm{datatype}=\mathrm{float},\mathrm{storage}=\mathrm{sparse}\right):$
 > $t≔\mathrm{Vector}\left(\left[15,12,18,3,-6,0\right],\mathrm{datatype}=\mathrm{float}\right):$
 > $\mathrm{LinearSolve}\left(S,t,\mathrm{method}='\mathrm{SparseIterative}'\right)$
 $\left[\begin{array}{c}{3.00000000000000}\\ {-}{33.0000000000000}\\ {6.00000000000000}\\ {42.0000000000000}\\ {-}{33.}\\ {5.}\end{array}\right]$ (6)
 > $N≔⟨⟨0,1,1,1,1⟩|⟨2,-2,0,-2,-3⟩|⟨0,0,1,1,3⟩|⟨-6,0,-3,-1,-3⟩|⟨2,2,2,2,4⟩⟩:$
 > $q,r≔\mathrm{QRDecomposition}\left(N,\mathrm{output}=\left['Q','R'\right]\right):$
 > $C≔⟨⟨1,6,0,9,4⟩|⟨1,2,3,4,5⟩⟩:$
 > $\mathrm{C_sol}≔\mathrm{LinearSolve}\left(\left[q,r\right],C\right)$
 ${\mathrm{C_sol}}{≔}\left[\begin{array}{cc}{4}& \frac{{8}}{{3}}\\ {-}{13}& {-}\frac{{7}}{{3}}\\ {-}\frac{{11}}{{2}}& \frac{{1}}{{6}}\\ {-}\frac{{17}}{{2}}& {-}\frac{{11}}{{6}}\\ {-}{12}& {-}\frac{{8}}{{3}}\end{array}\right]$ (7)
 > $N\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}.\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{C_sol}=C$
 $\left[\begin{array}{rr}{1}& {1}\\ {6}& {2}\\ {0}& {3}\\ {9}& {4}\\ {4}& {5}\end{array}\right]{=}\left[\begin{array}{rr}{1}& {1}\\ {6}& {2}\\ {0}& {3}\\ {9}& {4}\\ {4}& {5}\end{array}\right]$ (8)