Nothing Special   »   [go: up one dir, main page]

Lecture - 2 Numerical Methods MSC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Numerical Methods MSc Lecture notes Prof. dr. Chelang A.

Arslan

Systems of Linear Algebraic Equations:


Gauss-Jordan elimination:
The steps of Jordan elimination as follow:
1. Form the augmented matrix corresponding to the system of linear
equations.
2. Transform the augmented matrix to the matrix in reduced row echelon
form via elementary row operations.
3. Solve the linear system corresponding to the matrix in reduced row
echelon form.

Solve the following system by using the Gauss-Jordan


elimination method.
X+Y+Z=5
2X + 3Y + 5Z = 8
4X + 5Z = 2
Sol:
1. Form the augmented matrix.

2. Transform from augmented to reduced form matrix.

18
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan

3. Solve the linear system corresponding to the matrix in reduced row


echelon form.
X = 3, Y = 4, Z = -2

Example 3: Solve the following system by using the Gauss-Jordan


elimination method.
X + 2Y – 3Z = 2
6X + 3Y – 9Z = 6
7X + 14Y – 21Z = 13

1. Form the augmented matrix

19
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan

2. Transform from augmented to reduced form matrix.

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

𝐵1 𝑎12 𝑎13 … … . . 𝑎1𝑛


𝐵2 𝑎22 𝑎23 … … . . 𝑎2𝑛
𝐵3 𝑎32 𝑎33 … … . . 𝑎3𝑛

…..
[ ….. ]
𝑋1 =
𝐷

20
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan

𝑎11 𝐵1 𝑎13 … … . . 𝑎1𝑛


𝑎21 𝐵2 𝑎23 … … . . 𝑎2𝑛
𝑎31 𝐵3 𝑎33 … … . . 𝑎3𝑛

…..
[ ….. ]
𝑋2 =
𝐷

EXAMPLE (1) Cramer’s Rule

Use Cramer’s rule to solve


0.3X1+0.52X2+X3= -0.01
0.5X1+X2+1.9X3= 0.67
0.1X1+0.3X2+0.5X3= -0.44

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

0.3 0.52 −0.01


|| 0.5 1 0.67 ||
0.1 0.3 −0.44
X3== =19.8
−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

Inversion of coefficient Matrix A

The equations which are given as AX=B

Can be expressed also as X= A-1 B

We should find A-1

Finding A-1 is given by


1
𝐴−1 = [𝐴𝑖𝑗]𝑇
det 𝑜𝑓 𝐴

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):

Solve the example :

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

Useful Notes for Matlab use :-

To solve linear algebraic system , there are several methods ;


The right division is used to solve matrix equation XA=B, where X, B are row vectors

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

For Example: if we want to use above in solving

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 𝑧

Using Crammer rule in Matlab


a- By Cramer’s Rule:
One of the most popular methods for solving systems of linear equations is
Cramer’s rule.
If we have n equations with n unknowns, AX=B. Cramer’s rule states that:
|𝐴1 | |𝐴2 | |𝐴3 | |𝐴𝑛 |
𝑥1 = , 𝑥2 = , 𝑥3 = , 𝑥𝑛 =
|𝐴| |𝐴| |𝐴| |𝐴|

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).

Example: Solve the following system of linear equations by Cramer’s rule:

𝑤 + 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

(Open a Script File)

% MATLAB program for solving system of linear equations % by


Cramer's rule

A=input('Enter the elements of matrix A: ');

B=input('Enter the elements of matrix B: ');

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(' ')

display('Values of w,x,y,and z are found:')

w=det(wv)/det(A)

x=det(xv)/det(A)

y=det(yv)/det(A)

z=det(zv)/det(A)

(Save and run)

27
Numerical Methods MSc Lecture notes Prof. dr. Chelang A. Arslan

(In the command window)

Enter the elements of matrix A: [1 2 0 -3;0 4 -5 2;2 8 -4 1;3 0 1 -5] ↵

Enter the elements of matrix B: [30;13;42;35] ↵

Values of w,x,y,and z are found:

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).

The form of x1 , x2 and x3 will be as following:

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:

(Open a Script File)

% MATLAB program for solving system of linear equations % by


Jacobi method

A=input('Enter the elements of matrix A: ');

B=input('Enter the elements of matrix B: ');

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('Values of x1, x2, and x3 are found')

display(x1)

display(x2)

display(x3)

(Save and run)

30

You might also like