-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path438
More file actions
359 lines (303 loc) · 7.82 KB
/
438
File metadata and controls
359 lines (303 loc) · 7.82 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
C ALGORITHM 438, COLLECTED ALGORITHMS FROM ACM.
C THIS WORK PUBLISHED IN COMMUNICATIONS OF THE ACM
C VOL. 15, NO. 6, June, 1972, P.1071.
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# Fortran/
# Fortran/Dp/
# Fortran/Dp/Drivers/
# Fortran/Dp/Drivers/Makefile
# Fortran/Dp/Drivers/driver.f
# Fortran/Dp/Drivers/res
# Fortran/Dp/Src/
# Fortran/Dp/Src/src.f
# This archive created: Thu Dec 15 13:28:17 2005
export PATH; PATH=/bin:$PATH
if test ! -d 'Fortran'
then
mkdir 'Fortran'
fi
cd 'Fortran'
if test ! -d 'Dp'
then
mkdir 'Dp'
fi
cd 'Dp'
if test ! -d 'Drivers'
then
mkdir 'Drivers'
fi
cd 'Drivers'
if test -f 'Makefile'
then
echo shar: will not over-write existing file "'Makefile'"
else
cat << "SHAR_EOF" > 'Makefile'
all: Res
src.o: src.f
$(F77) $(F77OPTS) -c src.f
driver.o: driver.f
$(F77) $(F77OPTS) -c driver.f
DRIVERS= driver
RESULTS= Res
Objs1= driver.o src.o
driver: $(Objs1)
$(F77) $(F77OPTS) -o driver $(Objs1) $(SRCLIBS)
Res: driver
./driver >Res
diffres:Res res
echo "Differences in results from driver"
$(DIFF) Res res
clean:
rm -rf *.o $(DRIVERS) $(CLEANUP) $(RESULTS)
SHAR_EOF
fi # end of overwriting check
if test -f 'driver.f'
then
echo shar: will not over-write existing file "'driver.f'"
else
cat << "SHAR_EOF" > 'driver.f'
program main
c***********************************************************************
c
cc TOMS438_PRB tests TOMS438.
c
implicit none
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TOMS438_PRB'
write ( *, '(a)' ) ' Test TOMS algorithm 438, product-type'
write ( *, '(a)' ) ' two point Gauss-Legendre Simpson'
write ( *, '(a)' ) ' integration.'
call test01
call test02
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TOMS438_PRB'
write ( *, '(a)' ) ' Normal end of execution.'
stop
end
subroutine test01
c***********************************************************************
c
cc TEST01 tests the rule with one factor equal to 1.
c
implicit none
double precision a
double precision b
double precision exact
double precision fn00, gn00
external fn00
external gn00
integer n
double precision vint
a = -4.0D+00
b = 4.0D+00
exact = 2.0D+00 * atan ( 4.0D+00 )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TEST01'
write ( *, '(a)' ) ' Integral of F(X) * G(X) from -1 to 1,'
write ( *, '(a)' ) ' with F(X) = 1, G(X) = 1/(1+x**2 )'
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' N VINT'
write ( *, '(a)' ) ' '
do n = 1, 10
call p2pgs ( a, b, n, fn00, gn00, vint )
write ( *, '(2x,i6,2x,g14.6)' ) n, vint
end do
write ( *, '(a)' ) ' '
write ( *, '(a,g14.6)' ) ' Exact: ', exact
return
end
subroutine test02
c***********************************************************************
c
cc TEST02 tests the rule with factors exp(-x) and cos(x).
c
implicit none
double precision a
double precision b
double precision exact
double precision gn01, gn02
external gn01
external gn02
integer n
double precision vint
a = 0.0D+00
b = 3.141592653589793D+00
exact = 0.5 * exp ( -b ) * ( sin ( b ) - cos ( b ) )
& - ( 0.5 * exp ( -a ) * ( sin ( a ) - cos ( a ) ) )
write ( *, '(a)' ) ' '
write ( *, '(a)' ) 'TEST02'
write ( *, '(a)' ) ' Integral of F(X) * G(X) from 0 to PI,'
write ( *, '(a)' ) ' with F(X) = EXP(-X), G(X) = COS(X)'
write ( *, '(a)' ) ' '
write ( *, '(a)' ) ' N VINT'
write ( *, '(a)' ) ' '
do n = 1, 10
call p2pgs ( a, b, n, gn01, gn02, vint )
write ( *, '(2x,i6,2x,g14.6)' ) n, vint
end do
write ( *, '(a)' ) ' '
write ( *, '(a,g14.6)' ) ' Exact: ', exact
return
end
function fn00 ( x )
c***********************************************************************
c
cc FN00 evaluates the function 1.
c
implicit none
double precision fn00
double precision x
fn00 = 1.0D+00
return
end
function fn01 ( x )
c***********************************************************************
c
cc FN01 evaluates the function X.
c
implicit none
double precision fn01
double precision x
fn01 = x
return
end
function gn00 ( x )
c***********************************************************************
c
cc GN00 evaluates the function 1/(1+X**2).
c
implicit none
double precision gn00
double precision x
gn00 = 1.0D+00 / ( 1.0D+00 + x * x )
return
end
function gn01 ( x )
c***********************************************************************
c
cc GN01 evaluates the function exp(-x).
c
implicit none
double precision gn01
double precision x
gn01 = exp ( - x )
return
end
function gn02 ( x )
c***********************************************************************
c
cc GN02 evaluates the function cos(x).
c
implicit none
double precision gn02
double precision x
gn02 = cos ( x )
return
end
SHAR_EOF
fi # end of overwriting check
if test -f 'res'
then
echo shar: will not over-write existing file "'res'"
else
cat << "SHAR_EOF" > 'res'
TOMS438_PRB
Test TOMS algorithm 438, product-type
two point Gauss-Legendre Simpson
integration.
TEST01
Integral of F(X) * G(X) from -1 to 1,
with F(X) = 1, G(X) = 1/(1+x**2 )
N VINT
1 5.49020
2 2.47843
3 2.90842
4 2.57255
5 2.69529
6 2.63329
7 2.66030
8 2.64773
9 2.65342
10 2.65082
Exact: 2.65164
TEST02
Integral of F(X) * G(X) from 0 to PI,
with F(X) = EXP(-X), G(X) = COS(X)
N VINT
1 0.390787
2 0.516996
3 0.520913
4 0.521413
5 0.521532
6 0.521572
7 0.521589
8 0.521596
9 0.521600
10 0.521603
Exact: 0.521607
TOMS438_PRB
Normal end of execution.
SHAR_EOF
fi # end of overwriting check
cd ..
if test ! -d 'Src'
then
mkdir 'Src'
fi
cd 'Src'
if test -f 'src.f'
then
echo shar: will not over-write existing file "'src.f'"
else
cat << "SHAR_EOF" > 'src.f'
SUBROUTINE P2PGS ( A, B, N, FN, GN, VINT )
C
C THIS SUBROUTINE USES THE PRODUCT TYPE TWO-POINT GAUSS-
C LEGENDRE-SIMPSON RULE COMPOUNDED N TIMES TO APPROXIMATE
C THE INTEGRAL FROM A TO B OF THE FUNCTION FN(X) * GN(X).
C FN AND GN ARE FUNCTION SUBPROGRAMS WHICH MUST BE SUPPLIED
C BY THE USER. THE RESULT IS STORED IN VINT.
C
INTEGER I, N, J, K
DOUBLE PRECISION A, AG, AM(2,3), B, F(2), FN, G(3),
& GN, H, VINT, X(2), Y(2)
DATA AM(1,1), AM(2,3) / 2 * 2.732050807568877D0 /,
& AM(1,2), AM(2,2) / 2 * 4.D0 /, AM(1,3), AM(2,1)
& / 2 * -.7320508075688773D0 /
H = ( B - A ) / DBLE ( FLOAT ( N ) )
X(1) = A + .2113248654051871D0 * H
X(2) = A + .7886751345948129D0 * H
Y(1) = A + H / 2.D0
Y(2) = A + H
VINT = 0.D0
G(3) = GN ( A )
DO 4 I = 1, N
G(1) = G(3)
DO 1 J = 1, 2
F(J) = FN ( X(J) )
G(J+1) = GN ( Y(J) )
X(J) = X(J) + H
Y(J) = Y(J) + H
1 CONTINUE
DO 3 J = 1, 2
AG = 0.D0
DO 2 K = 1, 3
AG = AG + AM(J,K) * G(K)
2 CONTINUE
VINT = VINT + F(J) * AG
3 CONTINUE
4 CONTINUE
VINT = H * VINT / 12.D0
RETURN
END
SHAR_EOF
fi # end of overwriting check
cd ..
cd ..
cd ..
# End of shell archive
exit 0