What is the issue with calculating eigenvalues using rgg.f?

  • Thread starter Thread starter llello
  • Start date Start date
  • Tags Tags
    Eigenvalues
Click For Summary
SUMMARY

The discussion revolves around a segmentation fault encountered while using the Netlib routine rgg.f to calculate eigenvalues of a diagonal matrix in Fortran. The user attempted to input a simple diagonal matrix with values 1 and 2 but faced issues due to incorrectly passing a zero value into the subroutine. The problem was resolved by ensuring that the variables passed to the routine were properly defined and not set to zero.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with eigenvalue and eigenvector concepts
  • Knowledge of matrix operations in numerical computing
  • Experience with debugging segmentation faults in Fortran
NEXT STEPS
  • Review the Netlib documentation for rgg.f to understand its parameters and usage
  • Learn about memory management and allocation in Fortran to prevent segmentation faults
  • Explore advanced eigenvalue algorithms such as QR algorithm and Jacobi method
  • Investigate debugging techniques for Fortran programs, focusing on segmentation fault resolution
USEFUL FOR

Researchers, physicists, and software developers working with numerical methods in Fortran, particularly those focused on eigenvalue problems and matrix computations.

llello
Messages
30
Reaction score
0
Hey folks, I'm having an issue using a routine from the netlib that is supposed to calculate eigenvalues and eigenvectors. The canned routine can be found here:

http://www.netlib.org/seispack/rgg.f

I want to find the eigenvalues of a matrix (a more complex hamiltonian), so for my simple attempt to get this code to work, I input the diagonal matrix with 1 and 2 on the diagonals. So if everything worked fine, this canned routine should just spit out 1 and 2. So my issue comes in when I run this, it spits out a segmentation fault error and I can't sort out why it isn't working. Anyone have any insight into where I'm going wrong? My trial code is given below.
program trial
implicit none

double precision, allocatable, dimension(:,:) :: hamiltonian
double precision, allocatable, dimension(:,:) :: identity
double precision, allocatable, dimension(:) :: reigenval
double precision, allocatable, dimension(:) :: ieigenval
double precision, allocatable, dimension(:) :: denom
double precision, allocatable, dimension(:,:) :: eigenvec

double precision trueValue(100)
double precision answer, pos, xstep
integer i, j, m, n, k, gridsize

gridsize = 2

k = gridsize

allocate(hamiltonian(k,k),identity(k,k),reigenval(k),ieigenval(k),denom(k),eigenvec(k,k))

! makes the matrices
do i=1, gridsize
do j=1, gridsize
hamiltonian(i,j) = delta(i,j)*i
identity(i,j) = delta(i,j)
enddo
enddo

! calls the canned routine
call rgg(k,k,hamiltonian,identity,reigenval,ieigenval,denom,0,eigenvec,0)open (unit=15, file='eigenvalueSHO.txt', access='append', status='new')

do i=1, gridsize
write(15,*) i, reigenval(i)
enddoclose(unit=15)

deallocate(hamiltonian,identity,reigenval,ieigenval,denom,eigenvec)contains

! function to calculate kronecker delta

double precision function delta(m,n) result(answer)

integer, intent(in) :: m
integer, intent(in) :: n

if (m .eq. n) then
answer = 1.0
else
answer = 0.0
endif

end function delta

end program
 
Computer science news on Phys.org
Ok, solved the problem. It was really stupid too. I was throwing "0" into the subroutine but i had to define variables that are zero to put into the code. Rookie mistake.
 
I am having a hell of a time finding a good all-in-one inkjet printer. I must have gone through 5 Canon, 2 HP, one Brother, one Epson and two 4 X 6 photo printers in the last 7 yrs. all have all sort of problems. I don't even know where to start anymore. my price range is $180-$400, not exactly the cheapest ones. Mainly it's for my wife which is not exactly good in tech. most of the problem is the printers kept changing the way it operate. Must be from auto update. I cannot turn off the...

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
3
Views
3K
  • · Replies 10 ·
Replies
10
Views
26K