Eigenvalues of a tridiagonal matrix

AI Thread Summary
The discussion revolves around the subroutine tqli(d,e,z) from "Numerical Recipes in Fortran," specifically its implementation and logic in the context of eigenvalue calculations. Users express confusion regarding the Jacobi rotation technique and the role of the three modules involved in the subroutine. One participant mentions their experience with a similar problem in C and seeks clarification on how to implement the Fortran version, particularly focusing on a tridiagonal matrix with specific diagonal and off-diagonal properties. They request an explicit explanation of the subroutine, particularly in Fortran 90, while providing a link to the Fortran 77 version for reference. The subroutine itself is designed to compute the eigenvalues of a symmetric tridiagonal matrix, with the optional parameter z intended for eigenvector calculations, although the user is currently only interested in the eigenvalues. The conversation highlights the need for clear explanations and examples to aid understanding of the algorithm's implementation.
petr1243
Messages
12
Reaction score
0
Could some one please explain the logic behind the subroutine tqli(d,e,z) found on pg.1228 of numerical recipes in fortran. For this subroutine, d and e are one dimensional arrays and z is an optional multi-dimensional array(only used if also seeking for eigenvectors of matrix). The 3 modules, and the whole jacobi rotation technique has me confused. Thank you very much.
 
Technology news on Phys.org
It looks like you're looking at the F90 version...
Have you looked at the online F77 version that provides some explanation?
 
Are you referring to the explanation from indiana university? If it isn't, then could you please send me the link.
 
Can you post the contents of the subroutine?

I've actually worked on this problem before - in C, however - but maybe I can help provide some input.
 
I'm actually working on a tridiagonal matrix in which the diagonal term is some forumla in terms of integer n, and the super and sub diagonal terms are equivalent to one another(constant, independent of n). I would like to implement this subroutine into my program. I would prefer an explanation in f90, but if you can explain it in f77 then that's fine. Here is the f77 program: http://www.physics.louisville.edu/help/nr/bookfpdf/f11-3.pdf (on pg.474)

I am not too skilled in f77, so could you please be explicit in your explanation. Thank you for your time.
Here is the subroutine in f90, where the 3 modules are easily accessible on the net:

SUBROUTINE tqli(d,e,z)

USE nrtype; USE nrutil, ONLY : assert_eq, nrerror
USE nr, ONLY : pythag

IMPLICIT NONE

REAL(sp), DIMENSION(:), INTENT(inout) :: d, e
!REAL(sp), DIMENSION(:,:), OPTIONAL, INTENT(inout) :: z

INTEGER(i4b) :: i, iter, l, m, n, ndum
REAL(sp) :: b, c, dd, f, g, p, r, s
REAL(sp), DIMENSION(SIZE(e)) :: ff

n = assert_eq(SIZE(d), SIZE(e), 'tqli: n')
!IF(PRESENT(z)) ndum=assert_eq(n, SIZE(z, 1), SIZE(z, 2), 'tqli: ndum')
e(:)=EOSHIFT(e(:),1)
DO l=1, n
iter=0
iterate: DO
DO m=l, n-1
dd=ABS(d(m)) + ABS(d(m+1))
IF(ABS(e(m))+dd == dd) EXIT
END DO
IF (m==l) EXIT iterate
IF(iter == 30) CALL nrerror('too many iterations in tqli')
iter = iter+1
g=(d(l+1)-d(l))/(2.0_sp*e(l))
r = pythag(g, 1.0_sp)
g = d(m) - d(l) + e(l) / (g + SIGN(r, g))
s = 1.0
c = 1.0
p = 0.0
DO i = m-1, l, -1
f = s*e(i)
b = c*e(i)
r = pythag(f, g)
e(i+1) = r
IF(r == 0.0) THEN
d(i+1) = d(i+1) - p
e(m) = 0.0
CYCLE iterate
END IF
s = f/r
c = g/r
g = d(i + 1) - p
r = (d(i) - g) * s + 2.0_sp * c * b
p = s * r
d(i + 1) = g + p
g = c * r - b
!IF(PRESENT(z)) THEN
!ff(1:n) = z(1:n,i+1)
!z(1:n, i+1) = s*z(1:n,i) + c*ff(1:n)
!z(1:n,i) = c*z(1:n, i) - s*ff(1:n)
!END IF
END DO
d(l) = d(l) - p
e(l) = g
e(m) = 0.0
END DO iterate
END DO
END SUBROUTINE tqli

!I have commented z out, since I'm only interested in the eigenvalues of this matrix.
 
Last edited by a moderator:
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...

Similar threads

Replies
18
Views
6K
Replies
12
Views
3K
Replies
21
Views
2K
Replies
18
Views
3K
Replies
2
Views
2K
Replies
7
Views
2K
Replies
2
Views
2K
Replies
2
Views
3K
Back
Top