Download - Gauss jordan
Jorge Eduardo Celis vargas
Code: 2073412
GAUSS-JORDAN
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
mnmnmm
nn
nn
bxaxaxa
bxaxaxa
bxaxaxa
.....
.....
.....
2211
22222121
11213112
mmnmm
n
n
b
b
b
aaa
aaa
aaa
2
1
21
22221
11211
.......
........
........
........_ n21 xxxSystem of linear equations
Resulting augmented matrix
Mathematical Algorithm1. 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 1211 aa
mmnmm
n
n
b
b
b
aaa
aaa
aaa
2
1
12
22122
11112
.......
........
........
GAUSS-JORDAN3. 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.
mmnmm
n
n
mmnmm
n
n
b
b
a
b
aaa
aaa
a
a
a
a
aF
b
b
b
aaa
aaa
aaa
2
11
1
21
22221
11
1
11
12
11
2
1
21
22221
11211
.......
........
........1
)1(*1
.......
........
........
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)
mmnmm
n
n
mmnmm
n
n
b
a
bb
a
b
aaa
aa
a
a
a
a
aFF
b
b
a
b
aaa
aaa
a
a
a
a
11
12
11
1
21
222
11
1
11
12
212
11
1
21
22221
11
1
11
12
.......
........0
........1
*12
.......
........
........1
1.......0........0
...1....0....0
........1...0
........1
3
213
11312
n
n
n
a
aa
aaa
GAUSS-JORDAN5. 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
223
11312
33
213
11312
n
n
nn
n
n
aa
aaa
aFnnFa
aa
aaa
We repeat this procedure until you reach a small phased array.
GAUSS-JORDAN6. 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:
bnxn
bx
bx
22
11
Example
322
1123
82
zyx
zyx
zyx
3212
11213
8112 )
2
1(*1F
3212
11213
42/12/11
312
3 21
FF
FF
5120
12/12/10
42/12/11
Example
2*2F
5120
2110
42/12/11
322
)2/1( 12
FF
FF
1100
2110
3101
Example
1*3
13
23
F
FF
FF
1100
3010
2001
ZYX
Then the solution of this system of equations is:
1;3;2 zyx
Example
Flow Chart
INICIO
1i=1,n,1
j=1,n,1
M(j,i)
F(i)
1f
2f
nf
11a 12a na1
21a 22a na2
1na 2na
nna
i
j
nxnM jf
M(j,k)=M(j,k)/M(j,i)
F(j)=F(j)-M(j,i)*F(i)
k=i,n,1
M(j,k)=M(j,k)-M(j,i)*M(i,k)
F(i)=F(i)/M(j,i)
1
i=j
k=i,n,1
si no
j=1,n,1
i=1,n,1 2
1 12a na1
0 1 na2
0 0 1
i
j
k
F(j)=F(j)-M(j,i)*F(i)
2
j=i-1,1,-1
i=n,1,-1
k=i,n,1
M(j,k)=M(j,k)-M(j,i)*M(i,k)
i=1,n,1
‘X’(i)=F(i)
FIN
1 0 0
0 1 0
0 0 1
1x 2x nx
1f
2f
nf
k
i
j
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)
do k=i,n,1
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
•JAVA
package javaapplication1;import javax.swing.JOptionPane;import java.util.Scanner;public class Gauss_Jordan {public static void main(String[] args) {int i,j,k,n;double a;double m[][],f[];Scanner reader=new Scanner(System.in);System.out.println("escriba n");n=reader.nextInt();m=new double [n][n];f=new double [n];for(i=0;i<n;i++){ f[i]=Double.parseDouble(JOptionPane.showInputDialog("f"+i));for(j=0;j<n;j++){m[i][j]=Double.parseDouble(JOptionPane.showInputDialog("M("+i+j+")"));}}for(i=0;i<n;i++){ for(j=0;j<n;j++){ a=m[j][i];
if(i==j){ for(k=i;k<=n;k++){ m[j][k]=(m[j][k]/a);} f[i]=(f[i]/a);} else { for(k=i;k<=n;k++){ m[j][k]=m[j][k]-a*m[i][k];} f[j]=f[j]-a*f[i];}}}for(i=n;i>=0;i--){ for(j=i-1;j>=0;j--){ a=m[j][i]; for(k=j;k<=n;k++){ m[j][k]=m[j][k]-a*m[i][k];} f[j]=f[j]-a*f[i];}}for(i=0;i<n;i++){ System.out.println("x"+i+"="+f[i]);}}}
bibliography
• http://www.acatlan.unam.mx/acatlecas/mn/sistemas.htm#3.1.1._Método_de_Gauss_
• Internet wikipedia.