Eigenvalues, eigenvectors in VBA
Posted: January 13th, 2003, 5:48 pm
Hello everyone,I am trying to create some automation in VBA that will compute eigenvalues and eigenvectors from a given covariance matrix on the spreadsheet. I wish to utilize the power method and solve for each pair by iteration. I have set an initial eigenvector guess as a 3x1 vector X comprised of only 1s. Below is an excerpt from my code:XT = Application.Transpose(X)Y = Application.MMult(A, X)M_0 = Application.Sum(Application.MMult(XT, X), 0)M_1 = Application.Sum(Application.MMult(XT, Y), 0)q = M_1 / M_0largest = Application.Abs(Y(0, 0)) *For i = 1 To matsize If Application.Abs(Y(i, 0)) > largest Then largest = Application.Abs(Y(i, 0)) Next iI am just testing this on a matrix A of dimension 3x3. The value for q will be an approximation for the dominant eigenvalue. The variable largest will be used to standardize the approximating eigenvector Y. After many iterations, q will converge to lamda_1. However, I am getting an error in my code here. The line with the * is causing the problem, as VBA is telling me that I have a problem with subscripts. I am using Option Base 0, and the UBound (Y,1) = 3 and the LBound(Y,1) = 1. In addition, the UBound(Y,2) = 1 and the LBound(Y,2) = 1. Please help me with this error.Thanks in advance!