-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path470driver.f
337 lines (273 loc) · 6.81 KB
/
470driver.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
program main
c***********************************************************************
c
cc TOMS470_PRB tests FAKUB.
c
c Modified:
c
c 15 January 2006
c
c Author:
c
c John Burkardt
c
implicit none
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TOMS470_PRB'
write ( *, '(a)' ) ' Test TOMS algorithm 470, for solving'
write ( *, '(a)' ) ' an "almost tridiagonal" linear system.'
call test01
call test02
call test03
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TOMS470_PRB'
write ( *, '(a)' ) ' Normal end of execution.'
write ( *, '(a)' ) ' '
stop
end
subroutine test01
c***********************************************************************
c
cc TEST01 tests FAKUB.
c
c Discussion:
c
c Here, we just give a simple tridiagonal system.
c
c Our linear system is:
c
c ( 4 -1 0 0 0 ) (1) ( 2)
c (-1 4 -1 0 0 ) (2) ( 4)
c ( 0 -1 4 -1 0 ) * (3) = ( 6)
c ( 0 0 -1 4 -1 ) (4) ( 8)
c ( 0 0 0 -1 4 ) (5) (16)
c
c Modified:
c
c 15 January 2006
c
c Author:
c
c John Burkardt
c
implicit none
integer m
integer mm
integer n
integer nn
parameter ( m = 1 )
parameter ( n = 5 )
parameter ( mm = m )
parameter ( nn = n )
real alfa
real b(nn,mm)
real d(n)
real eps
real h(n)
integer i
integer jprom(1)
real s(n)
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TEST01'
write ( *, '(a)' ) ' Test FAKUB, a linear system solver'
write ( *, '(a)' ) ' for "almost tridiagonal" systems.'
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Actually, try a true tridiagonal system.'
s(1) = 0.0E+00
do i = 2, n
s(i) = -1.0E+00
end do
do i = 1, n
d(i) = 4.0E+00
end do
do i = 1, n-1
h(i) = -1.0E+00
end do
h(n) = 0.0E+00
do i = 1, n
b(i,1) = 2.0E+00 * i
end do
b(n,1) = b(n,1) + n + 1
alfa = 0.25E+00
eps = 0.000001E+00
write ( *, '(a)' ) ' '
write ( *, '(a,i6)' ) ' Number of equations, N = ', n
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Tridiagonal elements:'
write ( *, '(a)' ) ' '
do i = 1, n
write ( *, * ) s(i), d(i), h(i)
end do
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Right hand side of linear system:'
write ( *, '(a)' ) ' '
do i = 1, n
write ( *, * ) b(i,1)
end do
call fakub ( n, s, d, h, b, m, nn, mm, jprom, alfa, eps )
if ( m .le. 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a,i6)' ) ' M = ', m
write ( *, '(a)' ) ' '
end if
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Solution, which should be (1,2,3,...,n):'
write ( *, '(a)' ) ' '
do i = 1, n
write ( *, * ) b(i,1)
end do
return
end
subroutine test02
c***********************************************************************
c
cc TEST02 tests FAKUB.
c
c Discussion:
c
c Here we give an "almost tridiagonal" system.
c
c Our linear system is:
c
c ( 4 -1 0 0 -1 ) (1) (-3)
c (-1 4 -1 0 0 ) (2) ( 4)
c ( 0 -1 4 -1 0 ) * (3) = ( 6)
c ( 0 0 -1 4 -1 ) (4) ( 8)
c (-1 0 0 -1 4 ) (5) (15)
c
c Modified:
c
c 15 January 2006
c
c Author:
c
c John Burkardt
c
implicit none
integer m
integer mm
integer n
integer nn
parameter ( m = 3 )
parameter ( n = 5 )
parameter ( mm = m )
parameter ( nn = n )
real alfa
real b(nn,mm)
real d(n)
real eps
real h(n)
integer i
integer j
integer jprom(m-1)
real s(n)
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TEST02'
write ( *, '(a)' ) ' Test FAKUB, a linear system solver'
write ( *, '(a)' ) ' for "almost tridiagonal" systems.'
s(1) = 0.0E+00
do i = 2, n
s(i) = -1.0E+00
end do
do i = 1, n
d(i) = 4.0E+00
end do
do i = 1, n-1
h(i) = -1.0E+00
end do
h(n) = 0.0E+00
do i = 1, n
b(i,1) = 2.0E+00 * i
end do
b(1,1) = b(1,1) - n
b(n,1) = b(n,1) + n
do i = 1, n
do j = 2, m
b(i,j) = 0.0E+00
end do
end do
b(1,2) = -1.0E+00
b(n,3) = -1.0E+00
jprom(1) = n
jprom(2) = 1
alfa = 0.25E+00
eps = 0.000001E+00
write ( *, '(a)' ) ' '
write ( *, '(a,i6)' ) ' Number of equations, N = ', n
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Tridiagonal elements:'
write ( *, '(a)' ) ' '
do i = 1, n
write ( *, * ) s(i), d(i), h(i)
end do
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Indices of unknowns with nonzero'
write ( *, '(a)' ) ' non-tridiagonal coefficients.'
write ( *, '(a)' ) ' '
do j = 1, m-1
write ( *, * ) jprom(j)
end do
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Right hand side of linear system:'
write ( *, '(a)' ) ' '
do i = 1, n
write ( *, * ) b(i,1)
end do
call fakub ( n, s, d, h, b, m, nn, mm, jprom, alfa, eps )
if ( m .le. 0 ) then
write ( *, '(a)' ) ' '
write ( *, '(a,i6)' ) ' M = ', m
write ( *, '(a)' ) ' '
end if
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Solution, which should be (1,2,3,...,n):'
write ( *, '(a)' ) ' '
do i = 1, n
write ( *, * ) b(i,1)
end do
return
end
subroutine test03
c***********************************************************************
c
cc TEST03 tests GAUSD.
c
implicit none
integer n
integer nn
parameter ( n = 5 )
parameter ( nn = n )
real a(nn,nn)
real b(nn)
integer i
integer j
integer m
real x(nn)
save a
data a /
& 10.0E+00, 1.0E+00, 2.0E+00, 3.0E+00, 4.0E+00,
& 1.0E+00, 10.0E+00, 2.0E+00, 3.0E+00, 4.0E+00,
& 1.0E+00, 2.0E+00, 10.0E+00, 3.0E+00, 4.0E+00,
& 1.0E+00, 2.0E+00, 3.0E+00, 10.0E+00, 4.0E+00,
& 1.0E+00, 2.0E+00, 3.0E+00, 4.0E+00, 10.0E+00 /
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TEST03'
write ( *, '(a)' ) ' Test GAUSD, a linear system solver.'
do i = 1, n
x(i) = i
end do
do i = 1, n
b(i) = 0.0E+00
do j = 1, n
b(i) = b(i) + a(i,j) * x(j)
end do
end do
call gausd ( n, a, b, m, nn )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' Solution, which should be (1,2,3,...,n):'
write ( *, '(a)' ) ' '
do i = 1, n
write ( *, * ) b(i)
end do
return
end