Solution of Systems of Linear Equations

You can use the operation solve to solve systems of linear equations. The operation solve takes two arguments, the list of equations and the list of the unknowns to be solved for. A system of linear equations need not have a unique solution. To solve the linear system:

            x + y + x = 8
        3*x - 2*y + z = 0
        x + 2*y + 2*z = 17

evaluate this expression.

Parameters are given as new variables starting with a percent sign and "%" and the variables are expressed in terms of the parameters. If the system has no solutions then the empty list is returned. When you solve the linear system

          x + 2*y + 3*z = 2
        2*x + 3*y + 4*z = 2
        3*x + 4*y + 5*z = 2

with this expression you get a solution involving a parameter.

The system can also be presented as a matrix and a vector. The matrix contains the coefficients of the linear equations and the vector contains the numbers appearing on the right-hand sides of the equations. You may input the matrix as a list of rows and the vector as a list of its elements. To solve the system:

           x + y + z = 8
       2*x - 2*y + z = 0
       x + 2*y + 2*z = 17

in matrix form you would evaluate this expression.

The solutions are presented as a Record with two components: the component particular contains a particular solution of the given system or the item "failed" if there are no solutions, the component basis contains a list of vectors that are a basis for the space of solutions of the corresponding homogeneous system. If the system of linear equations does not have a unique solution, then the basis component contains non-trivial vectors. This happens when you solve the linear system

        x + 2*y + 3*z = 2
      2*x + 3*y + 4*z = 2
      3*x + 4*y + 5*z = 2

with this command.

All solutions of this system are obtained by adding the particular solution with a linear combination of the basis vectors. When no solution exists then "failed" is returned as the particular component, as follows:

When you want to solve a system of homogeneous equations (that is, a system where the numbers on the right-hand sides of the equations are all zero) in the matrix form you can omit the second argument and use the nullSpace operation. This computes the solutions of the following system of equations:

        x + 2*y + 3*z = 0
      2*x + 3*y + 4*z = 0
      3*x + 4*y + 5*z = 0

The result is given as a list of vectors and these vectors form a basis for the solution space.