Lecture - 2 Numerical Methods MSC
Lecture - 2 Numerical Methods MSC
Lecture - 2 Numerical Methods MSC
Arslan
18
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
19
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
We obtain a row whose elements are all zero’s except the last one on the
right. Therefore, we conclude that the system of equations is inconsistent,
i.e., it has no solutions.
Cramer’s Rule.
This rule states that each unknown in a system of linear algebraic equations
may be expressed as a fraction of two determinants with denominator D and
with
the numerator obtained from D by replacing the column of
coefficients of the unknown
in question by the constants b1, b2, . . . , bn. For example, x1 would be
computed as
20
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
Sol:
0.3 0.52 1
D=| 0.5 1 1.9 |=-0.0022
0.1 0.3 0.5
−0.01 0.52 1
|0.67 1 1.9 |
−0.44 0.3 0.5
X1= =-14.9
−0.0022
0.3 −0.01 1
|| 0.5 0.67 1.9 ||
0.1 −0.44 0.5
X2= =-29.5
−0.0022
Example(2).
Solve:
3y+4Z=14.8
4X+2y-Z=-6.3
X-y+0.55Z=13.5
21
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
Solution:
4X+2y-Z=-6.3
X-y+0.55Z=13.5
3y+4Z=14.8
4 2 −1
|
D=| 1 −1 0.55 ||= -33.6
0 3 4
−6.3 2 −1
|13.5 −1 0.55|
14.8 3 4
X= = 3.3161
−33.6000
4 −6.3 −1
|1 13.5 0.55|
0 14.8 4
y= = -5.4952
−33.6000
4 2 −6.3
|1 −1 13.5 |
0 3 14.8
Z== = 8.0268
−33.6000
22
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
𝐴𝑖𝑗 𝑖𝑠 𝑒𝑞𝑢𝑎𝑙 𝑡𝑜 (−1) i+j times the determinant A after deleting i row
and j col.
Example(1):
8 X1 +2 X2+3X3=30
X1-9X2+2X3=1
2X1+3X2+6X3=31
Solution:
8 2 3 𝑋1 30
[ 1 − 9 2 ] [𝑋2] = [ 1 ]
2 3 6 𝑋3 31
1st Finding A -1
Find determinant of A
−9 2 1 2 1 −9
8| |− 2| | + 3| |=-421
3 6 2 6 2 3
To Find Aij coefficients
𝑎11 𝑎12 𝑎13 𝑎14
𝑎21 𝑎22 𝑎23 𝑎24
Aij=[ ]
𝑎31 𝑎32 𝑎33 𝑎34
𝑎41 𝑎42 𝑎43 𝑎44
−9 2
a11=(-1)1+1 | | = −60
3 6
1 2
a12=(-1)1+2 | | = −2
2 6
1 −9
a13=(-1)1+3 | | = 21
2 3
2 3
a21=(-1)2+1 | | = −3
3 6
23
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
8 3
a22=(-1)2+2 | | = 42
2 6
8 2
a23=(-1)2+3 | | = −20
2 3
2 3
a31=(-1)3+1 | | = 31
−9 2
8 3
a32=(-1)3+2 | | = −13
1 2
8 2
a33=(-1)3+3 | | = −74
1 −9
1
𝐴−1 = [𝐴𝑖𝑗]𝑇
det 𝑜𝑓 𝐴
1 −60 −2 21 𝑇
𝐴−1 = [ −3 42 − 20 ]
−421
31 − 13 − 74
𝑋1 −60 −3 31 30
1
[𝑋2]=−421 [ −2 42 − 13 ] [ 1 ]
𝑋3 21 − 20 − 74 31
X1=2, X2=1,X3=4
Check
24
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
XA = B
X=B/A
Or
X*A = B
-1 -1
X*A*A = B * A
-1
X*I = B * A
-1
X=B*A
Left division is used to solve the matrix equation CX=D, where X, D are column
vectors.
CX = D
X=C\D
Or
C*X = D
-1 -1
C *C*X = C * D
-1
I*X = C * D
-1
X=C *D
25
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
X+Y+Z=5
2X + 3Y + 5Z = 8
4X + 5Z = 2
Sol : in command window : enter the A , B matrix
1 1 1 5 𝑥
A=[2 3 5] , B=[8], X=[ 𝑦 ]
4 0 5 2 𝑧
Where Ai is a matrix obtained from A by replacing the ith column with B and n is
the number of unknowns and equations. Determinate of A must not equal to zero
(|A| ≠ 0).
𝑤 + 2𝑥 − 3𝑧 = 30
4𝑥 − 5𝑦 + 2𝑧 = 13
2𝑤 + 8𝑥 − 4𝑦 + 𝑧 = 42
3𝑤 + 𝑦 − 5𝑧 = 35
Solution:
𝟏 𝟐 𝟎 −𝟑 𝟑𝟎
𝟎 𝟒 −𝟓 𝟐 𝟏𝟑
𝑨=[ ] 𝑩=[ ]
𝟐 𝟖 −𝟒 𝟏 𝟒𝟐
𝟑 𝟎 𝟏 −𝟓 𝟑𝟓
26
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
wv=[B,A(:,2),A(:,3),A(:,4)];
xv=[A(:,1),B,A(:,3),A(:,4)];
yv=[A(:,1),A(:,2),B,A(:,4)];
zv=[A(:,1),A(:,2),A(:,3),B];
display(' ')
w=det(wv)/det(A)
x=det(xv)/det(A)
y=det(yv)/det(A)
z=det(zv)/det(A)
27
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
w=
2.0000
x=
5.0000
y=
-1
z=
-6
28
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
a- By Jacobi Method:
The Jacobi Method is a simple iterative method for solving a square system of linear
equations (AX=B).
Example:
Use the Jacobi method to approximate the solution of the following system of linear
equations.
6𝑥1 + 4𝑥2 + 3𝑥3 = 2
4𝑥1 + 3𝑥2 + 2𝑥3 = 0.5
3𝑥1 + 4𝑥2 + 2𝑥3 = −2.5
29
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan
Solution:
x1=0;x2=0;x3=0;
for i=1:100
x1=(1/A(1,1))*(B(1)-(A(1,2)*x2)-(A(1,3)*x3));
x2=(1/A(2,2))*(B(2)-(A(2,1)*x1)-(A(2,3)*x3));
x3=(1/A(3,3))*(B(3)-(A(3,1)*x1)-(A(3,2)*x2));
end
display(' ')
display(x1)
display(x2)
display(x3)
30