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

In summary: I would write it like this:do col = 1, n do row = 1, col alpha(row, row) = 1 sum = 0 if (row /= 1) then do k = 1, row-1 sum = sum + ( alpha(row, k) * beta(k, col) ) end do end if beta(row, col) = aa(row, col) - sum decomposed(row, col) = beta(row, col) end doend do
  • #1
svishal03
129
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
  • #2
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.
 

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

1. What is a runtime error?

A runtime error is an error that occurs during the execution of a program. It is usually caused by a mistake in the code or an unexpected condition that the program encounters while running.

2. How do I investigate a runtime error?

To investigate a runtime error, you can start by looking at the line of code where the error occurred. Check for any typos, missing or incorrect syntax, or variables that are not properly defined. You can also use debugging tools or try to replicate the error to understand its cause.

3. What is Beta(i,j) and why is it important to investigate it?

Beta(i,j) is a function or variable in the code that is causing the runtime error. It is important to investigate it because it is the source of the error and understanding why it is causing the error can help you fix it and prevent it from happening in the future.

4. Can a runtime error be fixed?

Yes, a runtime error can be fixed. Once you have identified the cause of the error, you can make the necessary changes to the code to fix it. It may require debugging, rewriting the code, or using a different approach, but it is possible to fix a runtime error.

5. How can I prevent runtime errors from happening?

To prevent runtime errors, it is important to write clean and well-structured code. This includes proper syntax, variable declarations, and error handling. You can also use debugging tools while writing and testing your code to catch any potential errors early on.

Similar threads

  • Programming and Computer Science
Replies
4
Views
963
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
22
Views
4K
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
12
Views
3K
Back
Top