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

  • Thread starter Thread starter llello
  • Start date Start date
  • Tags Tags
    Eigenvalues
AI Thread Summary
The discussion revolves around an issue encountered while using a routine from the netlib to calculate eigenvalues and eigenvectors of a matrix. The user attempted to apply the routine to a simple diagonal matrix but faced a segmentation fault error during execution. The code provided includes the definition of matrices and a call to the routine, but the problem was traced back to incorrectly passing a zero value into the subroutine. The issue was resolved by ensuring that variables defined as zero were correctly handled in the code, highlighting the importance of proper variable initialization in programming.
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.
 
Well, the date has now passed, and Windows 10 is no longer supported. Hopefully, the readers of this forum have done one of the many ways this issue can be handled. If not, do a YouTube search and a smorgasbord of solutions will be returned. What I want to mention is that I chose to use a debloated Windows from a debloater. There are many available options, e.g., Chris Titus Utilities (I used a product called Velotic, which also features AI to prevent your computer from overheating etc...
I've been having problems for the past few weeks with the display on my Dell computer. I bought the computer new back in 2019 or so, which makes it about 6 years old. My monitor is a 27" HP monitor that I bought for another computer (an HP Pavilion), recently demised, back in about 2012 or 2013. As far as I can tell, the computer, which is running a 10-core Xeon Scalable processor, is functioning as it should. The first symptom was that the screen would go dark, which I would attempt to...
Back
Top