※ 引述《collegeman (花生)》之銘言:
: Private Function ReductionUpTriangularForm(ByVal Matrix As Double(,)) _
: As Double(,)
: Dim i, j, k As Integer
: For i = 0 To UBound(Matrix, 2) - 1
: '
: 'Find the element of maximum magnitude
: '
: Dim MaxValueIndex As Double = i + 1
: For j = i + 1 To UBound(Matrix, 1)
: If Matrix(j, i) > Matrix(MaxValueIndex, i) Then
: MaxValueIndex = j :
: End If
: Next
: If Matrix(MaxValueIndex, i) <> 0 Then
: '
: 'Interchange rows
: '
: Dim TempVector_Row(UBound(Matrix, 2)) As Double
: For j = 0 To UBound(Matrix, 2)
: TempVector_Row(j) = Matrix(MaxValueIndex, j)
: Next
: For j = 0 To UBound(Matrix, 2)
: Matrix(MaxValueIndex, j) = Matrix(i, j)
: Matrix(i, j) = TempVector_Row(j)
: Next
: '
: 'Compute the multiplier and make the elimination
: '
: For j = i + 1 To UBound(Matrix, 1)
: Dim Multiplier As Double = Matrix(j, i) / Matrix(i, i)
: For k = 0 To UBound(Matrix, 2)
: Matrix(j, k) -= Multiplier * Matrix(i, k)
: Next
: Next
: End If
: Next
: Return Matrix
: End Function
感謝感謝…:
這感覺上是類似高斯消去法…
請問一下,如果我的A矩陣是一個幾百乘幾百的矩陣,這樣解起來會很慢嗎??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.76.172