PDA

View Full Version : Type Mismatch



Meskit
12-12-2009, 02:59 AM
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:

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


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

Bob Phillips
12-12-2009, 06:06 AM
We need the rest of the code, where maxit gets set, the pop routine, etc.