Consulting

Results 1 to 2 of 2

Thread: Type Mismatch

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Dec 2009
    Posts
    3
    Location

    Type Mismatch

    Hi all, a question here. A simple routine for least square calculation. This is run for iterations=1 to iterations= max input by user. It runs well in the first itīs but i get the type mismatch error when calculating the inverted matrix. If someone has a clue i would be thankfull.


    VBA CODE:

    [vba]Sub LeastSqr()

    For k=1 to maxit

    ReDim m_aux(1 To pop(it), 1 To nv)
    ReDim fcrit_aux(1 To pop(it))

    For i = 1 To pop(it)
    For j = 1 To nv
    m_aux(i, j) = m_swarm(i, j)
    Next j
    fcrit_aux(i) = fcrit(i)
    Next i

    fcrit_aux = Application.Transpose(fcrit_aux)

    ReDim m_aux1(1 To pop(it), 1 To 3)

    ReDim coef2(1 To 3, 1 To nv)

    For j = 1 To nv
    For i = 1 To pop(it)
    m_aux1(i, 1) = 1
    m_aux1(i, 2) = m_aux(i, j)
    m_aux1(i, 3) = m_aux(i, j) ^ 2
    Next i

    mt1 = Application.Transpose(m_aux1)

    mm1 = Application.MMult(mt1, m_aux1)

    ReDim minv1(1 To nv, 1 To nv)
    minv1 = Application.MInverse(mm1) ""TYPE MISMATCH ERROR FOR K=16 FOR EXAMPLE""

    ReDim mmm1(1 To nv, 1 To pop(it))
    mmm1 = Application.MMult(minv1, mt1)

    ReDim mmmm1(1 To nv)
    mmmm1 = Application.MMult(mmm1, fcrit_aux)

    NExt j
    Next k
    [/vba]

    This is working fine for a few iterations, but then it stucks with the type mismatch error in "minv1 = Application.MInverse(mm1)" line.

    With add watch i confirmed that
    minv: Variant (1 to 3, 1 to 3)
    mm1: Variant (1 to 3, 1 to 3)

    mm1=
    50 22 10
    22 10 4
    10 4 2
    Last edited by Bob Phillips; 12-12-2009 at 06:04 AM. Reason: Add VBA tags

Posting Permissions

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