2. GAUSS-JORDAN
• Gaussian elimination is an algorithm of linear algebra to determine
the solutions of a system of linear equations, matrices and inverse
finding.
The computational complexity of Gaussian elimination is
approximately n3. That is, the number of operations required is n3 if
the size of the matrix is n × n
m
n
mn
m
m
n
n
n
n
b
x
a
x
a
x
a
b
x
a
x
a
x
a
b
x
a
x
a
x
a
.....
.....
.....
2
2
1
1
2
2
2
22
1
21
1
1
2
13
1
12
m
mn
m
m
n
n
b
b
b
a
a
a
a
a
a
a
a
a
2
1
2
1
2
22
21
1
12
11
.......
........
........
........
_ n
2
1 x
x
x
System of linear equations
Resulting augmented matrix
3. Mathematical Algorithm
1. Go to the far left column is not zero
2. If the first line has a zero in this column, swap it with
another that does not have If
0
,
,
0 12
11 a
a
m
mn
m
m
n
n
b
b
b
a
a
a
a
a
a
a
a
a
2
1
1
2
2
21
22
1
11
12
.......
........
........
4. GAUSS-JORDAN
3. Then, get below zero this item forward, adding
appropriate multiples of row than the row below it.
This is done through the following:
• Multiply an equation by a nonzero scalar.
• Exchange of position two equations.
• Add to a multiple of another equation.
m
mn
m
m
n
n
m
mn
m
m
n
n
b
b
a
b
a
a
a
a
a
a
a
a
a
a
a
F
b
b
b
a
a
a
a
a
a
a
a
a
2
11
1
2
1
2
22
21
11
1
11
12
11
2
1
2
1
2
22
21
1
12
11
.......
........
........
1
)
1
(
*
1
.......
........
........
5. GAUSS-JORDAN
4. Cover the top row and repeat the above process with the remaining
submatrix. Repeat with the rest of the lines (at this point the array is in
the form of step)
m
mn
m
m
n
n
m
mn
m
m
n
n
b
a
b
b
a
b
a
a
a
a
a
a
a
a
a
a
F
F
b
b
a
b
a
a
a
a
a
a
a
a
a
a
11
1
2
11
1
2
1
2
22
11
1
11
12
21
2
11
1
2
1
2
22
21
11
1
11
12
.......
........
0
........
1
*
1
2
.......
........
........
1
1
.......
0
........
0
...
1
....
0
....
0
....
....
1
...
0
...
...
..
1
3
2
13
1
13
12
n
n
n
a
a
a
a
a
a
6. GAUSS-JORDAN
5. Starting with the last line is not zero, move up: for each row
get a 1 up front and introduce zero multiples of this sum for
the rows corresponding
1
.......
0
........
0
0
...
1
....
0
....
0
....
....
1
...
0
...
...
...
1
)
(
*
)
1
(
1
.......
0
........
0
...
1
....
0
....
0
....
....
1
...
0
...
...
..
1
2
23
1
13
12
3
3
2
13
1
13
12
n
n
n
n
n
n
a
a
a
a
a
a
Fn
n
F
a
a
a
a
a
a
We repeat this procedure until you reach a small phased array.
7. GAUSS-JORDAN
6. Then we obtain the solutions of systems of equations
bn
b
b
b
xn
x
x
x
3
2
1
.......
0
........
0
0
...
3
....
0
....
0
0
....
0
....
2
...
0
0
...
0
....
0
...
1
Then the solution is:
bn
xn
b
x
b
x
2
2
1
1
15. Code
• Fortran:
program gauss_Jordan
integer::i,j,n,k
real::a
real,allocatable::m(:,:)
real,allocatable::f(:)
read(*,*)n
allocate(m(n,n),f(n))
do i=1,n,1
read(*,*)f(i)
end do
do i=1,n,1
read(*,*)m(i,1:n)
end do
do i=1,n,1
do j=1,n,1
if(i==j)then
a=m(j,i)
do k=i,n,1
m(j,k)=(m(j,k))/(a)
end do
f(i)=(f(i))/(a)
else
a=m(j,i)
m(j,k)=m(j,k)-a*m(i,k)
end do
f(j)=f(j)-a*f(i)
end if
end do
end do
do i=n,1,-1
do j=i-1,1,-1
a=m(j,i)
do k=j,n,1
m(j,k)=m(j,k)-a*m(i,k)
end do
f(j)=f(j)-a*f(i)
end do
end do
do i=1,n,1
write(*,*)’x’,(i),’=‘,f(i)
end do
write(*,*)'bn'
write(*,*)m
close(25)
end program gauss