Beruflich Dokumente
Kultur Dokumente
ALGEBRAIC EQUATIONS
3
Many of the fundamental equations of
engineering and science are based on
conservation laws.
Some familiar quantities that conform to such
laws are mass, energy, and momentum.
In mathematical terms, these principles lead
to balance or continuity equations that relate
system behavior as represented by the levels
or response of the quantity being modeled
4
Two types of systems that can be modeled using linear algebraic equations:
(a) lumped variable system that involves coupled finite components and
(b) distributed variable system that involves a continuum.
5
In lecture 2, the value x that satisfied a single
equation, f(x) = 0 is determined.
Now, we deal with the case of determining the
values x1, x2, …… xn that simultaneously satisfy a set
of equations:
f1 (x1, x2, . . . xn ) = 0
f2 (x1, x2, . . . xn ) = 0
. .
. .
fn (x1, x2, . . . xn ) = 0
6
For system of linear algebraic equation in general
form:
a11x1 + a12x2 + . . . .+ a1nxn = b1
a21x1 + a22x2 + . . . .+ a2nxn = b2
. . .
. . .
an1x1 + an2x2 + . . . .+ annxn = bn ------- (3.1)
where;
a = constant coefficients
b = constants
n = number of equations
Note: Only linear equations involve in the calculation.
7
There are 4 approaches for solving a
system of linear algebraic equations:
Naïve Gauss Elimination (Elimination
method)
Gauss-Siedel Method (iterative solution
techniques)
Gauss-Jordan Elimination
LU Decomposition Method
8
Introduction
Naïve Gauss Elimination
Gauss-Siedel Method
Solving linear equations using MATLAB
9
There are 2 steps of procedure
for solving:
i) Step 1-Forward elimination:
The equations were
manipulated to eliminate
one of unknowns from the
equations. The result - one
equation with one unknown.
10
To solve a general set of n equations (3.1):
a11x1 + a12x2 + . . . .+ a1nxn = b1
a21x1 + a22x2 + . . . .+ a2nxn = b2
. .
. .
an1x1 + an2x2 + . . . .+ annxn = bn------- (3.1)
11
In simplified form;
Ax = b -------- (3.2)
where; A = known non-singular matrix n x n
b = n x 1 matrix
x = unknown nx1 matrix (to be
calculated)
3 2 −1 𝑥1 5
1 −1 3 𝑥2 = −10
−2 1 −2 𝑥3 5 13
1. Simplified matrix
3 2 −1 ⋮ 5 (𝑅1) < - - pivotal row
1 0 −1 3 ⋮ −10 (𝑅2)
−2 0 1 −2 ⋮ 5 (𝑅3)
14
3. Then, eliminate a21: R2’ = R2 + m1R1
eliminate a31: R3’ = R3 + m2R1
m1 = -1/3 m2 =2/3
3 2 −1 5
3 2 −1 ⋮ 5 R2'=R2− 1/3 R1 5 10 ⋮ 35 𝑅1
1 −1 3 ⋮ −10 0 − ⋮ − 𝑅2′
3 3 3
R3’=R3+ 2/3 R1 7 8 ⋮ 25
−2 1 −2 ⋮ 5 0 − 𝑅3′
3 3 3
15
4. Eliminates x2 from R3’ by using R2’ as pivotal row
Pivot element, a22 = -5/3
Coefficient, m3 = - a32/a22 = -(7/3)/(-5/3) = 7/5
7 7 5
R3’’ 𝑎32 = + − =0
3 5 3
8 7 10
𝑎33 = − + =2
3 5 3
25 7 35
𝑏31 = + − = −8
3 5 3
3 2 −1 5 3 2 −1 ⋮ 5
5 10 ⋮ 35 R3''=R3' +7/5 R2' 𝑅1
0 − ⋮ − 0 −
5 10
⋮ −
35
𝑅2′
3 3 3
7 8 3 3 3
0 − ⋮ 25 0 0 2 ⋮ −8 𝑅3′′
3 3 3
16
5: Calculate x1, x2, and x3 by back substitution.
x3 = b3 /a33 = -8/2 = -4
x2 = (b2 – a23x3 )/a22 = [-35/3 – 10/3(-4) ]/(-5/3) = -1
x1 = (b1 – a12x2 – a13x3)/a11 = [5 – 2(-1) – 4 ]/3 =1
17
Answer: x1 1
x= x2 = -1
x3 -4
or
x = [1, -1, 4]T
where T = transpose matrix
18
1. In every steps, pivot element 0
2. If pivot element = 0, rearrange
the rows to lower level until pivot
element 0
3. If pivot element = 0 after rearrange;
no single solution or answer for vector x.
19
Given a set of linear equations:
10𝑥1 + 2𝑥2 − 𝑥3 = 27
− 3𝑥1 − 5𝑥2 + 2𝑥3 = −61.5
𝑥1 + 𝑥2 + 6𝑥3 = −21.5
2𝑥2 + 3𝑥3 = 8
4𝑥1 + 6𝑥2 + 7𝑥3 = −3
2𝑥1 + 𝑥2 + 6𝑥3 = 5
22
Division by zero
During both the elimination and back substitution
phase, it is possible that a division by zero could
occur
2𝑥2 + 3𝑥3 = 8
4𝑥1 + 6𝑥2 + 7𝑥3 = −3 a11 = 0
2𝑥1 + 𝑥2 + 6𝑥3 = 5
Round-Off Errors
Since computers carry a limited number of
significant figures, round off errors can occur and it
will propagate.
23
ILL Conditioned systems
Adequacy of solution depends on condition of
the system. ILL conditioned system will
produced a wide range of answers.
24
Using “Partial Pivoting”
Example: Division by zero
Determine the largest available coefficient in the
column below the pivot element.
Switched the row so that the largest element is the
pivot element. pivot element
25
Example: Round off error
26
Solve by using Gauss elimination:
0.0003x1 + 3.0000x2 = 2.0001 ....... (i)
1.0000x1 + 1.0000x2 = 1.0000 ....... (ii)
5 0.66667 0.30000 10
6 0.666667 0.330000 1
28
If equations are solved in reverse order, switched row with
the largest pivot element:
29
This case is much less sensitive to the number significant
figures in the computation
30
Introduction
Naïve Gauss Elimination
Gauss-Siedel Method
31
To solve a general set of n equations (3.1):
a11x1 + a12x2 + . . . .+ a1nxn = b1
a21x1 + a22x2 + . . . .+ a2nxn = b2
. .
. .
an1x1 + an2x2 + . . . .+ annxn = bn------- (3.1)
a11
j 1
b2 a21 x1 a23 x3
j
x2 ... 12.1(b)
j
a22
b3 a31 x1 a32 x2
j j
x3
j ... 12.1(c)
a33
xij xij 1
a ,i j
100% s ... 12.2
xi
35
1. Choosing guesses values for x2 j-1 and x3 j-1. A simple way to
obtain initial guesses is to assume that they are all zero.
2. Calculate a new value for x1=b1/a11 by substitute these
initial guess into Eq. 12.1 (a)
3. Compute a new value for x2 by substitute new value of x1
along with the previous initial value of x3 in Eq. 12.1 (b)
4. Calculate a new estimate for x3 by substitute x1 and x2
obtained from step 2 and 3.
5. Check convergence using Eq. 12.2 for all i, where j and (j-1)
are the present (new) and previous iterations(old).
6. Then, return to the first equation and repeat the entire
procedure until all our solution converges closely enough to
the true values.
37
Find X1, X2 and X3 using Gauss-Siedel method with εs=0.05%
10𝑥1 + 2𝑥2 − 𝑥3 = 27 … … … (1)
− 3𝑥1 − 5𝑥2 + 2𝑥3 = −62 … (2)
𝑥1 + 𝑥2 + 6𝑥3 = −22 … … … (3)
1) Let x2old=0, x3old=0
2) Calculate x1
27 − 2𝑥2 + 𝑥3
𝑥1 𝑛𝑒𝑤 =
10
27 − 2(0) + (0)
𝑥1 𝑛𝑒𝑤 = = 2.700
10
3) Calculate x2, x1=2.7, x3=0;
𝑛𝑒𝑤
−62 + 3𝑥1 − 2𝑥3
𝑥2 =
−5
−62 + 3(2.7) − 2(0)
𝑥2 𝑛𝑒𝑤 = = 10.78 38
4) Calculate x3, x1=2.7, x2=10.78;
−22 − 𝑥1 − 𝑥2
𝑥3 𝑛𝑒𝑤 =
6
𝑛𝑒𝑤
−22 − 2.7 − (10.78)
𝑥3 = = −5.9133
6
5) Calculate εa,1, εa,2 ,and εa,3
𝜀𝑎,1 = −
10.78−0
𝜀𝑎,2 = × 100 = 100%
10.78
−5.9133−0
𝜀𝑎,3 = × 100 = 100%
−5.9133
39
3) Calculate x2, x1=−0.0473, x3= - 5.9133 ;
𝑛𝑒𝑤
−62 + 3(−0.0473) − 2(− 5.9133)
𝑥2 = = 10.0631
−5
4) Calculate x3, x1= −0.0473, x2=10.0631;
𝑛𝑒𝑤
−22 + 0.04732.7 − (10.0631)
𝑥3 = = − 5.3360
6
5) Calculate εa,1, εa,2 ,and εa,3
−0.0473−2.7
𝜀𝑎,1 = × 100 = 5804.22%
−0.0473
10.0631−10.78
𝜀𝑎,2 = × 100 = 0.3802%
10.0631
−5.3360−(−5.9133)
𝜀𝑎,3 = × 100 = 17.1053%
−5.3360
40
X1=0.1277 X2=10.1702 X3= -5.3830
41
Solve for X, Y and Z using Gauss-Siedel
method, es= 5%
31.3𝑋 − 11.2𝑌 − 5.8𝑍 = 21.54 … … … (1)
− 12.7𝑋 + 45.4𝑌 + 8.06𝑍 = 17.43 … (2)
4.65𝑋 + 𝑌 + 10.04𝑍 = −12.47 … … … (3)
Answer: 4 iterations
X= 0.6911 Y= 0.8698 Z= -1.6487
42
Solve for vector x1, x2, and x3; as describe by linear equations
using Gauss-Siedel method. Stop iteration at |es|=5%:
3x1 + 2x2 – x3 = 5 -------- (i)
x1 - x2 + 3x3 = 10 ------- (ii)
-2x1 + x2 – 2x3 = 5 ------ (iii)
43
ANSWER for Exercise 3.4 ???
44
DIVERGE
45
Gauss-Seidel will converge if the following condition
holds: 𝑛
47
𝑛
48
0. Check the convergence and diagonal dominance
1. Choosing guesses values for x2 j-1 and x3 j-1. A simple way to
obtain initial guesses is to assume that they are all zero.
2. Calculate a new value for x1=b1/a11 by substitute these
initial guess into Eq. 12.1 (a)
3. Compute a new value for x2 by substitute new value of x1
along with the previous initial value of x3 in Eq. 12.1 (b)
4. Calculate a new estimate for x3 by substitute x1 and x2
obtained from step 2 and 3.
5. Check convergence using Eq. 12.2 for all i, where j and (j-1)
are the present (new) and previous iterations(old).
6. Then, return to the first equation and repeat the entire
procedure until all our solution converges closely enough to
the true values. 49
Solve for vector x1, x2, and x3; as describe by linear equations
using Gauss-Siedel method. Stop iteration at |es|=5 %:
3x1 + 2x2 – x3 = 5 -------- (i)
x1 - x2 + 3x3 = 10 ------- (ii)
-2x1 + x2 – 2x3 = 5 ------ (iii)
50
Solve for vector x, y, and z; as describe by linear equations using
Gauss-Siedel method. Stop iteration at |es|%=5:
8x + 3y +z = 12 -------- (i)
- 6x + 7z = 1 ------- (ii)
2x + 4y – z = 5 ------ (iii)
51
2. The equations given below can be solved to find the standard ratio
of macronutrients in the organic fertilizers that a company should
manufacture per day. The unknowns are the number of nitrogen (N),
phosphorus (P), and potassium (K).
3𝑁 + 7𝑃 + 13𝐾 = 76 … … … (1)
𝑁 + 5𝑃 + 3𝐾 = 28 … … … (2)
12𝑁 + 3𝑃 − 5𝐾 = 1 … … … (3)
Find the values of N,P,K and absolute relative error for each
nutrient using N=1, P=0, and K=1 as initial guess. Conduct iteration
until |εa,i|% < 5
Solve the linear algebraic problem using simple 3-lines MATLAB
command.
Write the MATLAB commands to solve the problem using
GaussSeidel user-define function (given in text book page 289)
54
Introduction
Naïve Gauss Elimination
Gauss-Siedel Method
Linear algebraic equations and MATLAB
57
General form of linear algebraic
[A] {x}={b}
{x}=[A]-1{b}
66
3) Using GaussSeidel
user-defined function
67
1) Solve for vector x1, x2, and x3; as describe by
linear equations:
3x1 + 2x2 – x3 = 5 -------- (i)
x1 - x2 + 3x3 = 10 ------- (ii)
-2x1 + x2 – 2x3 = 5 ------ (iii)
Solve using all methods
68
% Simple method % Gauss Naive function
A=[ 7 2 -3; 2 5 -3;1 -1 -6]; A=[ 7 2 -3; 2 5 -3;1 -1 -6];
b=[-12; -20;-26]; b=[-12; -20;-26];
Y=GaussNaive(A,b)
W=A\b
X=inv(A)*b
69
2) 2x1 − 0.1x2 − 0.2x3 = 7
0.1x1 + 5x2 − 0.3x3 = −20
0.3x1 − 0.2x2 + 9x3 = 70
70
3. A company is planning to invest a total of RM 1 million into 3 projects, A, B
and C. The estimated one-year return for each project under two different
market conditions, I and II is given on table. The manager’s goal is to
distribute funds between the projects in a way that would yield the total
return of 1.2 for both scenarios. The amount of money (in millions of ringgit)
to be invested in each project are denote as XA, XB, XC, respectively.
Project Scenario I Scenario II
A 1.4 0.9
B 0.8 2.0
C 1.2 1.0
Total 1.2 1.2
71
Following is the matrix operation:
{x} = {d} − [C]{x}
Where
𝑏1 𝑎12 𝑎13
ൗ𝑎11 0 Τ𝑎11 Τ𝑎11
𝑎23
{d} = 𝑏2
ൗ𝑎22 [C] = 𝑎21Τ𝑎22 0 Τ𝑎22
𝑏1 𝑎31 𝑎32
ൗ𝑎33 Τ𝑎32 Τ𝑎33 0