Programa jacobi y gauss seidel

Páginas: 3 (578 palabras) Publicado: 22 de febrero de 2012
program jacobi
implicit none
character(500)nom_archivo
integer n,maximo,i,j,iter
real,dimension(:,:),allocatable::A !matriz dinamica 
real,dimension(:),allocatable::b,x_act,x_ini
realtol,suma,norma,suma2

!seccion de ejecucion
print*,"ingrese el archivo de datos:"
read*,nom_archivo
open(unit=20,file=nom_archivo)
read(20,*)n
allocate(A(n,n),b(n),x_act(n),x_ini(n))
do i=1,n,1 read(20,*)A(i,1:n:1),b(i)
 end do
 close(20)
 print*,"ingrese el maximo de iteraciones y la tolerancia:"
 read*,maximo,tol
 print*,"ingrese el vector de estimaciones iniciales:"
 read*,x_ini
 doiter=1,maximo,1
 do i=1,n,1
 suma=0
 do j=1,i-1,1
 suma=suma+A(i,j)*x_ini(j)
 end do
 suma2=0
 do j=i+1,n,1
 suma2=suma2+A(i,j)*x_act(j)
 end do
 x_act(i)=(b(i)-suma-suma2)/A(i,i) print*,"iteracion=",iter,"x=",x_act
 norma=sqrt(sum((x_act-x_ini)**2))
 print*,"norma=",norma
 print*,"--------------------------------------"
 if(norma<=tol)then
 print*,"el metodo converge"
 print*,"elvector solucion es:",x_act
 exit
 else
 x_ini=x_act
 end if
 end do
 end do
 pause
 end program

! Last change: L
SUBROUTINE LLENADO(N,D,MAT)
IMPLICIT NONEINTEGER,INTENT(IN)::N,D
REAL,DIMENSION(N,D),INTENT(OUT)::MAT
INTEGER ::I,J,ERROR1
DO I=1,N
DO J=1,N
WRITE(*,*)"DAME COMPONENTE A(",J,") DE LA ECUACION",I
READ(*,*)MAT(I,J)
IF (J==N) THEN
WRITE(*,*)"DAME EL VALOR DEB EN LA ECUACION",I
READ(*,*)MAT(I,D)
END IF
END DO
END DO
END SUBROUTINE LLENADO

PROGRAM PROYECTO_2
IMPLICIT NONE
REAL::ER,SUMA
INTEGER::K=0,N,ERROR1,D,J,I,ITERA,Y,MREAL,ALLOCATABLE,DIMENSION(:)::X1,ERRAB,C,V
REAL,ALLOCATABLE,DIMENSION(:,:)::MAT
WRITE(*,*)"EL SIGUIENTE PUEDE ENCONTRAR VALORES EN SISTEMAS DE N ECUCACIONES CON N INCOGNITAS "
WRITE(*,*)"INTRODUCE EN NUMERO DEECUACIONES"
READ(*,*)N
D=N+1
ALLOCATE(MAT(1:N,1:D),STAT=ERROR1)
IF (ERROR1/=0) stop"NO HAY SUFICIENTE ESPACIO EN LA MEMORIA"
CALL LLENADO(N,D,MAT)
WRITE(*,*)"INTRODUCE VALORES INICIALES DE LAS...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Método Gauss-Seidel & Jacobi
  • Ejemplos SEAL Jacobi Gauss Seidel
  • Metodo de jacobi y gauss-seidel
  • Gauss seidel-jacobi-minimogrado-eliminacion
  • Gauss seidel
  • Gauss Seidel
  • Metodo de Gauss y Gauss Seidel
  • Gauss Seidel

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS