Solving a Runtime Error: Investigating Beta(i,j)

  • Context: Fortran 
  • Thread starter Thread starter svishal03
  • Start date Start date
  • Tags Tags
    Error Runtime
Click For Summary
SUMMARY

The forum discussion addresses a runtime error encountered in a Fortran program implementing Crout's decomposition for solving linear algebraic equations. Specifically, the issue arises when calculating the beta(i,j) value for i=1 and j=2, which fails to execute, indicating a problem with the loop structure. The code provided demonstrates the decomposition process, but the user must ensure that the loops iterate through all dimensions of the matrix to avoid missing calculations. The solution involves adjusting the loop to cover the entire matrix dimensions.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with matrix operations and linear algebra concepts
  • Knowledge of Crout's decomposition method for matrix factorization
  • Experience with debugging runtime errors in programming
NEXT STEPS
  • Review Fortran loop structures and ensure proper iteration over matrix dimensions
  • Learn about debugging techniques specific to Fortran programming
  • Study Crout's decomposition in detail to understand its implementation
  • Explore matrix operations in Fortran, focusing on array manipulation and indexing
USEFUL FOR

Programmers working with Fortran, mathematicians implementing numerical methods, and anyone involved in solving linear algebraic equations using matrix decomposition techniques.

svishal03
Messages
124
Reaction score
1
I'm n facing a runtime error and do not know the reason.Also, I found where is the run time error in the code below but am at no clues, why it is occurring.

Actually when j=2 and i=1, the beta(i,j) is not getting calculated- that is, the print statement for beta(i,j) is not executed when j=2 and i=1. Thouhg the program is done till j=2 and also prints i=1 but does not calculate beta(2,1) as it is not printed. See the code in bold below

Anyone knows why?

Please help if possible!

MODULE DIRECT_METHODS_FOR_SOLUTION_OF_LINEAR_ALGEBRAIC_EQUATIONS
CONTAINS


FUNCTION CroutDecomp(AA,total_rows,total_columns,no_of_equations) !This routine decomposes the 'A' matrix of Ax=b into an upper and lower triangular matrix

!It is to be noted that this function fills in only the combined matrix of 'alpha's' and 'beta's' ; where alpha is the upper triangular matrix and beta is the lower triangular matrix.


!Crout's decomposition carries out 2 steps:
!1) First, for i=1,2,---,j use , beta(i,j)= a(i,j)-(summation over k=1 to i-1)[alpha(i,k)*beta(k,j)
!2)Second, for i=j+1,--N use, alpha(i,k)= 1/beta(j,j)*((a(i,j)-summation over k=1 to j-1 [ alpha(i,k)*beta(k,j)]


INTEGER::total_rows,total_columns ,no_of_equations
REAL aa(total_rows,total_columns)
INTEGER:: i,j,k
REAL ::sum1
REAL alpha(total_rows,total_columns),beta(total_rows,total_columns),decomposed(total_rows,total_columns)



LOOP_COLUMN:DO j=1,total_columns

print*,'inside j' ,j
LOOP_ROWS:DO i= 1,j
print*,'inside i', i
alpha(i,i)=1
sum1=0

INotEqual1:IF(i.NE.1)THEN
print*,'inside prod alpha beta',i,j
LOOP_PROD_ALPHA_BETA:DO k=1,i-1
sum1=sum1+(alpha(i,k)*beta(k,j))
END DO LOOP_PROD_ALPHA_BETA
END IF INotEqual1

beta(i,j)=AA(i,j)-sum1
print*,'printing betaqqqqqqqqqqq',beta(i,j)

decomposed(i,j)=beta(i,j)
print*,'printing decomposed',decomposed(i,j)
END DO LOOP_ROWS



jLessThanNoOfEqns:IF(j.LT.no_of_equations)THEN
LOOP_ROWS_1: DO i=j+1,no_of_equations
sum1=0

jNotEqual1:IF(j.NE.1)THEN
LOOP_PROD_ALPHA_BETA2:DO k=1,j-1
sum1=sum1+(alpha(i,k)*beta(k,j))
END DO LOOP_PROD_ALPHA_BETA2
END IF jNotEqual1

alpha(i,j)=(1/beta(j,j))*(AA(i,j)-sum1)
decomposed(i,j)=alpha(i,j)
END DO LOOP_ROWS_1

END IF jLessThanNoOfEqns

END DO LOOP_COLUMN
print *,'in CroutDecomp'



!ROW11_LOOP:DO i=1,total_rows
!COLUMN11_LOOP:DO j=1,total_columns
!PRINT*,decomposed(i,j)
!END DO COLUMN11_LOOP
!END DO ROW11_LOOP


CroutDecomp = 20

END FUNCTION CroutDecomp




END MODULE DIRECT_METHODS_FOR_SOLUTION_OF_LINEAR_ALGEBRAIC_EQUATIONS


PROGRAM LINEAR_EQUATIONS_SOLVER
USE DIRECT_METHODS_FOR_SOLUTION_OF_LINEAR_ALGEBRAIC_EQUATIONS
!IMPLICIT NONE
REAL,DIMENSION(100,100)::AA,x
REAL,DIMENSION(100)::b
INTEGER::total_rows,total_columns,no_of_equations,i,j
PRINT*, 'ENTER THE TOTAL NUMBER OF ROWS AND COLUMNS'
READ*, total_rows,total_columns
PRINT*, 'ENTER THE TOTAL NUMBER OF EQUATIONS'
READ*, no_of_equations
PRINT*, 'ENTER THE A MATRIX OF Ax = b'
ROW_LOOP:DO i=1,total_rows
COLUMN_LOOP:DO j=1,total_columns
READ*,AA(i,j)
END DO COLUMN_LOOP
END DO ROW_LOOP
PRINT*, 'ENTER THE b MATRIX OF Ax = b'
ROW_LOOP:DO i=1,total_rows
READ*,b(i)
END DO ROW_LOOP

x= CroutDecomp(AA,total_rows,total_columns,no_of_equations)

END PROGRAM LINEAR_EQUATIONS_SOLVER
 
Technology news on Phys.org
This is happening because you are only filling in the lower diagonal of your matrix.

Code:
LOOP_COLUMN:DO j=1,total_columns 

print*,'inside j' ,j 
LOOP_ROWS:DO i= 1,j 
print*,'inside i', i 
alpha(i,i)=1 
sum1=0 

INotEqual1:IF(i.NE.1)THEN 
print*,'inside prod alpha beta',i,j 
LOOP_PROD_ALPHA_BETA:DO k=1,i-1 
sum1=sum1+(alpha(i,k)*beta(k,j)) 
END DO LOOP_PROD_ALPHA_BETA 
END IF INotEqual1 

beta(i,j)=AA(i,j)-sum1 
print*,'printing betaqqqqqqqqqqq',beta(i,j) 
decomposed(i,j)=beta(i,j) 
print*,'printing decomposed',decomposed(i,j) 
END DO LOOP_ROWS

This computes the following:

1,1
2,1;2,2
3,1;3,2;3,3
...

You need to iterate all the way through your dimensions, for example if your matrix is 10x10, you need to run you loop as follows:

Code:
do j = 1, 10
   do i = 1, 10
      a(i,j) = ...
   end do
end do

Also, I hope what you provided was pseudo-code because it's very ugly.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K