Download - Elim Gauss

Transcript
Page 1: Elim Gauss

Dim Am(10, 10), xs(10), bv(10) As DoubleSub ElimGauss(ByRef A(), x(), b() As Double, n As Integer)'Dim A(10, 10) As Double'Dim x(10), b(10) As DoubleDim i, j, k As IntegerDim pivot, mult, top As Double'SUBROUTINE Eliminasi Gauss'Begin the subprogramFor j = 1 To n - 1' Begin [outer For..Next loop]' Begin the "Triangularisation"pivot = A(j, j)For i = j + 1 To n' Begin [middle For..Next loop]mult = A(i, j) / pivotFor k = j + 1 To nA(i, k) = A(i, k) - mult * A(j, k)Nextb(i) = b(i) - mult * b(j)Next' End [middle For..Next loop]Next' End [outer For..Next loop]' End of Triangularisation' *--- Substitusi Balik ---*x(n) = b(n) / A(n, n)For i = n - 1 To 1 Step -1top = b(i)For k = i + 1 To ntop = top - A(i, k) * x(k)Nextx(i) = top / A(i, i)NextEnd Sub

Sub SPAL2P()Dim i, j, k, neq As Integer'' INPUT "element" dari matriks "A":neq = 2For i = 1 To neqFor j = 1 To neqAm(i, j) = Cells(i + 7, 15 + j)NextNext' INPUT "element" dari vektor "b":For i = 1 To neqbv(i) = Cells(i + 7, 22)NextCall ElimGauss(Am, xs, bv, 2)' Hasil dan Tampilan ke Excel:For i = 1 To neqCells(i + 7, 19) = xs(i)NextEnd Sub

Sub SPALM2P()'' INPUT "element" dari matriks "A":neq = 2

Page 2: Elim Gauss

For i = 1 To neqFor j = 1 To neqA(i, j) = Cells(i + 13, 2 + j)NextNext' INPUT "element" dari vektor "b":For i = 1 To neqb(i) = Cells(i + 13, 9)Next'Range(Cells(14, 6), Cells(15, 6)).Select' Sama dengan: Range("F14:F15").Select' Range("Cells(14, 6), Cells(15, 6)") ="=MMULT(MINVERSE(C14:D15),I14:I15)"Selection.FormulaArray ="=MMULT(MINVERSE(C14:D15),I14:I15)"' Call ElimGauss(2)' Hasil dan Tampilan ke Excel:' For i = 1 To neq' Cells(i + 13, 6) = x(i)' NextEnd Sub


Top Related