ass3_solutions

ass3_solutions - solutions.txt Mon Dec 12 17:49:10 2011 1 1:

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: solutions.txt Mon Dec 12 17:49:10 2011 1 1: 2:******************************************* 3:./code/linear_mod.f90 4: 5:MODULE linear_mod 6: 7: IMPLICIT NONE 8: 9: CONTAINS 10: 11: ! *********************************************************************** 12: 13: FUNCTION gauss_elim(mat1,vv) 14: !**** Function to reduce a square matrix to upper triangular form 15: !**** 16: 17: !***** Dummy Variables ***** 18: REAL,DIMENSION(:,:), INTENT(INOUT) :: mat1 !** Matrix to be reduced 19: REAL,DIMENSION(:), INTENT(INOUT) :: vv !** RHS vector 20: 21: LOGICAL :: gauss_elim !*** Set return type for function gauss_elim 22: 23: REAL :: lambda !*** multiplier variable 24: INTEGER :: n,i,j 25: 26: gauss_elim=. TRUE . !*** Set default to success 27: n=SIZE(mat1,1) 28: 29: DO j=1,n-1 !** Loop over each pivot column 30: IF (mat1(j,j)==0) gauss_elim=find_pivot(mat1,vv,j) !** Check zero pivot 31: IF (gauss_elim .EQV. . FALSE .) EXIT !** No solution 32: DO i=j+1,n !** Loop to zero all the elements under pivot 33: IF (mat1(j,i) .NE. 0) THEN 34: lambda=mat1(i,j)/mat1(j,j) 35: mat1(i,j:n)=mat1(i,j:n)-lambda*mat1(j,j:n) 36: vv(i)=vv(i)-lambda*vv(j) !*** Keep RHS vector consistent 37: ENDIF 38: END DO 39: END DO 40: IF (mat1(n,n)==0) gauss_elim=. FALSE . !** Check last element 41: END FUNCTION gauss_elim 42: 43: ! *********************************************************************** 44: 45: FUNCTION find_pivot(mat1,vv,index) 46: !*** When pivot is zero find valid row for interchange !...
View Full Document

Page1 / 2

ass3_solutions - solutions.txt Mon Dec 12 17:49:10 2011 1 1:

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