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

In summary, the programmer was trying to solve a problem where they were using a routine from the netlib and they were not following the instructions. They were using a canned routine that was supposed to spit out 1 and 2 when the programmer put in a diagonal matrix with 1 and 2 on the diagonals. However, when the programmer ran the code, it gave them a segmentation fault error. After fixing the mistake, the programmer was able to solve the problem.
  • #1
llello
32
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
  • #2
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.
 

1. What is the purpose of using rgg.f for calculating eigenvalues?

Rgg.f is a computer program that uses the Rayleigh-Ritz-Galerkin method to calculate eigenvalues for a given matrix. This method is commonly used in scientific computing to solve eigenvalue problems, which have many applications in physics, engineering, and other fields.

2. How does rgg.f calculate eigenvalues?

Rgg.f uses the Rayleigh-Ritz-Galerkin method, which is an iterative numerical algorithm that approximates eigenvalues by finding the minimum of a certain functional. This functional is related to the eigenvalue problem and its solution, and as the algorithm progresses, it converges to the true eigenvalue.

3. Is rgg.f suitable for all types of matrices?

Rgg.f is typically used for symmetric matrices, as the Rayleigh-Ritz-Galerkin method is specifically designed for these types of matrices. However, it can also be used for non-symmetric matrices with some modifications.

4. How accurate are the eigenvalues calculated by rgg.f?

The accuracy of eigenvalues calculated by rgg.f depends on the number of iterations and the convergence criteria used. Generally, the more iterations and stricter convergence criteria used, the more accurate the results will be. However, it is important to note that rgg.f is an iterative method, so there will always be some degree of error in the calculated eigenvalues.

5. Can rgg.f calculate multiple eigenvalues at once?

Yes, rgg.f can calculate multiple eigenvalues at once. The user can specify the number of eigenvalues to be calculated, and the program will return the corresponding eigenvalues in order of magnitude.

Similar threads

  • Programming and Computer Science
Replies
4
Views
612
  • Programming and Computer Science
Replies
3
Views
1K
  • Quantum Physics
Replies
2
Views
967
  • Atomic and Condensed Matter
Replies
3
Views
865
  • Special and General Relativity
Replies
7
Views
912
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
5K
Replies
6
Views
1K
  • Programming and Computer Science
Replies
12
Views
3K
  • Programming and Computer Science
Replies
7
Views
4K
Back
Top