我需要帮助来创建一个与该等式相对应的矩阵: c *矩阵1 +(1-c)*矩阵2
其中matrix1的计算公式为:
Function VarCovarZeros(InputMatix As Range) As Variant
Dim MatrixColumns As Long
MatrixColumns = InputMatix.Columns.Count
Dim MatrixRows As Long
MatrixRows = InputMatix.Rows.Count
Dim Matrix() As Double
ReDim Matrix(1 To MatrixColumns, 1 To MatrixColumns)
Dim i As Long
For i = 1 To MatrixColumns
Matrix(i, i) = Application.WorksheetFunction.Covar(InputMatix.Columns(i), InputMatix.Columns(i)) * MatrixRows / (MatrixRows - 1)
Next i
VarCovarZeros = Matrix
End Function
矩阵2由下式给出:
Function VarCovar(rng As Range) As Variant
Dim i As Integer
Dim j As Integer
Dim numcols As Integer
numcols = rng.Columns.Count
numrows = rng.Rows.Count
Dim Matrix() As Double
ReDim Matrix(numcols - 1, numcols - 1)
For i = 1 To numcols
For j = 1 To numcols
Matrix(i - 1, j - 1) = Application.WorksheetFunction.Covar(rng.Columns(i), rng.Columns(j)) * numrows / (numrows - 1)
Next j
Next i
VarCovar = Matrix
End Function
这些矩阵基于相同的原始数据,但是需要在每个周期动态更新,为什么我不仅为两个静态矩阵都需要它。
我想将其放在excel函数中,以便: c在“ M1”中
minverse(M1*VarCovarZeros(A3:F27)+(1-c)*(VarCovar(A3:F27))
但是好像它没有将“ M1 * VarCovarZeros(A3:F27)+(1-c)*(VarCovar(A3:F27))”部分作为一个矩阵读取,因为它没有给出结果应该。
这就是为什么我需要使用VBA创建矩阵的帮助,因此可以这样说:
minverse(matrix3(A3:F27))
有人可以帮忙吗?