Results 1 to 14 of 14

Thread: [2005] help understanding how to use this module plz

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    [2005] help understanding 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
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: [2005] help understanding how to use this module plz

    It would, you have a multi-dimension array being passed to a function that only takes an array

    ie:

    SymmetricEVD(ByRef A_() As Double Needs a Dim mat (0 to 1) not a mat(0 to 1, 0 to 1). What makes you think you had to do that?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: [2005] help understanding how to use this module plz

    in the module description
    "symmetric matrix which is given by its upper or lower
    ' triangular part.
    ' Array whose indexes range within [1..N, 1..N]."
    how can i store a matrix in a 1d array??

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

    Re: [2005] help understanding how to use this module plz

    The function should read like this if that was the case, but I have no idea what the functions you are calling within that are declared as:

    Public Function SymmetricEVD(ByRef A_(,) As Double, _
    ByVal N As Long, _
    ByVal ZNeeded As Long, _
    ByVal IsUpper As Boolean, _
    ByRef D(,) As Double, _
    ByRef Z(,) As Double) As Boolean

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

    Re: [2005] help understanding how to use this module plz

    I've just read the site (Im feeling helpful ) the code you are using is from VB6, which you do not have to declare as a specifc array size. You can use either (0 to 1) or (0 to 1, 0 to 1).

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: [2005] help understanding how to use this module plz

    oh i posted in the wrong forum.. but anyway how can i use this in vb 2005??

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

    Re: [2005] help understanding how to use this module plz

    It depends what you have, I assume you have a .dll from this place that contains UnpackQFromTridiagonal and TridiagonalEVD methods?

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: [2005] help understanding how to use this module plz

    no it's not a .dll but a .bas for the other functions

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

    Re: [2005] help understanding how to use this module plz

    Well, you will have to convert them as well into a module, and update it to take the new array, probly in the method declaration again.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: [2005] help understanding how to use this module plz

    anyway what am i doing wrong in my code..cuz i am getting "type mismatch"

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

    Re: [2005] help understanding how to use this module plz

    I have already said what would be going wrong, and suggested what to do.

    You need to convert the bas file into .net. You will most likely have to change the .bas file to use this array, as VB6 allows you to pass arrays about without being specific of their size. This will mean changing the declaration of the functions to use multi-dimension arrays.

    I have included an example of what the new function header would look like, but you havent shown anything of the .bas file so I can't advise on how to change it.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    128

    Re: [2005] help understanding how to use this module plz

    oh ok will post this on vb6 forum thanks

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

    Re: [2005] help understanding how to use this module plz

    Im lost, I thought you are coding this in .net 2005 ?

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

    Re: [2005] help understanding how to use this module plz

    It all becomes clear...
    It is VB6 your using this in, which works differently. But you did ask how to get this working in 2005. Sorry for wasting your time.

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