1
©2009 by L. Lagerstrom
Solving Systems of Linear Equations
• For an introduction to the basic concepts, see the
associated video clip
• Solution by matrix inversion
• Solution by matrix division
• Checking a solution exists
• Intersection of two lines
Matlab code
Command window display
©2009 by L. Lagerstrom
Solution by Matrix Inversion
%Consider the following 3 equations
%in 3 unknowns:
%
3*x1 + 2*x2 
x3 = 10
%
x1 + 3*x2 + 2*x3 =
5
%
x1 
x2 
x3 = 1
%We write this in Ax = b form, where
%A is the matrix of coefficients,
%x is a column vector with the
%elements x1, x2, and x3, and b is
%a column vector with 10, 5, 1:
A = [3 2 1; 1 3 2; 1 1 1]
b = [10; 5; 1]
%Find x by getting the inverse of A
%and multiplying it by b:
x = inv(A)*b
%Remember: Before writing down A and
%b, all the terms in the 3 equations
%must be lined up properly and all
%the constants must be on the right
%side of the equations.
A =
3
2
1
1
3
2
1
1
1
b =
10
5
1
x =
2.00
5.00
6.00
Matlab code
Command window display
©2009 by L. Lagerstrom
Solution by Matrix Division
%Alternatively, we can solve for x
%by matrix division (the underlying
%method uses a technique called
%"Gauss elimination"):
%Define A and b as before:
A = [3 2 1; 1 3 2; 1 1 1]
b = [10; 5; 1]
%Find x by using the left division
%operator:
x = A\b
%This time we'll also confirm that
%the values in x solve the equations
%by plugging in x and seeing if
%we get b (i.e., A*x should = b):
result = A*x
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '10
 Lagerstrom
 Linear Algebra, Vector Space, Linear map, L. Lagerstrom

Click to edit the document details