Lecture_notes_63

Lecture_notes_63 - enddo enddo else File:...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
File: /home/pierre/Documents/ProgCl…ran Code/Linear_solver_mod.f90 Page 1 of 2 module Linear_solver_mod use type_module implicit none type linear_system real (DP), allocatable :: A(:,:) real (DP), allocatable :: b(:), x(:) integer :: N end type linear_system contains subroutine Construct(this, A_in, b_in, N_in, M) implicit none type (linear_system) :: this real (DP), intent ( in ) :: A_in(:,:) real (DP), intent ( in ) :: b_in(:) integer , intent ( in ) :: N_in, M allocate (this%A(N_in, N_in)) allocate (this%b(N_in)) allocate (this%x(N_in)) this%A(:,:) = A_in(:,:) this%b(:) = b_in(:) this%N = N_in end subroutine Construct subroutine Destruct(this) implicit none type (linear_system) :: this deallocate (this%A) deallocate (this%b) deallocate (this%x) end subroutine Destruct subroutine GaussSeidel(this, Nmax) implicit none type (linear_system) :: this integer , optional :: Nmax integer :: i,j,k real (DP) :: sum_i = 0 if ( present (Nmax)) then do i= 1 ,Nmax do k= 1 ,this%N sum_i = 0 do j = 1 , this%N if (j==k) then cycle endif sum_i = sum_i + this%A(k,j)*this%x(j) enddo this%x(k) = (this%b(k) - sum_i)/this%A(k,k)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: enddo enddo else File: /home/pierre/Documents/ProgCl…ran Code/Linear_solver_mod.f90 Page 2 of 2 do i= 1 , 1000 do k= 1 ,this%N sum_i = do j = 1 , this%N if (j==k) then cycle endif sum_i = sum_i + this%A(k,j)*this%x(j) enddo this%x(k) = (this%b(k) - sum_i)/this%A(k,k) enddo enddo endif end subroutine GaussSeidel subroutine output_File(this, FileName) implicit none type (linear_system) :: this character ( len =*), intent ( in ), optional :: FileName real (DP), dimension ( 1 :this%N) :: vector integer :: file_unit,i vector = matmul (this%A,this%x) if ( present (FileName)) then open ( unit = file_unit, FILE = FileName, STATUS = 'REPLACE' , ACTION = 'WRITE' ) else file_unit = 6 endif do i= 1 ,this%N write (file_unit,*) vector(i), this%b(i), vector(i) - this%b(i) enddo if ( present (FileName)) then close (file_unit) endif end subroutine output_File end module Linear_solver_mod...
View Full Document

This note was uploaded on 01/15/2012 for the course MAT 5939 taught by Professor Garreau during the Fall '11 term at FSU.

Page1 / 2

Lecture_notes_63 - enddo enddo else File:...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online