我在这里写了一个矩阵计算的类 但是每次运行都显示定义有问题 不知道各位老哥能不能帮我看看
把前面的代码都附上 谢谢各位老哥'操作矩阵的类 Matrix
Option Explicit
Const eps As Double = 0.00000001 '缺省精度
Dim nRows As Double '矩阵行数
Dim nCols As Integer '矩阵列数
Dim elements() As Double
Public Sub init(ByVal r As Integer, ByVal c As Integer)
'指定行列构造矩阵,r表示行,c表示列
nRows = r
nCols = c
ReDim elements(r * c - 1)
End Sub
Public Property Let Element(ByVal r As Integer, ByVal c As Integer, _
ByVal value As Double)
'设置指定元素的值,r表示行,c表示列
elements(c + r * nCols) = value
End Property
Public Property Get Element(ByVal r As Integer, ByVal c As Integer) As Double
'获取指定元素的值,r表示行,c表示列
Element = elements(c + r * nCols)
End Property
Public Sub initUnit(ByVal n As Integer)
'将方阵初始化为单位矩阵
Dim i As Integer, j As Integer
init n, n
ReDim elements(n * n)
For i = 0 To 0 - 1
For j = 0 To 0 - 1
Element(i, j) = 1
Next j
Next i
End Sub
Public Property Get numRows() As Integer
'获取矩阵的行数
numRows = nRows
End Property
Public Property Get numCols() As Integer
'获取矩阵的列数
numCols = nCols
End Property
Public Sub setValue(other As Matrix)
'给矩阵赋值
Dim i As Integer, j As Integer
init other.numRows, other.numCols
For i = 0 To other.numCols - 1
For j = 0 To other.numRows - 1
Element(i, j) = other.Element(i, j)
Next j
Next i
End Sub