Topic 4 - Solving System of Linear Algebraic Equations
Topic 4 - Solving System of Linear Algebraic Equations
Where the coefficients Ai j and the constants bj are known and xi represent the unknowns.
In matrix notation the equations are written as
or, simply
1
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad
2
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad
Methods of Solution
There are two classes of methods for solving systems of linear, algebraic equations:
1. Direct methods
2. Indirect methods (iterative methods)
Direct methods
Direct methods transform the original equations into equivalent equations (equations that
have the same solution) that can be solved more easily by applying the three operations:
a) Exchanging two equations (changes sign of |A|).
b) Multiplying an equation by a nonzero constant (multiplies |A| by the same constant).
c) Multiplying an equation by a nonzero constant and then subtracting it from another
equation (leaves |A| unchanged).
Three popular direct methods are:
Elimination phase
Eq. (i ) − λ × Eq. ( j) → Eq. (i )
so as to eliminate x1 from Eqs. (b) and (c):
Eq. (b) − (− 0.5) × Eq. (a) →Eq. (b)
Eq. (c) − 0.25 × Eq. (a) → Eq. (c)
This completes the first pass. Now we pick (b) as the pivot equation and eliminate x2
from(c):
Eq. (c) − ( − 0.5) × Eq. (b) → Eq. (c)
4
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad
5
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad
After five more iterations the results would agree with the exact solution x1 = 3,
x2 = x3 = 1.
>> x=A\b
x=
1.0000
-2.0000
3.0000
Or
>> x=inv (A)*b
x=
1.0000
-2.0000
3.0000
Matlab could also solve overdetermined system which is the system of linear equations
where the number of unknowns is greater than the number of equations. The least-squares
solution is computed to find x=A\b instead of Gauss elimination algorithm.
Example 4
>> b=[11;-16;17]
b=
11
-16
17
>> x=A\b
x=
2.2857
-3.5000
0
2.5714
7
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad
m) A=[1 2 3; 4 5 6; 7 8 8] n) A=[1 2 3 0; 4 5 6 5; 7 8 8 2]
A= B=
[ 2, 1, 1 ] 2
[ -1, 1, -1 ] 3
[ 1, 2, 3 ] -10
Use linsolve to solve AX = B for the vector of unknowns X.
X = linsolve(A,B)
X=
3
1
-5
Solve the system of equations using solve.
The inputs to solve are a vector of equations,and a vector of
variables to solve the equations.
sol = solve([eqn1, eqn2, eqn3], [x, y, z ]);
Since x, y, and z are defined as syms, therefore,to display their
values, we use;
xSol = sol.x
ySol = sol.y
zSol = sol z
xSol =
3
ySol =
1
zSol =
-5