vba 矩阵运算Sub 矩阵写入() '由孪晶组合计算N矩阵Dim arr(1 To 3,1 To 3) As Variantarr(1,1) = Sheets("sheet1").Range("CJ2").Valuearr(1,2) = Sheets("sheet1").Range("CK2").Valuearr(1,3) = Sheets("sheet1").Range("CL2").Valuearr(2,1) = Shee
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/05 18:56:08
vba 矩阵运算Sub 矩阵写入() '由孪晶组合计算N矩阵Dim arr(1 To 3,1 To 3) As Variantarr(1,1) = Sheets("sheet1").Range("CJ2").Valuearr(1,2) = Sheets("sheet1").Range("CK2").Valuearr(1,3) = Sheets("sheet1").Range("CL2").Valuearr(2,1) = Shee
vba 矩阵运算
Sub 矩阵写入() '由孪晶组合计算N矩阵
Dim arr(1 To 3,1 To 3) As Variant
arr(1,1) = Sheets("sheet1").Range("CJ2").Value
arr(1,2) = Sheets("sheet1").Range("CK2").Value
arr(1,3) = Sheets("sheet1").Range("CL2").Value
arr(2,1) = Sheets("sheet1").Range("EE2").Value
arr(2,2) = Sheets("sheet1").Range("EF2").Value
arr(2,3) = Sheets("sheet1").Range("EG2").Value
arr(3,1) = Sheets("sheet1").Range("EU2").Value
arr(3,2) = Sheets("sheet1").Range("EV2").Value
arr(3,3) = Sheets("sheet1").Range("EW2").Value
Dim brr(1 To 3,1 To 3) As Variant
brr(1,1) = Sheets("sheet1").Range("DC2").Value
brr(1,2) = Sheets("sheet1").Range("DD2").Value
brr(1,3) = Sheets("sheet1").Range("DE2").Value
brr(2,1) = Sheets("sheet1").Range("EI2").Value
brr(2,2) = Sheets("sheet1").Range("EJ2").Value
brr(2,3) = Sheets("sheet1").Range("EK2").Value
brr(3,1) = Sheets("sheet1").Range("EY2").Value
brr(3,2) = Sheets("sheet1").Range("EZ2").Value
brr(3,3) = Sheets("sheet1").Range("FA2").Value
Sheets("sheet1").Range("FC24:FE26").Value = arr
Sheets("sheet1").Range("FC19:FE21").Value = brr
crr = "=TRANSPOSE(MMULT(MINVERSE(brr),arr))" 'N矩阵的逆矩阵
Sheets("sheet1").Range("FG20:FI22").Value = crr
End Sub
请问为什么Sheets("sheet1").Range("FG20:FI22")里面都显示出错了#NOME?
vba 矩阵运算Sub 矩阵写入() '由孪晶组合计算N矩阵Dim arr(1 To 3,1 To 3) As Variantarr(1,1) = Sheets("sheet1").Range("CJ2").Valuearr(1,2) = Sheets("sheet1").Range("CK2").Valuearr(1,3) = Sheets("sheet1").Range("CL2").Valuearr(2,1) = Shee
crr = "=TRANSPOSE(MMULT(MINVERSE(brr),arr))"
用
with WorksheetFunction
crr = .Transpose(.MMult(.MInverse(brr),arr))
end with
试试
---------------------------------------------------------------------------------------------------------------------
Sheets("sheet1").Range("CJ2").Value = 1
Sheets("sheet1").Range("CK2").Value = 2
Sheets("sheet1").Range("CL2").Value = 100
Sheets("sheet1").Range("EE2").Value = 100
Sheets("sheet1").Range("EF2").Value = 5
Sheets("sheet1").Range("EG2").Value = 6
Sheets("sheet1").Range("EU2").Value = 7
Sheets("sheet1").Range("EV2").Value = 100
Sheets("sheet1").Range("EW2").Value = 9
Sheets("sheet1").Range("DC2").Value = 10
Sheets("sheet1").Range("DD2").Value = 100
Sheets("sheet1").Range("DE2").Value = 12
Sheets("sheet1").Range("EI2").Value = 100
Sheets("sheet1").Range("EJ2").Value = 14
Sheets("sheet1").Range("EK2").Value = 15
Sheets("sheet1").Range("EY2").Value = 16
Sheets("sheet1").Range("EZ2").Value = 17
Sheets("sheet1").Range("FA2").Value = 100
Dim arr(1 To 3, 1 To 3) As Variant
arr(1, 1) = Sheets("sheet1").Range("CJ2").Value
arr(1, 2) = Sheets("sheet1").Range("CK2").Value
arr(1, 3) = Sheets("sheet1").Range("CL2").Value
arr(2, 1) = Sheets("sheet1").Range("EE2").Value
arr(2, 2) = Sheets("sheet1").Range("EF2").Value
arr(2, 3) = Sheets("sheet1").Range("EG2").Value
arr(3, 1) = Sheets("sheet1").Range("EU2").Value
arr(3, 2) = Sheets("sheet1").Range("EV2").Value
arr(3, 3) = Sheets("sheet1").Range("EW2").Value
Dim brr(1 To 3, 1 To 3) As Variant
brr(1, 1) = Sheets("sheet1").Range("DC2").Value
brr(1, 2) = Sheets("sheet1").Range("DD2").Value
brr(1, 3) = Sheets("sheet1").Range("DE2").Value
brr(2, 1) = Sheets("sheet1").Range("EI2").Value
brr(2, 2) = Sheets("sheet1").Range("EJ2").Value
brr(2, 3) = Sheets("sheet1").Range("EK2").Value
brr(3, 1) = Sheets("sheet1").Range("EY2").Value
brr(3, 2) = Sheets("sheet1").Range("EZ2").Value
brr(3, 3) = Sheets("sheet1").Range("FA2").Value
Sheets("sheet1").Range("FC24:FE26").Value = arr
Sheets("sheet1").Range("FC19:FE21").Value = brr
'crr = "=TRANSPOSE(MMULT(MINVERSE(brr),arr))" 'N矩阵的逆矩阵
With WorksheetFunction
crr = .Transpose(.MMult(.MInverse(brr), arr))
End With
这是我的测试数据,没有问题
如果你出现1004错误 说类WorksheetFunction的MInverse属性无法记问,那么应该是你给出的矩阵不可逆的关系.