Link to home
Start Free TrialLog in
Avatar of Michael Hamacher
Michael Hamacher

asked on

EigenvectorEigenValues - Debug

The code in module 2 of attached sheet contains a function PORT_FACTOR_EIGEN_VALUES_VECTORS_JACOBI_FUNC, which essentially is supposed to return the eigenvectors and eigenvalues of a matrix (based on the so-called Jacobi method, for what its worth).

However, it seems that the code gets stuck & throws up an error message...

The issue seems to be in the following code segment: ROTATION_ARR(3), which gives a ‘type mismatch’ error
(NB: By default (variable ‘output’ = 0), the code jumps straight to the 2nd pass (1983)).

Understand that its not necessarily an easy one, but any help would be greatly appreciated

Cheers


A_ROTATION_LINE: 'Returns vector containing the row and column vectors and
'the angle of rotation for the P matrix
'------------------------------------------------------------------------------------------------
 ReDim TEMP_MATRIX(1 To NSIZE, 1 To NSIZE)
 MAX_VAL = -1
 ii = -1
 jj = -1
 For i = 1 To NSIZE
 For j = i + 1 To NSIZE
 TEMP_MATRIX(i, j) = Abs(DATA_MATRIX(i, j))
 If TEMP_MATRIX(i, j) > MAX_VAL Then
 MAX_VAL = TEMP_MATRIX(i, j)
 ii = i
 jj = j
 End If
 Next j
 Next i
 If DATA_MATRIX(ii, ii) = DATA_MATRIX(jj, jj) Then
 RAD_VAL = 0.25 * PI_VAL * Sgn(DATA_MATRIX(ii, jj))
 Else
 RAD_VAL = 0.5 * Atn(2 * DATA_MATRIX(ii, jj) / (DATA_MATRIX(ii, ii) - DATA_MATRIX(jj, jj)))
 End If
 ROTATION_ARR = Array(ii, jj, RAD_VAL)
'------------------------------------------------------------------------------------------------
Return
'------------------------------------------------------------------------------------------------


'------------------------------------------------------------------------------------------------
R_ROTATION_LINE:
'Returns the rotation PTHIS_MATRIX matrix
'------------------------------------------------------------------------------------------------
 ReDim PTHIS_MATRIX(1 To NSIZE, 1 To NSIZE)
 For i = 1 To NSIZE: PTHIS_MATRIX(i, i) = 1: Next i 'Identity Matrix
 PTHIS_MATRIX(ROTATION_ARR(1), ROTATION_ARR(1)) = Cos(ROTATION_ARR(3))
 PTHIS_MATRIX(ROTATION_ARR(2), ROTATION_ARR(1)) = Sin(ROTATION_ARR(3))
 PTHIS_MATRIX(ROTATION_ARR(1), ROTATION_ARR(2)) = -Sin(ROTATION_ARR(3))
 PTHIS_MATRIX(ROTATION_ARR(2), ROTATION_ARR(2)) = Cos(ROTATION_ARR(3))
'------------------------------------------------------------------------------------------------
Return
'-----------------------------------------
EigenVektorValues.xlsm
Avatar of Michael Hamacher
Michael Hamacher

ASKER

Hello;

 thank you for your comment, well appreciated. I can assure you that none of my questions is a 'homework' question, or related to an academic setting. Rather, two of them center around methods intended for historical data analysis (PCA, Eigendecomposition), whereas the others around Least-squares, an application for generating hedging for a financial risk portfolio
ASKER CERTIFIED SOLUTION
Avatar of Bitsqueezer
Bitsqueezer
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Vielen Dank!
Gern geschehen...:-)