Functions > Solving and Optimization > Example: Solving a Linear System of Equations
Example: Solving a Linear System of Equations
Solve a linear system of n equations in n unknowns using the lsolve function or using solve blocks.
Using lsolve
1. Assume that you have the following set of equations (defined using the equal to operator):
2. Create a nonsingular matrix corresponding to the above system of equations:
3. Create the vector of constants corresponding to the above system of equations:
4. Use the lsolve function to find the solution:
Using Solve Blocks
You can also solve the above system of equations using a solve block.
 If you cast the system as a matrix times an unknown vector X, you must solve for all variables in the vector at once. You cannot hold any of the vector elements constant in this formulation.
1. Provide a guess values vector X:
2. Insert a solve block, then use the find function to solve the above system of equations:
 The guess values vector X must be defined before and outside the solve block.
Solve Blocks - Solving for Matrices
1. Define the set of algebraic Riccati equation (from system and control theory):
2. Define the initial guess matrix as an identity matrix:
3. Use the Find function to solve the above set of equations:
Units in Solve Blocks
1. Set V1, V2 and V3 to 1 volt:
2. Define and solve the system of equations with three unknowns: