gauss jordan

18
Jorge Eduardo Celis vargas Code: 2073412 GAUSS-JORDAN

Upload: jorgeduardooo

Post on 23-Jun-2015

3.462 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Gauss jordan

Jorge Eduardo Celis vargas

Code: 2073412

GAUSS-JORDAN

Page 2: 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

Page 3: Gauss jordan

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

.......

........

........

Page 4: Gauss jordan

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

.......

........

........

Page 5: Gauss jordan

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

Page 6: Gauss jordan

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.

Page 7: Gauss jordan

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

Page 8: Gauss jordan

Example

322

1123

82

zyx

zyx

zyx

Page 9: Gauss jordan

3212

11213

8112 )

2

1(*1F

3212

11213

42/12/11

312

3 21

FF

FF

5120

12/12/10

42/12/11

Example

Page 10: Gauss jordan

2*2F

5120

2110

42/12/11

322

)2/1( 12

FF

FF

1100

2110

3101

Example

Page 11: Gauss jordan

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

Page 12: Gauss jordan

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

Page 13: Gauss jordan

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

Page 14: Gauss jordan

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

Page 15: Gauss jordan

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

Page 16: Gauss jordan

•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];

Page 17: Gauss jordan

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]);}}}

Page 18: Gauss jordan

bibliography

• http://www.acatlan.unam.mx/acatlecas/mn/sistemas.htm#3.1.1._Método_de_Gauss_

• Internet wikipedia.