Lecture_notes_63

Lecture_notes_63 - enddo enddo else...

Info icon This 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)
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern