-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbarycentric_interp_1d_prb.f90
305 lines (272 loc) · 7.1 KB
/
barycentric_interp_1d_prb.f90
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
program main
!*****************************************************************************80
!
!! BARYCENTRIC_INTERP_1D_TEST tests BARYCENTRIC_INTERP_1D.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 17 September 2012
!
! Author:
!
! John Burkardt
!
implicit none
integer ( kind = 4 ), parameter :: nd_test_num = 6
integer ( kind = 4 ) i
integer ( kind = 4 ) nd
integer ( kind = 4 ), dimension ( nd_test_num ) :: nd_test = (/ &
4, 8, 16, 32, 64, 1000 /)
integer ( kind = 4 ) prob
integer ( kind = 4 ) prob_num
call timestamp ( )
write ( *, '(a)' ) ''
write ( *, '(a)' ) 'BARYCENTRIC_INTERP_1D_TEST:'
write ( *, '(a)' ) ' FORTRAN90 version'
write ( *, '(a)' ) ' Test the BARYCENTRIC_INTERP_1D library.'
write ( *, '(a)' ) ' The R8LIB library is needed.'
write ( *, '(a)' ) ' The tests need the TEST_INTERP_1D library.'
call p00_prob_num ( prob_num )
do prob = 1, prob_num
do i = 1, nd_test_num
nd = nd_test(i)
call test01 ( prob, nd )
end do
end do
do prob = 1, prob_num
do i = 1, nd_test_num
nd = nd_test(i)
call test02 ( prob, nd )
end do
end do
do prob = 1, prob_num
do i = 1, nd_test_num
nd = nd_test(i)
call test03 ( prob, nd )
end do
end do
!
! Terminate.
!
write ( *, '(a)' ) ''
write ( *, '(a)' ) 'BARYCENTRIC_INTERP_1D_TEST:'
write ( *, '(a)' ) ' Normal end of execution.'
write ( *, '(a)' ) ''
call timestamp ( )
return
end
subroutine test01 ( prob, nd )
!*****************************************************************************80
!
!! BARYCENTRIC_INTERP_1D_TEST01 tests LAGCHEBY1_INTERP_1D.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 17 September 2012
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) PROB, the problem index.
!
! Input, integer ( kind = 4 ) ND, the number of data points to use.
!
implicit none
real ( kind = 8 ) a
real ( kind = 8 ) b
real ( kind = 8 ) int_error
integer ( kind = 4 ) nd
integer ( kind = 4 ) ni
integer ( kind = 4 ) prob
real ( kind = 8 ) r8vec_norm_affine
real ( kind = 8 ), allocatable :: xd(:)
real ( kind = 8 ), allocatable :: xi(:)
real ( kind = 8 ), allocatable :: yd(:)
real ( kind = 8 ), allocatable :: yi(:)
write ( *, '(a)' ) ''
write ( *, '(a)' ) 'BARYCENTRIC_INTERP_1D_TEST01:'
write ( *, '(a,i6)' ) ' Interpolate data from TEST_INTERP_1D problem #', prob
write ( *, '(a)' ) ' Use Chebyshev Type 1 spacing for data points.'
write ( *, '(a,i6)' ) ' Number of data points = ', nd
!
! Define the data.
!
a = 0.0D+00
b = +1.0D+00
allocate ( xd(1:nd) )
allocate ( yd(1:nd) )
call r8vec_cheby1space ( nd, a, b, xd )
call p00_f ( prob, nd, xd, yd )
if ( nd < 10 ) then
call r8vec2_print ( nd, xd, yd, ' Data array:' )
end if
!
! #1: Does the interpolant match the function at the interpolation points?
!
ni = nd
allocate ( xi(1:ni) )
allocate ( yi(1:ni) )
xi(1:ni) = xd(1:ni)
call lagcheby1_interp_1d ( nd, xd, yd, ni, xi, yi )
int_error = r8vec_norm_affine ( ni, yi, yd ) / real ( ni, kind = 8 )
write ( *, '(a)' ) ''
write ( *, '(a,g14.6)' ) &
' L2 interpolation error averaged per interpolant node = ', int_error
deallocate ( xd )
deallocate ( xi )
deallocate ( yd )
deallocate ( yi )
return
end
subroutine test02 ( prob, nd )
!*****************************************************************************80
!
!! BARYCENTRIC_INTERP_1D_TEST02 tests LAGCHEBY2_INTERP_1D.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 17 September 2012
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) PROB, the problem index.
!
! Input, integer ( kind = 4 ) ND, the number of data points to use.
!
implicit none
real ( kind = 8 ) a
real ( kind = 8 ) b
real ( kind = 8 ) int_error
integer ( kind = 4 ) nd
integer ( kind = 4 ) ni
integer ( kind = 4 ) prob
real ( kind = 8 ) r8vec_norm_affine
real ( kind = 8 ), allocatable :: xd(:)
real ( kind = 8 ), allocatable :: xi(:)
real ( kind = 8 ), allocatable :: yd(:)
real ( kind = 8 ), allocatable :: yi(:)
write ( *, '(a)' ) ''
write ( *, '(a)' ) 'BARYCENTRIC_INTERP_1D_TEST02:'
write ( *, '(a,i6)' ) ' Interpolate data from TEST_INTERP_1D problem #', prob
write ( *, '(a)' ) ' Use Chebyshev Type 2 spacing for data points.'
write ( *, '(a,i6)' ) ' Number of data points = ', nd
!
! Define the data.
!
a = 0.0D+00
b = +1.0D+00
allocate ( xd(1:nd) )
allocate ( yd(1:nd) )
call r8vec_cheby2space ( nd, a, b, xd )
call p00_f ( prob, nd, xd, yd )
if ( nd < 10 ) then
call r8vec2_print ( nd, xd, yd, ' Data array:' )
end if
!
! #1: Does the interpolant match the function at the interpolation points?
!
ni = nd
allocate ( xi(1:ni) )
allocate ( yi(1:ni) )
xi(1:ni) = xd(1:ni)
call lagcheby2_interp_1d ( nd, xd, yd, ni, xi, yi )
int_error = r8vec_norm_affine ( ni, yi, yd ) / real ( ni, kind = 8 )
write ( *, '(a)' ) ''
write ( *, '(a,g14.6)' ) &
' L2 interpolation error averaged per interpolant node = ', int_error
deallocate ( xd )
deallocate ( xi )
deallocate ( yd )
deallocate ( yi )
return
end
subroutine test03 ( prob, nd )
!*****************************************************************************80
!
!! BARYCENTRIC_INTERP_1D_TEST03 tests LAGEVEN_INTERP_1D.
!
! Licensing:
!
! This code is distributed under the GNU LGPL license.
!
! Modified:
!
! 17 September 2012
!
! Author:
!
! John Burkardt
!
! Parameters:
!
! Input, integer ( kind = 4 ) PROB, the problem index.
!
! Input, integer ( kind = 4 ) ND, the number of data points to use.
!
implicit none
real ( kind = 8 ) a
real ( kind = 8 ) b
integer ( kind = 4 ) i
real ( kind = 8 ) int_error
integer ( kind = 4 ) nd
integer ( kind = 4 ) ni
integer ( kind = 4 ) prob
real ( kind = 8 ) r8vec_norm_affine
real ( kind = 8 ), allocatable :: xd(:)
real ( kind = 8 ), allocatable :: xi(:)
real ( kind = 8 ), allocatable :: yd(:)
real ( kind = 8 ), allocatable :: yi(:)
write ( *, '(a)' ) ''
write ( *, '(a)' ) 'BARYCENTRIC_INTERP_1D_TEST03:'
write ( *, '(a,i6)' ) ' Interpolate data from TEST_INTERP_1D problem #', prob
write ( *, '(a)' ) ' Use even spacing for data points.'
write ( *, '(a,i6)' ) ' Number of data points = ', nd
!
! Define the data.
!
a = 0.0D+00
b = +1.0D+00
allocate ( xd(1:nd) )
allocate ( yd(1:nd) )
call r8vec_midspace ( nd, a, b, xd )
call p00_f ( prob, nd, xd, yd )
if ( nd < 10 ) then
call r8vec2_print ( nd, xd, yd, ' Data array:' )
end if
!
! #1: Does the interpolant match the function at the interpolation points?
!
ni = nd
allocate ( xi(1:ni) )
allocate ( yi(1:ni) )
xi(1:ni) = xd(1:ni)
call lageven_interp_1d ( nd, xd, yd, ni, xi, yi )
int_error = r8vec_norm_affine ( ni, yi, yd ) / real ( ni, kind = 8 )
write ( *, '(a)' ) ''
write ( *, '(a,g14.6)' ) &
' L2 interpolation error averaged per interpolant node = ', int_error
deallocate ( xd )
deallocate ( xi )
deallocate ( yd )
deallocate ( yi )
return
end