Results 1 to 6 of 6

Thread: [RESOLVED] help me understand how to use this module plz

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Resolved [RESOLVED] help me understand how to use this module plz

    i want to find the eigenvectors and eigenvalues for a matrix... can someone help me use this module from

    VB Code:
    1. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    2. 'This code is generated by the AlgoPascal translator
    3. '
    4. 'This code is distributed under the ALGLIB license
    5. '    (see [url]http://www.alglib.net/copyrules.php[/url] for details)
    6. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    7. 'This routines must be defined by the programmer
    8. ' Function TridiagonalEVD(ByRef D() As Double, _
    9. '         ByRef E_() As Double, _
    10. '         ByVal N As Long, _
    11. '         ByVal ZNeeded As Long, _
    12. '         ByRef Z() As Double) As Boolean
    13. ' Sub ToTridiagonal(ByRef A() As Double, _
    14. '         ByVal N As Long, _
    15. '         ByVal IsUpper As Boolean, _
    16. '         ByRef Tau() As Double, _
    17. '         ByRef D() As Double, _
    18. '         ByRef E() As Double)
    19. ' Sub UnpackQFromTridiagonal(ByRef A() As Double, _
    20. '         ByRef N As Long, _
    21. '         ByRef IsUpper As Boolean, _
    22. '         ByRef Tau() As Double, _
    23. '         ByRef Q() As Double)
    24.  
    25.  
    26. 'Routines
    27. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    28. 'Finding the eigenvalues and eigenvectors of a symmetric matrix
    29. '
    30. 'The algorithm finds eigen pairs of a symmetric matrix by reducing it to
    31. 'tridiagonal form and using the QL/QR algorithm.
    32. '
    33. 'Input parameters:
    34. '    A       -   symmetric matrix which is given by its upper or lower
    35. '                triangular part.
    36. '                Array whose indexes range within [1..N, 1..N].
    37. '    N       -   size of matrix A.
    38. '    IsUpper -   storage format.
    39. '    ZNeeded -   flag controlling whether the eigenvectors are needed or not.
    40. '                If ZNeeded is equal to:
    41. '                 * 0, the eigenvectors are not returned;
    42. '                 * 1, the eigenvectors are returned.
    43. '
    44. 'Output parameters:
    45. '    D       -   eigenvalues in ascending order.
    46. '                Array whose index ranges within [1..N].
    47. '    Z       -   if ZNeeded is equal to:
    48. '                 * 0, Z hasn’t changed;
    49. '                 * 1, Z contains the eigenvectors.
    50. '                Array whose indexes range within [1..N, 1..N].
    51. '                The eigenvectors are stored in the matrix columns.
    52. '
    53. 'Result:
    54. '    True, if the algorithm has converged.
    55. '    False, if the algorithm hasn't converged (uncommon case).
    56. '
    57. '  -- ALGLIB --
    58. '     Copyright 2005 by Bochkanov Sergey
    59. '
    60. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    61. Public Function SymmetricEVD(ByRef A_() As Double, _
    62.          ByVal N As Long, _
    63.          ByVal ZNeeded As Long, _
    64.          ByVal IsUpper As Boolean, _
    65.          ByRef D() As Double, _
    66.          ByRef Z() As Double) As Boolean
    67.     Dim Result As Boolean
    68.     Dim A() As Double
    69.     Dim Tau() As Double
    70.     Dim E() As Double
    71.     A = A_
    72.  
    73.     Call ToTridiagonal(A, N, IsUpper, Tau, D, E)
    74.     If ZNeeded = 1# Then
    75.         Call UnpackQFromTridiagonal(A, N, IsUpper, Tau, Z)
    76.     End If
    77.     Result = TridiagonalEVD(D, E, N, ZNeeded, Z)
    78.  
    79.     SymmetricEVD = Result
    80. End Function

    i got this module from http://www.alglib.net/eigen/symmetric/symmevd.php .. i have add the ap lib module and this module...

    i used that code to test the function SymmetricEVD

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim mat(0 To 1, 0 To 1), Result(0 To 1, 0 To 1), eigenvect(0 To 1, 0 To 1) As Double
    3.  
    4. mat(0, 0) = 1
    5. mat(0, 1) = 2
    6. mat(1, 0) = 3
    7. mat(1, 1) = 4
    8.  
    9. Call SymmetricEVD(mat, 2, 1, True, Result, eigenvect)
    10. End Sub

    but i get "type mismatch"

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: help me understand how to use this module plz

    Quote Originally Posted by lplover2k
    i get "type mismatch"
    On what line?

  3. #3
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: help me understand how to use this module plz

    And don't bother with the "Call" part. The function name will be returned as a Boolean variable, so for your return, put something like this:

    VB Code:
    1. MsgBox SymmetricEVD(mat, 2, 1, True, Result, eigenvect)

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: help me understand how to use this module plz

    Quote Originally Posted by lplover2k
    but i get "type mismatch"
    well mat and result aren't declared as double, they're declared as variants, it should be:
    VB Code:
    1. Dim mat(0 To 1, 0 To 1) As Double, Result(0 To 1, 0 To 1) As Double, eigenvect(0 To 1, 0 To 1) As Double

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: help me understand how to use this module plz

    BushMobile: thank u!!!

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: help me understand how to use this module plz


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width