YoichiroUrita / Math

Mainly linear algebra function by various computer languages
2 stars 2 forks source link

EigenValuesForSymmetricMatirx.vba not true VBA #1

Open andrew-c-duncan opened 10 months ago

andrew-c-duncan commented 10 months ago

In VBA the Type must be assigned to each variable in the Dim Statement, even if all the variables are on one line separated by commas. If this is not done, the variables default to Type Variant.

Therefore: in "EigenValuesForSymmetricMatirx.vba" for Function EigenValueJ, for the first four Dim Statements:

Dim i, j, k, N, II, n_div, K_new, i_div, i_rot, j_rot, Kmax As Integer
Dim a(), U(), v() As Double
Dim b1, b2, b3, a_max, EpsRate, Eps, K_iter, ax, v_cos, v_sin, v_tan As Double
Dim i1, i2 As Double

Only Kmax is an Integer, v() is a Double, v_tan is a Double, and i2 is a Double. All other variables are Type Variant.

The above Dim Statements are fine for Visual Basic but not for Visual Basic for Applications.

For correct VBA, the following is required:

Dim i As Integer, j As Integer, k As Integer, N As Integer, II As Integer, _
    n_div As Integer, K_new As Integer, i_div As Integer, _
    i_rot As Integer, j_rot As Integer, Kmax As Integer
Dim a() As Double, U() As Double, v() As Double
Dim b1 As Double, b2 As Double, b3 As Double, a_max As Double, _
    EpsRate As Double, Eps As Double, K_iter As Double, ax As Double, _
    v_cos As Double, v_sin As Double, v_tan As Double
Dim i1 As Double, i2 As Double
YoichiroUrita commented 8 months ago

Thank you for your pointing out. That's right.