⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jie.txt

📁 解各类线性方程的方法以及相关的编程! 希望可以采用我这个工程软件,我可是花了好多的心血!
💻 TXT
字号:
文件头:

Private Sub Command1_Click()


Dim a() As Double, b() As Double, n As Integer


n = 3


ReDim a(n, n) As Double, b(n) As Double


a(1, 1) = 2


a(1, 2) = 0


a(1, 3) = 0


a(2, 1) = 3


a(2, 2) = 1


a(2, 3) = 0


a(3, 1) = 0


a(3, 2) = 4


a(3, 3) = 1


b(1) = 2


b(2) = 4


b(3) = 5


Solve a(), b()


Print b(1), b(2), b(3)


End Sub





Private Sub Solve(a() As Double, b() As Double)


'Gaussian elimination method, coded by www.dayi.net btef (please let this line remain)


Dim ii As Integer, i As Integer, j As Integer


Dim i1 As Integer, d1 As Double


Dim n As Integer, index() As Integer, x() As Double


Dim maxV As Double, maxI As Integer, maxJ As Integer





n = UBound(b)


ReDim index(n) As Integer, x(n) As Double


For i = 1 To n


index(i) = i


Next i





For ii = 1 To n - 1


maxV = Abs(a(ii, ii))


maxI = ii


maxJ = ii


For i = ii To n


For j = ii To n


If Abs(a(i, j)) > maxV Then


maxV = Abs(a(i, j))


maxI = i 'row of max element


maxJ = j 'column of max element


End If


Next j


Next i


If ii <> maxI T文件尾:

hen 'exchange rows


d1 = b(maxI)


b(maxI) = b(ii)


b(ii) = d1


For j = ii To n


d1 = a(maxI, j)


a(maxI, j) = a(ii, j)


a(ii, j) = d1


Next j


End If


If ii <> maxJ Then 'exchange columns


i1 = index(maxJ)


index(maxJ) = index(ii)


index(ii) = i1


For i = 1 To n


d1 = a(i, maxJ)


a(i, maxJ) = a(i, ii)


a(i, ii) = d1


Next i


End If





For i = ii + 1 To n 'elemination


d1 = a(i, ii) / a(ii, ii)


For j = ii + 1 To n


a(i, j) = a(i, j) - a(ii, j) * d1


Next j


b(i) = b(i) - b(ii) * d1


Next i


Next ii





x(n) = b(n) / a(n, n) 'back substitution


For i = n - 1 To 1 Step -1


d1 = 0#


For j = i + 1 To n


d1 = d1 + a(i, j) * x(j)


Next j


x(i) = (b(i) - d1) / a(i, i)


Next i


For i = 1 To n


b(index(i)) = x(i)


Next i





End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -