Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_interp_2d_scat_shep (e01sg)

## Purpose

nag_interp_2d_scat_shep (e01sg) generates a two-dimensional interpolant to a set of scattered data points, using a modified Shepard method.

## Syntax

[iq, rq, ifail] = e01sg(x, y, f, nw, nq, 'm', m)
[iq, rq, ifail] = nag_interp_2d_scat_shep(x, y, f, nw, nq, 'm', m)

## Description

nag_interp_2d_scat_shep (e01sg) constructs a smooth function Q(x,y)$Q\left(x,y\right)$ which interpolates a set of m$m$ scattered data points (xr,yr,fr)$\left({x}_{r},{y}_{r},{f}_{r}\right)$, for r = 1,2,,m$r=1,2,\dots ,m$, using a modification of Shepard's method. The surface is continuous and has continuous first partial derivatives.
The basic Shepard (1968) method interpolates the input data with the weighted mean
 Q(x,y) = ( ∑ r = 1mwr(x,y)qr)/( ∑ r = 1mwr(x,y)), $Q(x,y)=∑r=1mwr(x,y)qr ∑r=1mwr(x,y) ,$
where qr = fr ${q}_{r}={f}_{r}$, wr (x,y) = 1/(dr2) ${w}_{r}\left(x,y\right)=\frac{1}{{d}_{r}^{2}}$ and dr2 = (xxr)2 + (yyr)2 ${d}_{r}^{2}={\left(x-{x}_{r}\right)}^{2}+{\left(y-{y}_{r}\right)}^{2}$.
The basic method is global in that the interpolated value at any point depends on all the data, but this function uses a modification (see Franke and Nielson (1980) and Renka (1988a)), whereby the method becomes local by adjusting each wr(x,y)${w}_{r}\left(x,y\right)$ to be zero outside a circle with centre (xr,yr)$\left({x}_{r},{y}_{r}\right)$ and some radius Rw${R}_{w}$. Also, to improve the performance of the basic method, each qr${q}_{r}$ above is replaced by a function qr(x,y)${q}_{r}\left(x,y\right)$, which is a quadratic fitted by weighted least squares to data local to (xr,yr)$\left({x}_{r},{y}_{r}\right)$ and forced to interpolate (xr,yr,fr)$\left({x}_{r},{y}_{r},{f}_{r}\right)$. In this context, a point (x,y)$\left(x,y\right)$ is defined to be local to another point if it lies within some distance Rq${R}_{q}$ of it. Computation of these quadratics constitutes the main work done by this function.
The efficiency of the function is further enhanced by using a cell method for nearest neighbour searching due to Bentley and Friedman (1979).
The radii Rw${R}_{w}$ and Rq${R}_{q}$ are chosen to be just large enough to include Nw${N}_{w}$ and Nq${N}_{q}$ data points, respectively, for user-supplied constants Nw${N}_{w}$ and Nq${N}_{q}$. Default values of these parameters are provided by the function, and advice on alternatives is given in Section [Choice of and ].
This function is derived from the function QSHEP2 described by Renka (1988b).
Values of the interpolant Q(x,y)$Q\left(x,y\right)$ generated by this function, and its first partial derivatives, can subsequently be evaluated for points in the domain of the data by a call to nag_interp_2d_scat_shep_eval (e01sh).

## References

Bentley J L and Friedman J H (1979) Data structures for range searching ACM Comput. Surv. 11 397–409
Franke R and Nielson G (1980) Smooth interpolation of large sets of scattered data Internat. J. Num. Methods Engrg. 15 1691–1704
Renka R J (1988a) Multivariate interpolation of large sets of scattered data ACM Trans. Math. Software 14 139–148
Renka R J (1988b) Algorithm 660: QSHEP2D: Quadratic Shepard method for bivariate interpolation of scattered data ACM Trans. Math. Software 14 149–150
Shepard D (1968) A two-dimensional interpolation function for irregularly spaced data Proc. 23rd Nat. Conf. ACM 517–523 Brandon/Systems Press Inc., Princeton

## Parameters

### Compulsory Input Parameters

1:     x(m) – double array
2:     y(m) – double array
m, the dimension of the array, must satisfy the constraint m6${\mathbf{m}}\ge 6$.
The Cartesian coordinates of the data points (xr,yr)$\left({x}_{\mathit{r}},{y}_{\mathit{r}}\right)$, for r = 1,2,,m$\mathit{r}=1,2,\dots ,m$.
Constraint: these coordinates must be distinct, and must not all be collinear.
3:     f(m) – double array
m, the dimension of the array, must satisfy the constraint m6${\mathbf{m}}\ge 6$.
f(r)${\mathbf{f}}\left(\mathit{r}\right)$ must be set to the data value fr${f}_{\mathit{r}}$, for r = 1,2,,m$\mathit{r}=1,2,\dots ,m$.
4:     nw – int64int32nag_int scalar
The number Nw${N}_{w}$ of data points that determines each radius of influence Rw${R}_{w}$, appearing in the definition of each of the weights wr${w}_{\mathit{r}}$, for r = 1,2,,m$\mathit{r}=1,2,\dots ,m$ (see Section [Description]). Note that Rw${R}_{w}$ is different for each weight. If nw0${\mathbf{nw}}\le 0$ the default value nw = min (19,m1)${\mathbf{nw}}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(19,{\mathbf{m}}-1\right)$ is used instead.
Constraint: nwmin (40,m1)${\mathbf{nw}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(40,{\mathbf{m}}-1\right)$.
5:     nq – int64int32nag_int scalar
The number Nq${N}_{q}$ of data points to be used in the least squares fit for coefficients defining the nodal functions qr(x,y)${q}_{r}\left(x,y\right)$ (see Section [Description]). If nq0${\mathbf{nq}}\le 0$ the default value nq = min (13,m1)${\mathbf{nq}}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(13,{\mathbf{m}}-1\right)$ is used instead.
Constraint: nq0${\mathbf{nq}}\le 0$ or 5nqmin (40,m1)$5\le {\mathbf{nq}}\le \mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(40,{\mathbf{m}}-1\right)$.

### Optional Input Parameters

1:     m – int64int32nag_int scalar
Default: The dimension of the arrays x, y, f. (An error is raised if these dimensions are not equal.)
m$m$, the number of data points.
Constraint: m6${\mathbf{m}}\ge 6$.

liq lrq

### Output Parameters

1:     iq(liq) – int64int32nag_int array
liq2 × m + 1$\mathit{liq}\ge 2×{\mathbf{m}}+1$.
Integer data defining the interpolant Q(x,y)$Q\left(x,y\right)$.
2:     rq(lrq) – double array
lrq6 × m + 5$\mathit{lrq}\ge 6×{\mathbf{m}}+5$.
Real data defining the interpolant Q(x,y)$Q\left(x,y\right)$.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, m < 6${\mathbf{m}}<6$, or 0 < nq < 5$0<{\mathbf{nq}}<5$, or nq > min (40,m − 1) ${\mathbf{nq}}>\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(40,{\mathbf{m}}-1\right)$, or nw > min (40,m − 1) ${\mathbf{nw}}>\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(40,{\mathbf{m}}-1\right)$, or liq < 2 × m + 1$\mathit{liq}<2×{\mathbf{m}}+1$, or lrq < 6 × m + 5$\mathit{lrq}<6×{\mathbf{m}}+5$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, (x(i),y(i)) = (x(j),y(j))$\left({\mathbf{x}}\left(i\right),{\mathbf{y}}\left(i\right)\right)=\left({\mathbf{x}}\left(j\right),{\mathbf{y}}\left(j\right)\right)$ for some i ≠ j$i\ne j$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, all the data points are collinear. No unique solution exists.

## Accuracy

On successful exit, the function generated interpolates the input data exactly and has quadratic accuracy.

### Timing

The time taken for a call to nag_interp_2d_scat_shep (e01sg) will depend in general on the distribution of the data points. If x and y are uniformly randomly distributed, then the time taken should be O(m)$\mathit{O}\left({\mathbf{m}}\right)$. At worst O(m2)$\mathit{O}\left({{\mathbf{m}}}^{2}\right)$ time will be required.

### Choice of Nw and Nq

Default values of the parameters Nw${N}_{w}$ and Nq${N}_{q}$ may be selected by calling nag_interp_2d_scat_shep (e01sg) with nw0${\mathbf{nw}}\le 0$ and nq0${\mathbf{nq}}\le 0$. These default values may well be satisfactory for many applications.
If non-default values are required they must be supplied to nag_interp_2d_scat_shep (e01sg) through positive values of nw and nq. Increasing these parameters makes the method less local. This may increase the accuracy of the resulting interpolant at the expense of increased computational cost. The default values nw = min (19,m1) ${\mathbf{nw}}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(19,{\mathbf{m}}-1\right)$ and nq = min (13,m1) ${\mathbf{nq}}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(13,{\mathbf{m}}-1\right)$ have been chosen on the basis of experimental results reported in Renka (1988a). In these experiments the error norm was found to vary smoothly with Nw${N}_{w}$ and Nq${N}_{q}$, generally increasing monotonically and slowly with distance from the optimal pair. The method is not therefore thought to be particularly sensitive to the parameter values. For further advice on the choice of these parameters see Renka (1988a).

## Example

```function nag_interp_2d_scat_shep_example
x = [11.16;
12.85;
19.85;
19.72;
15.91;
0;
20.87;
3.45;
14.26;
17.43;
22.8;
7.58;
25;
0;
9.66;
5.22;
17.25;
25;
12.13;
22.23;
11.52;
15.2;
7.54;
17.32;
2.14;
0.51;
22.69;
5.47;
21.67;
3.31];
y = [1.24;
3.06;
10.72;
1.39;
7.74;
20;
20;
12.78;
17.87;
3.46;
12.39;
1.98;
11.87;
0;
20;
14.66;
19.57;
3.87;
10.79;
6.21;
8.53;
0;
10.69;
13.78;
15.03;
8.37;
19.63;
17.13;
14.36;
0.33];
f = [22.15;
22.11;
7.97;
16.83;
15.3;
34.6;
5.74;
41.24;
10.74;
18.6;
5.47;
29.87;
4.4;
58.2;
4.73;
40.36;
6.43;
8.74;
13.71;
10.25;
15.74;
21.6;
19.31;
12.11;
53.1;
49.43;
3.25;
28.63;
5.52;
44.08];
nw = int64(0);
nq = int64(0);
[iq, rq, ifail] = nag_interp_2d_scat_shep(x, y, f, nw, nq)
```
```

iq =

3
12
1
4
8
5
3
6
9
7
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
22
11
10
19
16
17
23
15
18
13
14
13
30
15
25
24
20
21
20
21
22
26
27
28
26
29
28
29
30

rq =

0
0
8.3333
6.6667
22.5597
271.5245
205.4824
189.9545
341.5185
174.9092
480.1409
351.2840
282.3028
217.6970
274.5241
259.8121
297.1145
306.2440
508.9409
301.4125
270.6925
291.9401
351.3640
125.8490
235.8665
135.0205
301.3909
172.9517
159.2721
367.6490
379.5581
371.3905
286.9056
270.1129
397.8650
0.1878
-0.1651
-0.2132
-1.1301
1.0468
0.0625
-0.0885
-0.1691
-0.8079
-0.1882
0.0832
-0.0586
0.1087
-1.0392
-0.3381
-0.0486
0.0172
-0.0871
-1.2037
-0.1929
-0.0898
0.0049
0.0372
-0.6652
-0.8723
0.2572
0.1824
-0.7009
-5.7655
-9.6106
-0.1071
0.0604
0.0720
-0.9609
0.1964
0.4051
0.1409
-0.3944
-5.0685
1.9018
0.0383
0.1960
-0.3135
-0.3698
-2.2983
-0.0608
0.0197
-0.0858
-0.9400
-0.5989
0.0549
-0.0392
0.0193
-0.6920
-0.4476
0.1788
0.0060
-0.1424
-2.6019
0.0566
0.0575
0.0023
0.0253
-0.4455
-0.4517
0.1591
-0.0533
0.1236
-4.5812
-1.7523
0.1713
0.1845
-0.5129
-1.4284
-6.1995
0.3180
0.0419
-1.0292
-3.0937
-0.8993
-0.0205
0.1689
-0.1461
-0.1984
-1.8325
-0.0044
0.0448
0.0002
-1.1667
-0.5838
0.1173
-0.1318
0.1124
-0.9391
-0.3562
0.0017
0.0532
0.0019
-1.0258
-0.7284
0.1174
-0.0572
0.0674
-0.8996
-0.7621
-0.0128
-0.0210
-0.0592
-0.6935
-0.2959
0.3389
-0.3648
0.0668
-2.8368
0.8061
-0.0989
0.0636
-0.0704
-0.8872
-0.3389
0.5183
0.2246
-0.8528
-6.8360
-1.9763
-0.0216
-0.0341
0.0905
-3.4386
0.1377
-0.0919
0.0075
0.0564
-1.4055
0.0492
0.2750
0.1535
-0.6945
-3.4433
-5.0134
0.0801
0.0351
0.0076
-0.7771
-0.3231
0.1475
-0.0108
-0.0167
-3.7187
-0.6231

ifail =

0

```
```function e01sg_example
x = [11.16;
12.85;
19.85;
19.72;
15.91;
0;
20.87;
3.45;
14.26;
17.43;
22.8;
7.58;
25;
0;
9.66;
5.22;
17.25;
25;
12.13;
22.23;
11.52;
15.2;
7.54;
17.32;
2.14;
0.51;
22.69;
5.47;
21.67;
3.31];
y = [1.24;
3.06;
10.72;
1.39;
7.74;
20;
20;
12.78;
17.87;
3.46;
12.39;
1.98;
11.87;
0;
20;
14.66;
19.57;
3.87;
10.79;
6.21;
8.53;
0;
10.69;
13.78;
15.03;
8.37;
19.63;
17.13;
14.36;
0.33];
f = [22.15;
22.11;
7.97;
16.83;
15.3;
34.6;
5.74;
41.24;
10.74;
18.6;
5.47;
29.87;
4.4;
58.2;
4.73;
40.36;
6.43;
8.74;
13.71;
10.25;
15.74;
21.6;
19.31;
12.11;
53.1;
49.43;
3.25;
28.63;
5.52;
44.08];
nw = int64(0);
nq = int64(0);
[iq, rq, ifail] = e01sg(x, y, f, nw, nq)
```
```

iq =

3
12
1
4
8
5
3
6
9
7
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
22
11
10
19
16
17
23
15
18
13
14
13
30
15
25
24
20
21
20
21
22
26
27
28
26
29
28
29
30

rq =

0
0
8.3333
6.6667
22.5597
271.5245
205.4824
189.9545
341.5185
174.9092
480.1409
351.2840
282.3028
217.6970
274.5241
259.8121
297.1145
306.2440
508.9409
301.4125
270.6925
291.9401
351.3640
125.8490
235.8665
135.0205
301.3909
172.9517
159.2721
367.6490
379.5581
371.3905
286.9056
270.1129
397.8650
0.1878
-0.1651
-0.2132
-1.1301
1.0468
0.0625
-0.0885
-0.1691
-0.8079
-0.1882
0.0832
-0.0586
0.1087
-1.0392
-0.3381
-0.0486
0.0172
-0.0871
-1.2037
-0.1929
-0.0898
0.0049
0.0372
-0.6652
-0.8723
0.2572
0.1824
-0.7009
-5.7655
-9.6106
-0.1071
0.0604
0.0720
-0.9609
0.1964
0.4051
0.1409
-0.3944
-5.0685
1.9018
0.0383
0.1960
-0.3135
-0.3698
-2.2983
-0.0608
0.0197
-0.0858
-0.9400
-0.5989
0.0549
-0.0392
0.0193
-0.6920
-0.4476
0.1788
0.0060
-0.1424
-2.6019
0.0566
0.0575
0.0023
0.0253
-0.4455
-0.4517
0.1591
-0.0533
0.1236
-4.5812
-1.7523
0.1713
0.1845
-0.5129
-1.4284
-6.1995
0.3180
0.0419
-1.0292
-3.0937
-0.8993
-0.0205
0.1689
-0.1461
-0.1984
-1.8325
-0.0044
0.0448
0.0002
-1.1667
-0.5838
0.1173
-0.1318
0.1124
-0.9391
-0.3562
0.0017
0.0532
0.0019
-1.0258
-0.7284
0.1174
-0.0572
0.0674
-0.8996
-0.7621
-0.0128
-0.0210
-0.0592
-0.6935
-0.2959
0.3389
-0.3648
0.0668
-2.8368
0.8061
-0.0989
0.0636
-0.0704
-0.8872
-0.3389
0.5183
0.2246
-0.8528
-6.8360
-1.9763
-0.0216
-0.0341
0.0905
-3.4386
0.1377
-0.0919
0.0075
0.0564
-1.4055
0.0492
0.2750
0.1535
-0.6945
-3.4433
-5.0134
0.0801
0.0351
0.0076
-0.7771
-0.3231
0.1475
-0.0108
-0.0167
-3.7187
-0.6231

ifail =

0

```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013