Tema10 - 10.14 Option Explicit Sub LUDTest() Dim n As...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 10.14 Option Explicit Sub LUDTest() Dim n As Integer, er As Integer, i As Integer, j As Integer Dim a(3, 3) As Single, b(3) As Single, x(3) As Single Dim tol As Single n = 3 a(1, 1) = 3: a(1, 2) = -0.1: a(1, 3) = -0.2 a(2, 1) = 0.1: a(2, 2) = 7: a(2, 3) = -0.3 a(3, 1) = 0.3: a(3, 2) = -0.2: a(3, 3) = 10 b(1) = 7.85: b(2) = -19.3: b(3) = 71.4 tol = 0.000001 Call LUD(a(), b(), n, x(), tol, er) 'output results to worksheet Sheets("Sheet1").Select Range("a3").Select For i = 1 To n ActiveCell.Value = x(i) ActiveCell.Offset(1, 0).Select Next i Range("a3").Select End Sub Sub LUD(a, b, n, x, tol, er) Dim i As Integer, j As Integer Dim o(3) As Single, s(3) As Single Call Decompose(a, n, tol, o(), s(), er) If er = 0 Then Call Substitute(a, o(), n, b, x) Else MsgBox "ill-conditioned system" End End If End Sub Sub Decompose(a, n, tol, o, s, er) Dim i As Integer, j As Integer, k As Integer Dim factor As Single For i = 1 To n o(i) = i s(i) = Abs(a(i, 1)) For j = 2 To n If Abs(a(i, j)) > s(i) Then s(i) = Abs(a(i, j)) Next j Next i For k = 1 To n - 1 Call Pivot(a, o, s, n, k) If Abs(a(o(k), k) / s(o(k))) < tol Then er = -1 Exit For End If For i = k + 1 To n factor = a(o(i), k) / a(o(k), k) a(o(i), k) = factor For j = k + 1 To n a(o(i), j) = a(o(i), j) - factor * a(o(k), j) Next j Next i Next k If (Abs(a(o(k), k) / s(o(k))) < tol) Then er = -1 End Sub Sub Pivot(a, o, s, n, k) Dim ii As Integer, p As Integer Dim big As Single, dummy As Single p = k big = Abs(a(o(k), k) / s(o(k))) For ii = k + 1 To n dummy = Abs(a(o(ii), k) / s(o(ii))) If dummy > big Then big = dummy...
View Full Document

Page1 / 12

Tema10 - 10.14 Option Explicit Sub LUDTest() Dim n As...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online