# Untitled

By: a guest on Jun 10th, 2012  |  syntax: VisualBasic  |  size: 2.65 KB  |  hits: 23  |  expires: Never
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
1. Sub Metoda_Thomasa()
2.
3. ' deklaracja tablic --------------------------------------------------------------------------------------------
4.
5. Dim a() As Double
6. Dim b() As Double
7. Dim c() As Double
8. Dim d() As Double
9. Dim wB() As Double
10. Dim wG() As Double
11. Dim wX() As Double
12. Dim N As Double
13.
14. ' pobranie rozmiaru tablic N InputBox---------------------------------------------------------------------------
15.
16. N = InputBox(prompt, "Podaj liczbe niewiadomch")
17.
18. ' ustalenie rozmiaru tablic ------------------------------------------------------------------------------------
19.
20. ReDim a(1 To N) As Double
21. ReDim b(1 To N) As Double
22. ReDim c(1 To N) As Double
23. ReDim d(1 To N) As Double
24. ReDim wB(1 To N) As Double
25. ReDim wG(1 To N) As Double
26. ReDim wX(1 To N, 1 To 2) As Double
27.
28. ' wczytanie wspolczynnikow--------------------------------------------------------------------------------------
29.
30. Dim i As Integer
31. For i = 1 To N
32.     If i <> 1 Then a(i) = InputBox(prompt, "podaj wspolczynnik a" & i)
33.     b(i) = InputBox(prompt, "podaj wspolczynnik b" & i)
34.     If i <> N Then c(i) = InputBox(prompt, "podaj wspolczynnik c" & i)
35.     d(i) = InputBox(prompt, "podaj wspolczynnik d" & i)
36. Next i
37.
38. a(1) = 0
39. c(N) = 0
40.
41. 'sprawdzenie
42. 'Dim k As Integer
43. 'k = 1
44. 'For i = 1 To N
45. '   Cells(i, k) = a(i)
46. '   Cells(i, k + 1) = b(i)
47. '   Cells(i, k + 2) = c(i)
48. '   Cells(i, N + 4) = d(i)
49. '   k = k + 1
50. 'Next i
51.
52. ' wyliczenie wB(1), wG(1)---------------------------------------------------------------------------------------
53.
54. wB(1) = -1 * (c(1) / b(1))
55. wG(1) = d(1) / b(1)
56.
57. ' wyliczenie wB(i), wG(i)---------------------------------------------------------------------------------------
58.
59. For i = 2 To N
60.    wB(i) = -c(i) / (a(i) * wB(i - 1) + b(i))
61. Next i
62.
63. For i = 2 To N
64.    wG(i) = (d(i) - a(i) * wG(i - 1)) / (a(i) * wB(i - 1) + b(i))
65. Next i
66.
67. ' podstawienie wX(N)=wG(N), wyliczenie pozostałych wartości wX(i)-----------------------------------------------
68.
69. wX(N, 1) = wG(N)
70.
71. For i = N - 1 To 1 Step -1
72.    wX(i, 1) = wX(i + 1, 1) * wB(i) + wG(i)
73. Next i
74.
75. 'sprwdzenie
76. 'k = 1
77. 'For i = 1 To N
78. '   Cells(i, N + 6) = wB(i)
79. '   Cells(i, N + 7) = wG(i)
80. '   Cells(i, N + 8) = wX(i, 1)
81. 'Next i
82.
83. ' wypisanie wynikow---------------------------------------------------------------------------------------------
84.
85. For i = 1 To N
86.     Cells(1, i) = "X" & i
87.     Cells(2, i) = wX(i, 1)
88. Next i
89.
90. ' --------------------------------------------------------------------------------------------------------------
91.