Solve a system of linear equations
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
linsolve(eqs
,options
) linsolve(eqs
,vars
,options
)
linsolve(eqs, vars)
solves a system of linear
equations with respect to the unknowns vars
.
linsolve(eqs, < vars , < ShowAssumptions >>)
solves
the linear system eqs
with respect to the unknowns vars
.
If no unknowns are specified, then linsolve
solves
for all indeterminates in eqs
; the unknowns are
determined internally by indets(eqs,PolyExpr)
.
linsolve(eqs, vars, Domain = R)
solves the
system over the domain R
,
which must be a field, i.e., a domain of category Cat::Field
.
Note:
Note that the return format does not allow to return kernel
elements if elements of the domain 
Each element of eqs
must be either an equation
or an arithmetical
expression f
, which is considered to be
equivalent to the equation f = 0
.
The unknowns in vars
need not be identifiers or indexed identifiers; expressions
such as sin(x)
, f(x)
, or y^(1/3)
are
allowed as well. More generally, any expression accepted as indeterminate
by poly
is a
valid unknown.
If the option ShowAssumptions
is not given
and the system is solvable, then the return value is a list of equations
of the form var = value
, where var
is
one of the unknowns in vars
and value
is
an arithmetical
expression that does not involve any of the unknowns
on the left side of a returned equation. Note that if the solution
manifold has dimension greater than zero, then some of the unknowns
in vars
will occur on the right side of some returned
equations, representing the degrees of freedom. See Example 2.
If vars
is a list,
then the solved equations are returned in the the same order as the
unknowns in vars
.
The function linsolve
can only solve systems
of linear equations. Use solve
for
nonlinear equations.
linsolve
is an interface function to the
procedures numeric::linsolve
and linalg::matlinsolve
.
For more details see the numeric::linsolve
, linalg::matlinsolve
help
pages and the background section of this help page.
The system eqs
is checked for linearity.
Since such a test can be expensive, it is recommended to use numeric::linsolve
or linalg::matlinsolve
directly
when you know that the system is linear.
Note:

Equations and variables may be entered as sets or lists:
linsolve({x + y = 1, 2*x + y = 3}, {x, y}), linsolve({x + y = 1, 2*x + y = 3}, [x, y]), linsolve([x + y = 1, 2*x + y = 3], {x, y}), linsolve([x + y = 1, 2*x + y = 3], [x, y])
Also expressions may be used as variables:
linsolve({cos(x) + sin(x) = 1, cos(x)  sin(x) = 0}, {cos(x), sin(x)})
Furthermore, indexed identifiers are valid, too:
S := linsolve({2*a[1] + 3*a[2] = 5, 7*a[2] + 11*a[3] = 13, 17*a[3] + 19*a[1] = 23}, {a[1], a[2], a[3]})
Assign individual solutions to variables using assign
.
Alternatively, access the solution by indexing into S
:
assign(S): a[1]; a2_val := S[2][2];
Delete a
for use in further computations.
delete a;
Next, we demonstrate the use of option Domain
and
solve a system over the field ℤ_{23} with
it:
linsolve([2*x + y = 1, x  y = 0], Domain = Dom::IntegerMod(23))
The following system does not have a solution:
linsolve({x + y = 1, 2*x + 2*y = 3}, {x, y})
If the solution of the linear system is not unique, then some
of the unknowns are used as "free parameters" spanning the solution
space. In the following example the unknown z
is
such a parameter. It does not appear on the left side of the solved
equations:
eqs := [x + y = z, x + 2*y = 0, 2*x  z = 3*y, y + z = 0]:
vars := [w, x, y, z]:
linsolve(eqs, vars)
If you use the Normal
option, linsolve
calls
the normal
function
for final results. This call ensures that linsolve
returns
results in normalized form:
linsolve([x + a*y = a + 1, b*x  y = b  1], {x, y})
If you specify Normal = FALSE
, linsolve
does
not call normal
for
the final result:
linsolve([x + a*y = a + 1, b*x  y = b  1], {x, y}, Normal = FALSE)
Solve this system:
eqs := [x + a*y = b, x + A*y = b]:
linsolve(eqs, [x, y])
Note that more solutions exist for a = A
. linsolve
omits
these solutions because it makes some additional assumptions on symbolic
parameters of this system. To see the assumptions that linsolve
made
while solving this system, use the ShowAssumptions
option:
linsolve(eqs, [x, y], ShowAssumptions)
delete eqs:

A list or a set of linear equations or arithmetical expressions 

A list or a set of unknowns to solve for: typically identifiers or indexed identifiers 

Option, specified as Solve the system over the field 

Option, specified as Return normalized results. The value By default, To avoid this additional call, specify 

Return information about internal assumptions that With this option, When Gaussian elimination produces an equation 
Without the ShowAssumptions
option, a list
of simplified equations is returned. It represents the general solution
of the system eqs
. FAIL
is returned if
the system is not solvable.
With ShowAssumptions
, a list [Solution,
Constraints, Pivots]
is returned. Solution
is
a list of simplified equations representing the general solution of eqs
.
The lists Constraints
and Pivots
contain
equations and inequalities involving symbolic parameters in eqs
.
Internally, these were assumed to hold true when solving the system.
If the option Domain
is not present, the
system is solved by calling numeric::linsolve
with
the option Symbolic
.
If the option Domain = R
is given and R
is
either Dom::ExpressionField
()
or Dom::Float
, then numeric::linsolve
is
used to compute the solution of the system. This function uses a sparse
representation of the equations.
Otherwise, eqs
is first converted into a
matrix and then solved by linalg::matlinsolve
.
A possibly sparse structure of the input system is not taken into
account.