PB with tred2 function SIGN


Ahy_Goon
08-11-2005, 10:20 AM
I used tred2 and tqli to get Eigenvalue vector of a symetric Matrix.
But I don't anderstand what is the function SIGN in tred2.
Can you help me?
Ahy_Goon

Ahy_Goon
08-12-2005, 02:20 AM
I fund the solution by read NR attentivly.
For SIGN and the rest.
But now my Pb is that in tqli, we fund:

"for (l=1;l<=n;l++){ ...."

and later:

"g=(d[l+1]-d[l])/(2.0*e[l]);"
with d[1...n]
So when l=n d[l+1] is not available and it produce an error.

I precis that I work in VB 6.0 and so it could be some trouble with indice start and stop (For loop for exemple with the next i at the end that increment i at the end of the loop.)

Can you help me for this Problem?

Thank Ahy_Goon

Ahy_Goon
08-12-2005, 02:55 AM
I tri the following thing:

The code is in VB6. RQ: The dots are here to indent the code to make it esayer to read.

Public Sub tqli(d() As Single, e() As Single, n As Integer, z() As Single)

Dim m, l, iter, i, k As Integer
Dim s, r, p, g, f, dd, c, b As Single

Dim bl_Test As Boolean


bl_Test = False

....For i = 2 To n
.......e(i - 1) = e(i)
....Next i
....e(n) = 0
....For l = 1 To n
........iter = 0
........While (m <> l)
............For m = l To n - 1
................bl_Test = True
................dd = Abs(d(m)) + Abs(d(m + 1))
................If CSng(Abs(e(m)) + dd) = dd Then Exit For
............Next m
............If bl_Test = True Then /* chek if we have make the loop FOR */
................m = m - 1
................bl_Test = False
............End If
............If m <> l Then
................iter = iter + 1
................If iter = 30 Then
....................Debug.Print "Too many iteration in tqli!"
....................GoTo ExitWhile
................End If
................g = (d(l + 1) - d(l)) / (2 * e(l))
................r = pythag(CSng(g), 1)
................g = d(m) - d(l) + e(l) / (g + sign(CSng(r), CSng(g)))
................s = c = 1
................p = 0 ...

No error but it doesn't work correctly:
For in input matrix:
1 2
2 3

tred2 +tqli give

Eigen Value: 1 and 3
Eigen Vector:
-3 1
2 0
Do you see the Problem?

gaspari
08-12-2005, 05:17 PM
Uhm...no.

Have a careful look at the C source code. Before
the

if (m != l)..

there is a loop for (m=l;m<=n-1;++l) ....


when l == n ....


Which is your problem ? try to post an example with output from
the NR routines.

Regards


Massimo

Ahy_Goon
08-16-2005, 12:40 AM
Thanks for your help.
I found the solution.
The pb come because I code in VB6 and the instructions like:
"a=b=c"
doesn't work with it.
And i have a solution for all the mistacke i made .
regards,
Y Goyer