File: interp.texi

package info (click to toggle)
gsl-doc 2.3-1
  • links: PTS
  • area: non-free
  • in suites: buster
  • size: 27,748 kB
  • ctags: 15,177
  • sloc: ansic: 235,014; sh: 11,585; makefile: 925
file content (653 lines) | stat: -rw-r--r-- 31,694 bytes parent folder | download
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
@cindex interpolation
@cindex spline

This chapter describes functions for performing interpolation.  The
library provides a variety of interpolation methods, including Cubic,
Akima, and Steffen splines.  The interpolation types are interchangeable,
allowing different methods to be used without recompiling.
Interpolations can be defined for both normal and periodic boundary
conditions.  Additional functions are available for computing
derivatives and integrals of interpolating functions. Routines
are provided for interpolating both one and two dimensional datasets.

These interpolation methods produce curves that pass through each
datapoint.  To interpolate noisy data with a smoothing curve see
@ref{Basis Splines}.

The functions described in this section are declared in the header files
@file{gsl_interp.h} and @file{gsl_spline.h}.

@menu
* 1D Introduction to Interpolation::  
* 1D Interpolation Functions::     
* 1D Interpolation Types::         
* 1D Index Look-up and Acceleration::  
* 1D Evaluation of Interpolating Functions::  
* 1D Higher-level Interface::      
* 1D Interpolation Example programs::  
* 1D Interpolation References and Further Reading::  
* 2D Introduction to Interpolation::  
* 2D Interpolation Functions::     
* 2D Interpolation Grids::     
* 2D Interpolation Types::         
* 2D Evaluation of Interpolating Functions::  
* 2D Higher-level Interface::      
* 2D Interpolation Example programs::  
@end menu

@node 1D Introduction to Interpolation
@section Introduction to 1D Interpolation

Given a set of data points @math{(x_1, y_1) \dots (x_n, y_n)} the
routines described in this section compute a continuous interpolating
function @math{y(x)} such that @math{y(x_i) = y_i}.  The interpolation
is piecewise smooth, and its behavior at the end-points is determined by
the type of interpolation used.

@node 1D Interpolation Functions
@section 1D Interpolation Functions

The interpolation function for a given dataset is stored in a
@code{gsl_interp} object.  These are created by the following functions.

@deftypefun {gsl_interp *} gsl_interp_alloc (const gsl_interp_type * @var{T}, size_t @var{size})
@tindex gsl_interp
This function returns a pointer to a newly allocated interpolation
object of type @var{T} for @var{size} data-points.
@end deftypefun

@deftypefun int gsl_interp_init (gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], size_t @var{size})
This function initializes the interpolation object @var{interp} for the
data (@var{xa},@var{ya}) where @var{xa} and @var{ya} are arrays of size
@var{size}.  The interpolation object (@code{gsl_interp}) does not save
the data arrays @var{xa} and @var{ya} and only stores the static state
computed from the data.  The @var{xa} data array is always assumed to be
strictly ordered, with increasing @math{x} values; 
the behavior for other arrangements is not defined.
@end deftypefun

@deftypefun void gsl_interp_free (gsl_interp * @var{interp})
This function frees the interpolation object @var{interp}.
@end deftypefun

@node 1D Interpolation Types
@section 1D Interpolation Types
@tindex gsl_interp_type
The interpolation library provides the following interpolation types:

@deffn {Interpolation Type} gsl_interp_linear
@cindex linear interpolation
Linear interpolation.  This interpolation method does not require any
additional memory.
@end deffn

@deffn {Interpolation Type} gsl_interp_polynomial
@cindex polynomial interpolation
Polynomial interpolation.  This method should only be used for
interpolating small numbers of points because polynomial interpolation
introduces large oscillations, even for well-behaved datasets.  The
number of terms in the interpolating polynomial is equal to the number
of points.
@end deffn

@deffn {Interpolation Type} gsl_interp_cspline
@cindex cubic splines
Cubic spline with natural boundary conditions.  The resulting curve is
piecewise cubic on each interval, with matching first and second
derivatives at the supplied data-points.  The second derivative is
chosen to be zero at the first point and last point.
@end deffn

@deffn {Interpolation Type} gsl_interp_cspline_periodic
Cubic spline with periodic boundary conditions.  The resulting curve
is piecewise cubic on each interval, with matching first and second
derivatives at the supplied data-points.  The derivatives at the first
and last points are also matched.  Note that the last point in the
data must have the same y-value as the first point, otherwise the
resulting periodic interpolation will have a discontinuity at the
boundary.

@end deffn

@deffn {Interpolation Type} gsl_interp_akima
@cindex Akima splines
Non-rounded Akima spline with natural boundary conditions.  This method
uses the non-rounded corner algorithm of Wodicka.
@end deffn

@deffn {Interpolation Type} gsl_interp_akima_periodic
Non-rounded Akima spline with periodic boundary conditions.  This method
uses the non-rounded corner algorithm of Wodicka.
@end deffn

@deffn {Interpolation Type} gsl_interp_steffen
Steffen's method guarantees the monotonicity of the interpolating function
between the given data points. Therefore, minima and maxima can only occur
exactly at the data points, and there can never be spurious oscillations
between data points. The interpolated function is piecewise cubic
in each interval. The resulting curve and its first derivative
are guaranteed to be continuous, but the second derivative may be
discontinuous.
@end deffn

@noindent
The following related functions are available:

@deftypefun {const char *} gsl_interp_name (const gsl_interp * @var{interp})
This function returns the name of the interpolation type used by @var{interp}.
For example,

@example
printf ("interp uses '%s' interpolation.\n", 
        gsl_interp_name (interp));
@end example

@noindent
would print something like,

@example
interp uses 'cspline' interpolation.
@end example
@end deftypefun

@deftypefun {unsigned int} gsl_interp_min_size (const gsl_interp * @var{interp})
@deftypefunx {unsigned int} gsl_interp_type_min_size (const gsl_interp_type * @var{T})
These functions return the minimum number of points required by the
interpolation object @var{interp} or interpolation type @var{T}.  For
example, Akima spline interpolation requires a minimum of 5 points.
@end deftypefun



@node 1D Index Look-up and Acceleration
@section 1D Index Look-up and Acceleration

The state of searches can be stored in a @code{gsl_interp_accel} object,
which is a kind of iterator for interpolation lookups.  It caches the
previous value of an index lookup.  When the subsequent interpolation
point falls in the same interval its index value can be returned
immediately.

@deftypefun size_t gsl_interp_bsearch (const double @var{x_array}[], double @var{x}, size_t @var{index_lo}, size_t @var{index_hi})
This function returns the index @math{i} of the array @var{x_array} such
that @code{x_array[i] <= x < x_array[i+1]}.  The index is searched for
in the range [@var{index_lo},@var{index_hi}].  @inlinefn{}
@end deftypefun

@deftypefun {gsl_interp_accel *} gsl_interp_accel_alloc (void)
@tindex gsl_interp_accel
This function returns a pointer to an accelerator object, which is a
kind of iterator for interpolation lookups.  It tracks the state of
lookups, thus allowing for application of various acceleration
strategies.
@end deftypefun

@deftypefun size_t gsl_interp_accel_find (gsl_interp_accel * @var{a}, const double @var{x_array}[], size_t @var{size}, double @var{x})
This function performs a lookup action on the data array @var{x_array}
of size @var{size}, using the given accelerator @var{a}.  This is how
lookups are performed during evaluation of an interpolation.  The
function returns an index @math{i} such that @code{x_array[i] <= x <
x_array[i+1]}.  @inlinefn{}
@end deftypefun

@deftypefun int gsl_interp_accel_reset (gsl_interp_accel * @var{acc});
This function reinitializes the accelerator object @var{acc}.  It
should be used when the cached information is no longer
applicable---for example, when switching to a new dataset.
@end deftypefun

@deftypefun void gsl_interp_accel_free (gsl_interp_accel* @var{acc})
This function frees the accelerator object @var{acc}.
@end deftypefun

@node 1D Evaluation of Interpolating Functions
@section 1D Evaluation of Interpolating Functions

@deftypefun  double gsl_interp_eval (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{x}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_interp_eval_e (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{x}, gsl_interp_accel * @var{acc}, double * @var{y})
These functions return the interpolated value of @var{y} for a given
point @var{x}, using the interpolation object @var{interp}, data
arrays @var{xa} and @var{ya} and the accelerator @var{acc}.  When
@var{x} is outside the range of @var{xa}, the error code
@code{GSL_EDOM} is returned with a value of @code{GSL_NAN} for
@var{y}.
@end deftypefun

@deftypefun double gsl_interp_eval_deriv (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{x}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_interp_eval_deriv_e (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{x}, gsl_interp_accel * @var{acc}, double * @var{d})
These functions return the derivative @var{d} of an interpolated
function for a given point @var{x}, using the interpolation object
@var{interp}, data arrays @var{xa} and @var{ya} and the accelerator
@var{acc}. 
@end deftypefun

@deftypefun double gsl_interp_eval_deriv2 (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{x}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_interp_eval_deriv2_e (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{x}, gsl_interp_accel * @var{acc}, double * @var{d2})
These functions return the second derivative @var{d2} of an interpolated
function for a given point @var{x}, using the interpolation object
@var{interp}, data arrays @var{xa} and @var{ya} and the accelerator
@var{acc}. 
@end deftypefun

@deftypefun double gsl_interp_eval_integ (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{a}, double @var{b}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_interp_eval_integ_e (const gsl_interp * @var{interp}, const double @var{xa}[], const double @var{ya}[], double @var{a}, double @var{b}, gsl_interp_accel * @var{acc}, double * @var{result})
These functions return the numerical integral @var{result} of an
interpolated function over the range [@var{a}, @var{b}], using the
interpolation object @var{interp}, data arrays @var{xa} and @var{ya} and
the accelerator @var{acc}.
@end deftypefun

@node 1D Higher-level Interface
@section 1D Higher-level Interface

The functions described in the previous sections required the user to
supply pointers to the @math{x} and @math{y} arrays on each call.  The
following functions are equivalent to the corresponding
@code{gsl_interp} functions but maintain a copy of this data in the
@code{gsl_spline} object.  This removes the need to pass both @var{xa}
and @var{ya} as arguments on each evaluation. These functions are
defined in the header file @file{gsl_spline.h}.

@deftypefun {gsl_spline *} gsl_spline_alloc (const gsl_interp_type * @var{T}, size_t @var{size})
@tindex gsl_spline
@end deftypefun

@deftypefun int gsl_spline_init (gsl_spline * @var{spline}, const double @var{xa}[], const double @var{ya}[], size_t @var{size})
@end deftypefun

@deftypefun void gsl_spline_free (gsl_spline * @var{spline})
@end deftypefun

@deftypefun {const char *} gsl_spline_name (const gsl_spline * @var{spline})
@end deftypefun

@deftypefun {unsigned int} gsl_spline_min_size (const gsl_spline * @var{spline})
@end deftypefun

@deftypefun double gsl_spline_eval (const gsl_spline * @var{spline}, double @var{x}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_spline_eval_e (const gsl_spline * @var{spline}, double @var{x}, gsl_interp_accel * @var{acc}, double * @var{y})
@end deftypefun

@deftypefun double gsl_spline_eval_deriv (const gsl_spline * @var{spline}, double @var{x}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_spline_eval_deriv_e (const gsl_spline * @var{spline}, double @var{x}, gsl_interp_accel * @var{acc}, double * @var{d})
@end deftypefun

@deftypefun double gsl_spline_eval_deriv2 (const gsl_spline * @var{spline}, double @var{x}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_spline_eval_deriv2_e (const gsl_spline * @var{spline}, double @var{x}, gsl_interp_accel * @var{acc}, double * @var{d2})
@end deftypefun

@deftypefun double gsl_spline_eval_integ (const gsl_spline * @var{spline}, double @var{a}, double @var{b}, gsl_interp_accel * @var{acc})
@deftypefunx int gsl_spline_eval_integ_e (const gsl_spline * @var{spline}, double @var{a}, double @var{b}, gsl_interp_accel * @var{acc}, double * @var{result})
@end deftypefun

@node 1D Interpolation Example programs
@section Examples of 1D Interpolation

The following program demonstrates the use of the interpolation and
spline functions.  It computes a cubic spline interpolation of the
10-point dataset @math{(x_i, y_i)} where @math{x_i = i + \sin(i)/2} and
@math{y_i = i + \cos(i^2)} for @math{i = 0 \dots 9}.

@example
@verbatiminclude examples/interp.c
@end example

@noindent
The output is designed to be used with the @sc{gnu} plotutils
@code{graph} program,

@example
$ ./a.out > interp.dat
$ graph -T ps < interp.dat > interp.ps
@end example

@iftex
@sp 1
@center @image{interp2,3.4in}
@end iftex

@noindent
The result shows a smooth interpolation of the original points.  The
interpolation method can be changed simply by varying the first argument of
@code{gsl_spline_alloc}.

The next program demonstrates a periodic cubic spline with 4 data
points.  Note that the first and last points must be supplied with 
the same y-value for a periodic spline.

@example
@verbatiminclude examples/interpp.c
@end example

@noindent

The output can be plotted with @sc{gnu} @code{graph}.

@example
$ ./a.out > interp.dat
$ graph -T ps < interp.dat > interp.ps
@end example

@iftex
@sp 1
@center @image{interpp2,3.4in}
@end iftex

@noindent
The result shows a periodic interpolation of the original points. The
slope of the fitted curve is the same at the beginning and end of the
data, and the second derivative is also.

The next program illustrates the difference between the cubic spline,
Akima, and Steffen interpolation types on a difficult dataset.

@example
@verbatiminclude examples/interp_compare.c
@end example

@iftex
@sp 1
@center @image{interp_compare,6in}
@end iftex

@noindent
The cubic method exhibits a local maxima between the 6th and 7th data points
and continues oscillating for the rest of the data. Akima also shows a
local maxima but recovers and follows the data well after the 7th grid point.
Steffen preserves monotonicity in all intervals and does not exhibit oscillations,
at the expense of having a discontinuous second derivative.

@node 1D Interpolation References and Further Reading
@section References and Further Reading

Descriptions of the interpolation algorithms and further references can
be found in the following publications:

@itemize @w{}
@item C.W. Ueberhuber,
@cite{Numerical Computation (Volume 1), Chapter 9 ``Interpolation''},
Springer (1997), ISBN 3-540-62058-3.

@item D.M. Young, R.T. Gregory,
@cite{A Survey of Numerical Mathematics (Volume 1), Chapter 6.8},
Dover (1988), ISBN 0-486-65691-8.

@item M. Steffen,
@cite{A simple method for monotonic interpolation in one dimension},
Astron. Astrophys. 239, 443-450, 1990.
@end itemize

@node 2D Introduction to Interpolation
@section Introduction to 2D Interpolation

Given a set of @math{x} coordinates @math{x_1,...,x_m} and a set of
@math{y} coordinates @math{y_1,...,y_n}, each in increasing order,
plus a set of function values @math{z_{ij}}
for each grid point @math{(x_i,y_j)}, the routines described in this
section compute a continuous interpolation function @math{z(x,y)} such
that @math{z(x_i,y_j) = z_{ij}}.

@node 2D Interpolation Functions
@section 2D Interpolation Functions

The interpolation function for a given dataset is stored in a
@code{gsl_interp2d} object. These are created by the following functions.

@deftypefun {gsl_interp2d *} gsl_interp2d_alloc (const gsl_interp2d_type * @var{T}, const size_t @var{xsize}, const size_t @var{ysize})
@tindex gsl_interp
This function returns a pointer to a newly allocated interpolation
object of type @var{T} for @var{xsize} grid points in the @math{x}
direction and @var{ysize} grid points in the @math{y} direction.
@end deftypefun

@deftypefun int gsl_interp2d_init (gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const size_t @var{xsize}, const size_t @var{ysize})
This function initializes the interpolation object @var{interp} for the
data (@var{xa},@var{ya},@var{za}) where @var{xa} and @var{ya} are arrays of
the @math{x} and @math{y} grid points of size @var{xsize} and @var{ysize}
respectively, and @var{za} is an array of function values of size
@var{xsize}*@var{ysize}.  The interpolation object (@code{gsl_interp2d}) does
not save the data arrays @var{xa}, @var{ya}, and @var{za} and only stores the
static state computed from the data. The @var{xa} and @var{ya} data arrays
are always assumed to be strictly ordered, with increasing @math{x,y} values; 
the behavior for other arrangements is not defined.
@end deftypefun

@deftypefun void gsl_interp2d_free (gsl_interp2d * @var{interp})
This function frees the interpolation object @var{interp}.
@end deftypefun

@node 2D Interpolation Grids
@section 2D Interpolation Grids

The 2D interpolation routines access the function values @math{z_{ij}}
with the following ordering:
@tex
\beforedisplay
$$
z_{ij} = za[j*xsize + i]
$$
\afterdisplay
@end tex
@ifinfo

@example
z_ij = za[j*xsize + i]
@end example

@end ifinfo
with @math{i = 0,...,xsize-1} and @math{j = 0,...,ysize-1}. However,
for ease of use, the following functions are provided to add and retrieve
elements from the function grid without requiring knowledge of the
internal ordering.

@deftypefun int gsl_interp2d_set (const gsl_interp2d * @var{interp}, double @var{za}[], const size_t @var{i}, const size_t @var{j}, const double @var{z})
This function sets the value @math{z_{ij}} for grid point
(@var{i},@var{j}) of the array @var{za} to @var{z}.
@end deftypefun

@deftypefun double gsl_interp2d_get (const gsl_interp2d * @var{interp}, const double @var{za}[], const size_t @var{i}, const size_t @var{j})
This function returns the value @math{z_{ij}} for grid point
(@var{i},@var{j}) stored in the array @var{za}.
@end deftypefun

@deftypefun size_t gsl_interp2d_idx (const gsl_interp2d * @var{interp}, const size_t @var{i}, const size_t @var{j})
This function returns the index corresponding to the grid point
(@var{i},@var{j}). The index is given by @math{j*xsize + i}.
@end deftypefun

@node 2D Interpolation Types
@section 2D Interpolation Types
@tindex gsl_interp2d_type
The interpolation library provides the following 2D interpolation types:

@deffn {Interpolation Type} gsl_interp2d_bilinear
@cindex bilinear interpolation
Bilinear interpolation.  This interpolation method does not require any
additional memory.
@end deffn

@deffn {Interpolation Type} gsl_interp2d_bicubic
@cindex bicubic interpolation
Bicubic interpolation.
@end deffn

@deftypefun {const char *} gsl_interp2d_name (const gsl_interp2d * @var{interp})
This function returns the name of the interpolation type used by @var{interp}.
For example,

@example
printf ("interp uses '%s' interpolation.\n", 
        gsl_interp2d_name (interp));
@end example

@noindent
would print something like,

@example
interp uses 'bilinear' interpolation.
@end example
@end deftypefun

@deftypefun {unsigned int} gsl_interp2d_min_size (const gsl_interp2d * @var{interp})
@deftypefunx {unsigned int} gsl_interp2d_type_min_size (const gsl_interp2d_type * @var{T})
These functions return the minimum number of points required by the
interpolation object @var{interp} or interpolation type @var{T}.  For
example, bicubic interpolation requires a minimum of 4 points.
@end deftypefun

@node 2D Evaluation of Interpolating Functions
@section 2D Evaluation of Interpolating Functions

@deftypefun double gsl_interp2d_eval (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_interp2d_eval_e (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{z})
These functions return the interpolated value of @var{z} for a given
point (@var{x},@var{y}), using the interpolation object @var{interp}, data
arrays @var{xa}, @var{ya}, and @var{za} and the accelerators @var{xacc}
and @var{yacc}.  When @var{x} is outside the range of @var{xa} or @var{y}
is outside the range of @var{ya}, the error code
@code{GSL_EDOM} is returned.
@end deftypefun

@deftypefun double gsl_interp2d_eval_extrap (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_interp2d_eval_extrap_e (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{z})
These functions return the interpolated value of @var{z} for a given
point (@var{x},@var{y}), using the interpolation object @var{interp}, data
arrays @var{xa}, @var{ya}, and @var{za} and the accelerators @var{xacc}
and @var{yacc}. The functions perform no bounds checking, so
when @var{x} is outside the range of @var{xa} or @var{y}
is outside the range of @var{ya}, extrapolation is performed.
@end deftypefun

@deftypefun double gsl_interp2d_eval_deriv_x (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_interp2d_eval_deriv_x_e (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
These functions return the interpolated value @var{d}
@math{= \partial z / \partial x} for a given point (@var{x},@var{y}),
using the interpolation object @var{interp}, data
arrays @var{xa}, @var{ya}, and @var{za} and the accelerators @var{xacc}
and @var{yacc}.  When @var{x} is outside the range of @var{xa} or @var{y}
is outside the range of @var{ya}, the error code
@code{GSL_EDOM} is returned.
@end deftypefun

@deftypefun double gsl_interp2d_eval_deriv_y (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_interp2d_eval_deriv_y_e (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
These functions return the interpolated value @var{d}
@math{= \partial z / \partial y} for a given point (@var{x},@var{y}),
using the interpolation object @var{interp}, data
arrays @var{xa}, @var{ya}, and @var{za} and the accelerators @var{xacc}
and @var{yacc}.  When @var{x} is outside the range of @var{xa} or @var{y}
is outside the range of @var{ya}, the error code
@code{GSL_EDOM} is returned.
@end deftypefun

@deftypefun double gsl_interp2d_eval_deriv_xx (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_interp2d_eval_deriv_xx_e (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
These functions return the interpolated value @var{d}
@math{= \partial^2 z / \partial x^2} for a given point (@var{x},@var{y}),
using the interpolation object @var{interp}, data
arrays @var{xa}, @var{ya}, and @var{za} and the accelerators @var{xacc}
and @var{yacc}.  When @var{x} is outside the range of @var{xa} or @var{y}
is outside the range of @var{ya}, the error code
@code{GSL_EDOM} is returned.
@end deftypefun

@deftypefun double gsl_interp2d_eval_deriv_yy (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_interp2d_eval_deriv_yy_e (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
These functions return the interpolated value @var{d}
@math{= \partial^2 z / \partial y^2} for a given point (@var{x},@var{y}),
using the interpolation object @var{interp}, data
arrays @var{xa}, @var{ya}, and @var{za} and the accelerators @var{xacc}
and @var{yacc}.  When @var{x} is outside the range of @var{xa} or @var{y}
is outside the range of @var{ya}, the error code
@code{GSL_EDOM} is returned.
@end deftypefun

@deftypefun double gsl_interp2d_eval_deriv_xy (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_interp2d_eval_deriv_xy_e (const gsl_interp2d * @var{interp}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
These functions return the interpolated value @var{d}
@math{= \partial^2 z / \partial x \partial y} for a given point (@var{x},@var{y}),
using the interpolation object @var{interp}, data
arrays @var{xa}, @var{ya}, and @var{za} and the accelerators @var{xacc}
and @var{yacc}.  When @var{x} is outside the range of @var{xa} or @var{y}
is outside the range of @var{ya}, the error code
@code{GSL_EDOM} is returned.
@end deftypefun

@node 2D Higher-level Interface
@section 2D Higher-level Interface

The functions described in the previous sections required the user to
supply pointers to the @math{x}, @math{y}, and @math{z} arrays on each call.
The following functions are equivalent to the corresponding
@code{gsl_interp2d} functions but maintain a copy of this data in the
@code{gsl_spline2d} object.  This removes the need to pass @var{xa},
@var{ya}, and @var{za} as arguments on each evaluation. These functions are
defined in the header file @file{gsl_spline2d.h}.

@deftypefun {gsl_spline2d *} gsl_spline2d_alloc (const gsl_interp2d_type * @var{T}, size_t @var{xsize}, size_t @var{ysize})
@tindex gsl_spline2d
@end deftypefun

@deftypefun int gsl_spline2d_init (gsl_spline2d * @var{spline}, const double @var{xa}[], const double @var{ya}[], const double @var{za}[], size_t @var{xsize}, size_t @var{ysize})
@end deftypefun

@deftypefun void gsl_spline2d_free (gsl_spline2d * @var{spline})
@end deftypefun

@deftypefun {const char *} gsl_spline2d_name (const gsl_spline2d * @var{spline})
@end deftypefun

@deftypefun {unsigned int} gsl_spline2d_min_size (const gsl_spline2d * @var{spline})
@end deftypefun

@deftypefun double gsl_spline2d_eval (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_spline2d_eval_e (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{z})
@end deftypefun

@deftypefun double gsl_spline2d_eval_deriv_x (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_spline2d_eval_deriv_x_e (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
@end deftypefun

@deftypefun double gsl_spline2d_eval_deriv_y (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_spline2d_eval_deriv_y_e (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
@end deftypefun

@deftypefun double gsl_spline2d_eval_deriv_xx (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_spline2d_eval_deriv_xx_e (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
@end deftypefun

@deftypefun double gsl_spline2d_eval_deriv_yy (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_spline2d_eval_deriv_yy_e (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
@end deftypefun

@deftypefun double gsl_spline2d_eval_deriv_xy (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc})
@deftypefunx int gsl_spline2d_eval_deriv_xy_e (const gsl_spline2d * @var{spline}, const double @var{x}, const double @var{y}, gsl_interp_accel * @var{xacc}, gsl_interp_accel * @var{yacc}, double * @var{d})
@end deftypefun

@deftypefun int gsl_spline2d_set (const gsl_spline2d * @var{spline}, double @var{za}[], const size_t @var{i}, const size_t @var{j}, const double @var{z})
@end deftypefun

@deftypefun double gsl_spline2d_get (const gsl_spline2d * @var{spline}, const double @var{za}[], const size_t @var{i}, const size_t @var{j})
This function returns the value @math{z_{ij}} for grid point
(@var{i},@var{j}) stored in the array @var{za}.
@end deftypefun

@node 2D Interpolation Example programs
@section 2D Interpolation Example programs

The following example performs bilinear interpolation on the unit
square, using @math{z} values of @math{(0,1,0.5,1)} going clockwise
around the square.

@example
@verbatiminclude examples/interp2d.c
@end example

@noindent
The results of the interpolation are shown in the following plot,
where the corners are labeled with their fixed @math{z} values.

@iftex
@sp 1
@center @image{interp2d,6in}
@end iftex