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

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_fit_2dspline_ts_sctr (e02jd)

## Purpose

nag_fit_2dspline_ts_sctr (e02jd) computes a spline approximation to a set of scattered data using a two-stage approximation method.
The computational complexity of the method grows linearly with the number of data points; hence large datasets are easily accommodated.

## Syntax

[coefs, iopts, opts, ifail] = e02jd(x, y, f, lsminp, lsmaxp, nxcels, nycels, iopts, opts, 'n', n)
[coefs, iopts, opts, ifail] = nag_fit_2dspline_ts_sctr(x, y, f, lsminp, lsmaxp, nxcels, nycels, iopts, opts, 'n', n)
Before calling nag_fit_2dspline_ts_sctr (e02jd), nag_fit_opt_set (e02zk) must be called with optstr set to ‘’. Settings for optional algorithmic parameters may be specified by calling nag_fit_opt_set (e02zk) before a call to nag_fit_2dspline_ts_sctr (e02jd).

## Description

nag_fit_2dspline_ts_sctr (e02jd) determines a smooth bivariate spline approximation to a set of data points (xi,yi,fi)$\left({x}_{\mathit{i}},{y}_{\mathit{i}},{f}_{\mathit{i}}\right)$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$. Here, ‘smooth’ means C1${C}^{1}$.
The approximation domain is the bounding box [xmin,xmax] × [ymin,ymax] $\left[{x}_{\mathrm{min}},{x}_{\mathrm{max}}\right]×\left[{y}_{\mathrm{min}},{y}_{\mathrm{max}}\right]$, where xmin${x}_{\mathrm{min}}$ (respectively ymin${y}_{\mathrm{min}}$) and xmax${x}_{\mathrm{max}}$ (respectively ymax${y}_{\mathrm{max}}$) denote the lowest and highest data values of the (xi)$\left({x}_{i}\right)$ (respectively (yi)$\left({y}_{i}\right)$).
The spline is computed by local approximations on a uniform triangulation of the bounding box. These approximations are extended to a smooth spline representation of the surface over the domain. The local approximation scheme is by least squares polynomials (Davydov and Zeilfelder (2004)).
The two-stage approximation method employed by nag_fit_2dspline_ts_sctr (e02jd) is derived from the TSFIT package of O. Davydov and F. Zeilfelder.
Values of the computed spline can subsequently be computed by calling nag_fit_2dspline_ts_evalv (e02je) or nag_fit_2dspline_ts_evalm (e02jf).

## References

Davydov O and Zeilfelder F (2004) Scattered data fitting by direct extension of local polynomials to bivariate splines Advances in Comp. Math. 21 223–271

## Parameters

### Compulsory Input Parameters

1:     x(n) – double array
2:     y(n) – double array
3:     f(n) – double array
n, the dimension of the array, must satisfy the constraint n > 1${\mathbf{n}}>1$.
The (xi,yi,fi) $\left({x}_{i},{y}_{i},{f}_{i}\right)$ data values to be fitted.
Constraint: x(j)x(1)${\mathbf{x}}\left(j\right)\ne {\mathbf{x}}\left(1\right)$ for some j = 2,,n$j=2,\dots ,n$ and y(k)y(1)${\mathbf{y}}\left(k\right)\ne {\mathbf{y}}\left(1\right)$ for some k = 2,,n$k=2,\dots ,n$; i.e., there are at least two distinct x$x$ and y$y$ values.
4:     lsminp – int64int32nag_int scalar
5:     lsmaxp – int64int32nag_int scalar
Are control parameters for the local approximations.
Each local approximation is computed on a local domain containing one of the triangles in the discretization of the bounding box. The size of each local domain will be adaptively chosen such that if it contains fewer than lsminp sample points it is expanded, else if it contains greater than lsmaxp sample points a thinning method is applied. lsmaxp mainly controls computational cost (in that working with a thinned set of points is cheaper and may be appropriate if the input data is densely distributed), while lsminp allows handling of different types of scattered data.
Setting ${\mathbf{lsmaxp}}<{\mathbf{lsminp}}$, and therefore forcing either expansion or thinning, may be useful for computing initial coarse approximations. In general smaller values for these arguments reduces cost.
A calibration procedure (experimenting with a small subset of the data to be fitted and validating the results) may be needed to choose the most appropriate values for lsminp and lsmaxp.
Constraints:
• 1lsminpn$1\le {\mathbf{lsminp}}\le {\mathbf{n}}$;
• lsmaxp1${\mathbf{lsmaxp}}\ge 1$.
6:     nxcels – int64int32nag_int scalar
7:     nycels – int64int32nag_int scalar
nxcels (respectively nycels) is the number of cells in the x$x$ (respectively y$y$) direction that will be used to create the triangulation of the bounding box of the domain of the function to be fitted.
Greater efficiency generally comes when nxcels and nycels are chosen to be of the same order of magnitude and are such that n is O(nxcels × nycels)$\mathit{O}\left({\mathbf{nxcels}}×{\mathbf{nycels}}\right)$. Thus for a ‘square’ triangulation — when ${\mathbf{nxcels}}={\mathbf{nycels}}$ — the quantities sqrt(n)$\sqrt{{\mathbf{n}}}$ and nxcels should be of the same order of magnitude. See also Section [Further Comments].
Constraints:
• nxcels1${\mathbf{nxcels}}\ge 1$;
• nycels1${\mathbf{nycels}}\ge 1$.
8:     iopts(liopts$\mathit{liopts}$) – int64int32nag_int array
The contents of iopts must not be modified in any way either directly or indirectly, by further calls to nag_fit_opt_set (e02zk), before calling either or both of the evaluation routines nag_fit_2dspline_ts_evalv (e02je) and nag_fit_2dspline_ts_evalm (e02jf).
9:     opts(lopts$\mathit{lopts}$) – double array
The contents of opts must not be modified in any way either directly or indirectly, by further calls to nag_fit_opt_set (e02zk), before calling either or both of the evaluation routines nag_fit_2dspline_ts_evalv (e02je) and nag_fit_2dspline_ts_evalm (e02jf).

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x, y, f. (An error is raised if these dimensions are not equal.)
n$n$, the number of data values to be fitted.
Constraint: n > 1${\mathbf{n}}>1$.

lcoefs

### Output Parameters

1:     coefs(lcoefs) – double array
lcoefs (((nxcels + 2) × (nycels + 2) + 1) / 2) × 10 + 1$\mathit{lcoefs}\ge \left(\left(\left({\mathbf{nxcels}}+2\right)×\left({\mathbf{nycels}}+2\right)+1\right)/2\right)×10+1$.
If ${\mathbf{ifail}}={\mathbf{0}}$ on exit, coefs contains the computed spline coefficients.
2:     iopts(liopts$\mathit{liopts}$) – int64int32nag_int array
Communication array, used to store information between calls to nag_fit_2dspline_ts_sctr (e02jd).
3:     opts(lopts$\mathit{lopts}$) – double array
Communication array, used to store information between calls to nag_fit_2dspline_ts_sctr (e02jd).
4:     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 = 2${\mathbf{ifail}}=2$
Constraint: n > 1${\mathbf{n}}>1$.
ifail = 4${\mathbf{ifail}}=4$
Constraint: 1lsminpn$1\le {\mathbf{lsminp}}\le {\mathbf{n}}$.
ifail = 5${\mathbf{ifail}}=5$
Constraint: lsmaxp1${\mathbf{lsmaxp}}\ge 1$.
ifail = 6${\mathbf{ifail}}=6$
Constraint: nxcels1${\mathbf{nxcels}}\ge 1$.
ifail = 7${\mathbf{ifail}}=7$
Constraint: nycels1${\mathbf{nycels}}\ge 1$.
ifail = 8${\mathbf{ifail}}=8$
Constraint: lcoefs(((nxcels + 2) × (nycels + 2) + 1) / 2) × 10 + 1$\mathit{lcoefs}\ge \left(\left(\left({\mathbf{nxcels}}+2\right)×\left({\mathbf{nycels}}+2\right)+1\right)/2\right)×10+1$.
ifail = 9${\mathbf{ifail}}=9$
Option arrays are not initialized or are corrupted.
ifail = 11${\mathbf{ifail}}=11$
ifail = 12${\mathbf{ifail}}=12$
On entry, all elements of x or of y are equal.
ifail = 21${\mathbf{ifail}}=21$
The value of optional parameter Polynomial Starting Degree was invalid.
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Technical results on error bounds can be found in Davydov and Zeilfelder (2004).
Local approximation by polynomials of degree d$d$ for n$n$ data points has optimal approximation order n (d + 1) / 2 ${n}^{-\left(d+1\right)/2}$.
The approximation error for C1${C}^{1}$ global smoothing is O(n2) $\mathit{O}\left({n}^{-2}\right)$.
Whether maximal accuracy is achieved depends on the distribution of the input data and the choices of the algorithmic parameters. The reference above contains extensive numerical tests and further technical discussions of how best to configure the method.

n$n$-linear complexity and memory usage can be attained for sufficiently dense input data if the triangulation parameters nxcels and nycels are chosen as recommended in their descriptions above. For sparse input data on such triangulations, if many expansion steps are required (see lsminp) the complexity may rise to be loglinear.

## Example

```function nag_fit_2dspline_ts_sctr_example
xdata = [0; 0.5; 1; 1.5; 2; 2.5; 3; 4; 4.5; 5; 5.5; 6; 7; 7.5; 8];
ydata = [-1.1; -0.372; 0.431; 1.69; 2.11; 3.1; 4.23; 4.35; 4.81; 4.61; 4.79; ...
5.23; 6.35; 7.19; 7.97];
wdata = [1; 1; 1.5; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
cstart = 'c';
sfac  = 0.001;
x     = [6.5178; 7.2463; 1.0159; 7.3070; 5.0589; 0.7803; 2.2280; 4.3751; ...
7.6601; 7.7191; 1.2609; 7.7647; 7.6573; 3.8830; 6.4022; 1.1351; ...
3.3741; 7.3259; 6.3377; 7.6759];
nest  = int64(numel(xdata) + 4);
ixloc = zeros(numel(x), 1, 'int64');
wrk   = zeros(4*numel(xdata) + 16*nest + 41, 1);
iwrk1 = zeros(nest, 1, 'int64');
iwrk2 = zeros(3+3*numel(x), 1, 'int64');
lamda = zeros(nest, 1);
xord  = int64(0);
start = int64(0);
deriv = int64(3);

% Generate the data to fit.
[x, y, f, lsminp, lsmaxp, nxcels, nycels] = generate_data();

% Initialize the options arrays and set/get some options.
[iopts, opts] = handle_options();

% Compute the spline coefficients.
[coefs, iopts, opts, ifail] = ...
nag_fit_2dspline_ts_sctr(x, y, f, lsminp, lsmaxp, nxcels, nycels, iopts, opts);

% pmin and pmax form the bounding box of the spline. We must not attempt to
% evaluate the spline outside this box.
pmin = [min(x); min(y)];
pmax = [max(x); max(y)];

% Evaluate the approximation at a vector of values.
evaluate_at_vector(coefs, iopts, opts, pmin, pmax);

% Evaluate the approximation on a mesh.
evaluate_on_mesh(coefs, iopts, opts, pmin, pmax);

function [x, y, f, lsminp, lsmaxp, nxcels, nycels] = generate_data()
% Generates an x and a y vector of n pseudorandom uniformly distributed
% values on (0,1]. These are passed to the bivariate function of R. Franke
% to create the data set to fit.  The remaining input data for
% nag_fit_2dspline_ts_sctr are set to suitable values for this problem,
% as discussed by Davydov and Zeilfelder.

n = int64(100);

% Initialize the generator to a repeatable sequence
[state, ifail] = nag_rand_init_repeat(int64(1), int64(0), int64(32958));

% Generate x values
[state, x, ifail] = nag_rand_dist_uniform01(n, state);

% Generate y values
[state, y, ifail] = nag_rand_dist_uniform01(n, state);

% Ensure that the bounding box stretches all the way to (0,0) and (1,1)
x(1) = 0;
y(1) = 0;
x(n) = 1;
y(n) = 1;

f = 0.75*exp(-((9*x(:)-2).^2+(9*y(:)-2).^2)/4)+0.75*exp(-(9*x(:)+ 1).^2/49 ...
-(9*y(:)+1)/10) + 0.5*exp(-((9*x(:)-7).^2+(9*y(:)- 3).^2)/4) - ...
0.2*exp(-(9*x(:)- 4).^2-(9.*y(:)-7).^2);

% Grid size for the approximation
nxcels = int64(6);
nycels = int64(6);

% Identify the computation.
fprintf('\nComputing the coefficients of a C^1 spline approximation to Franke''s function\n');
fprintf(' Using a %d by %d grid\n', nxcels, nycels);

% Local-approximation control parameters.
lsminp = int64(3);
lsmaxp = int64(100);
function [iopts, opts] = handle_options()
% Initialize the options arrays and demonstrate how to set and get
% optional parameters.
opts  = zeros(100, 1);
iopts = zeros(100, 1, 'int64');

[iopts, opts, ifail] = ...
nag_fit_opt_set('Initialize = nag_fit_2dspline_ts_sctr', iopts, opts);

%  Set some non-default parameters for the local approximation method.
optstr = strcat('Minimum Singular Value LPA = ', num2str(1/32));
[iopts, opts, ifail] = nag_fit_opt_set(optstr, iopts, opts);
[iopts, opts, ifail] = ...
nag_fit_opt_set('Polynomial Starting Degree = 3', iopts, opts);

% Set a non-default parameter for the global approximation method.
[iopts, opts, ifail] = nag_fit_opt_set('Averaged Spline = Yes', iopts, opts);

% As an example of how to get the value of an optional parameter,
% display whether averaging of local approximations is in operation.
[~, ~, cvalue, ~, ifail] = nag_fit_opt_get('Averaged Spline', iopts, opts);
if strcmp(cvalue, 'YES')
fprintf(' Using an averaged local approximation\n');
end
function evaluate_at_vector(coefs, iopts, opts, pmin, pmax)
% Evaluates the approximation at a (in this case trivial) vector of values.

xevalv = [0];
yevalv = [0];

% Force the points to be within the bounding box of the spline'
for i = 1:numel(xevalv)
xevalv(i) = max(xevalv(i),pmin(1));
xevalv(i) = min(xevalv(i),pmax(1));
yevalv(i) = max(yevalv(i),pmin(2));
yevalv(i) = min(yevalv(i),pmax(2));
end

[fevalv, ifail] = nag_fit_2dspline_ts_evalv(xevalv, yevalv, coefs, iopts, opts);

fprintf('\n Values of computed spline at (x_i,y_i):\n\n');
fprintf('         x_i          y_i   f(x_i,y_i)\n');
for i = 1:numel(xevalv)
fprintf('%12.2f %12.2f %12.2f\n', xevalv(i),yevalv(i),fevalv(i));
end
function evaluate_on_mesh(coefs,iopts,opts,pmin,pmax)
% Evaluates the approximation on a mesh of n_x * n_y values.
nxeval = 101;
nyeval = 101;

% Define the mesh by its lower-left and upper-right corners.
ll_corner = [0; 0];
ur_corner = [1; 1];

% Set the mesh spacing and the evaluation points.
% Force the points to be within the bounding box of the spline.
h = [(ur_corner(1)-ll_corner(1))/(nxeval-1); ...
(ur_corner(2)-ll_corner(2))/(nyeval-1)];

xevalm = ll_corner(1) + [0:nxeval-1]*h(1);
yevalm = ll_corner(2) + [0:nyeval-1]*h(2);

% Ensure that the evaluation points are in the bounding box
xevalm = max(pmin(1), xevalm);
xevalm = min(pmax(1), xevalm);
yevalm = max(pmin(2), yevalm);
yevalm = min(pmax(2), yevalm);

% Evaluate
[fevalm, ifail] = nag_fit_2dspline_ts_evalm(xevalm, yevalm, coefs, iopts, opts);

print_mesh = false;

if print_mesh
fprintf('\nValues of computed spline at (x_i,y_j):\n\n');
fprintf('         x_i          y_i   f(x_i,y_i)\n');
for i = 1:nxeval
for j=1:nyeval
fprintf('%12.2f %12.2f %12.2f\n', xevalm(i),yevalm(j),fevalm(i, j));
end
end
else
fprintf('\nOutputting of the function values on the mesh is disabled\n');
end
```
```

Computing the coefficients of a C^1 spline approximation to Franke's function
Using a 6 by 6 grid
Using an averaged local approximation

Values of computed spline at (x_i,y_i):

x_i          y_i   f(x_i,y_i)
0.00         0.00         0.76

Outputting of the function values on the mesh is disabled

```
```function e02jd_example
xdata = [0; 0.5; 1; 1.5; 2; 2.5; 3; 4; 4.5; 5; 5.5; 6; 7; 7.5; 8];
ydata = [-1.1; -0.372; 0.431; 1.69; 2.11; 3.1; 4.23; 4.35; 4.81; 4.61; 4.79; ...
5.23; 6.35; 7.19; 7.97];
wdata = [1; 1; 1.5; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
cstart = 'c';
sfac  = 0.001;
x     = [6.5178; 7.2463; 1.0159; 7.3070; 5.0589; 0.7803; 2.2280; 4.3751; ...
7.6601; 7.7191; 1.2609; 7.7647; 7.6573; 3.8830; 6.4022; 1.1351; ...
3.3741; 7.3259; 6.3377; 7.6759];
nest  = int64(numel(xdata) + 4);
ixloc = zeros(numel(x), 1, 'int64');
wrk   = zeros(4*numel(xdata) + 16*nest + 41, 1);
iwrk1 = zeros(nest, 1, 'int64');
iwrk2 = zeros(3+3*numel(x), 1, 'int64');
lamda = zeros(nest, 1);
xord  = int64(0);
start = int64(0);
deriv = int64(3);

% Generate the data to fit.
[x, y, f, lsminp, lsmaxp, nxcels, nycels] = generate_data();

% Initialize the options arrays and set/get some options.
[iopts, opts] = handle_options();

% Compute the spline coefficients.
[coefs, iopts, opts, ifail] = ...
e02jd(x, y, f, lsminp, lsmaxp, nxcels, nycels, iopts, opts);

% pmin and pmax form the bounding box of the spline. We must not attempt to
% evaluate the spline outside this box.
pmin = [min(x); min(y)];
pmax = [max(x); max(y)];

% Evaluate the approximation at a vector of values.
evaluate_at_vector(coefs, iopts, opts, pmin, pmax);

% Evaluate the approximation on a mesh.
evaluate_on_mesh(coefs, iopts, opts, pmin, pmax);

function [x, y, f, lsminp, lsmaxp, nxcels, nycels] = generate_data()
% Generates an x and a y vector of n pseudorandom uniformly distributed
% values on (0,1]. These are passed to the bivariate function of R. Franke
% to create the data set to fit.  The remaining input data for
% e02jd are set to suitable values for this problem,
% as discussed by Davydov and Zeilfelder.

n = int64(100);

% Initialize the generator to a repeatable sequence
[state, ifail] = g05kf(int64(1), int64(0), int64(32958));

% Generate x values
[state, x, ifail] = g05sa(n, state);

% Generate y values
[state, y, ifail] = g05sa(n, state);

% Ensure that the bounding box stretches all the way to (0,0) and (1,1)
x(1) = 0;
y(1) = 0;
x(n) = 1;
y(n) = 1;

f = 0.75*exp(-((9*x(:)-2).^2+(9*y(:)-2).^2)/4)+0.75*exp(-(9*x(:)+ 1).^2/49 ...
-(9*y(:)+1)/10) + 0.5*exp(-((9*x(:)-7).^2+(9*y(:)- 3).^2)/4) - ...
0.2*exp(-(9*x(:)- 4).^2-(9.*y(:)-7).^2);

% Grid size for the approximation
nxcels = int64(6);
nycels = int64(6);

% Identify the computation.
fprintf('\nComputing the coefficients of a C^1 spline approximation to Franke''s function\n');
fprintf(' Using a %d by %d grid\n', nxcels, nycels);

% Local-approximation control parameters.
lsminp = int64(3);
lsmaxp = int64(100);
function [iopts, opts] = handle_options()
% Initialize the options arrays and demonstrate how to set and get
% optional parameters.
opts  = zeros(100, 1);
iopts = zeros(100, 1, 'int64');

[iopts, opts, ifail] = ...
e02zk('Initialize = e02jd', iopts, opts);

%  Set some non-default parameters for the local approximation method.
optstr = strcat('Minimum Singular Value LPA = ', num2str(1/32));
[iopts, opts, ifail] = e02zk(optstr, iopts, opts);
[iopts, opts, ifail] = ...
e02zk('Polynomial Starting Degree = 3', iopts, opts);

% Set a non-default parameter for the global approximation method.
[iopts, opts, ifail] = e02zk('Averaged Spline = Yes', iopts, opts);

% As an example of how to get the value of an optional parameter,
% display whether averaging of local approximations is in operation.
[~, ~, cvalue, ~, ifail] = e02zl('Averaged Spline', iopts, opts);
if strcmp(cvalue, 'YES')
fprintf(' Using an averaged local approximation\n');
end
function evaluate_at_vector(coefs, iopts, opts, pmin, pmax)
% Evaluates the approximation at a (in this case trivial) vector of values.

xevalv = [0];
yevalv = [0];

% Force the points to be within the bounding box of the spline'
for i = 1:numel(xevalv)
xevalv(i) = max(xevalv(i),pmin(1));
xevalv(i) = min(xevalv(i),pmax(1));
yevalv(i) = max(yevalv(i),pmin(2));
yevalv(i) = min(yevalv(i),pmax(2));
end

[fevalv, ifail] = e02je(xevalv, yevalv, coefs, iopts, opts);

fprintf('\n Values of computed spline at (x_i,y_i):\n\n');
fprintf('         x_i          y_i   f(x_i,y_i)\n');
for i = 1:numel(xevalv)
fprintf('%12.2f %12.2f %12.2f\n', xevalv(i),yevalv(i),fevalv(i));
end
function evaluate_on_mesh(coefs,iopts,opts,pmin,pmax)
% Evaluates the approximation on a mesh of n_x * n_y values.
nxeval = 101;
nyeval = 101;

% Define the mesh by its lower-left and upper-right corners.
ll_corner = [0; 0];
ur_corner = [1; 1];

% Set the mesh spacing and the evaluation points.
% Force the points to be within the bounding box of the spline.
h = [(ur_corner(1)-ll_corner(1))/(nxeval-1); ...
(ur_corner(2)-ll_corner(2))/(nyeval-1)];

xevalm = ll_corner(1) + [0:nxeval-1]*h(1);
yevalm = ll_corner(2) + [0:nyeval-1]*h(2);

% Ensure that the evaluation points are in the bounding box
xevalm = max(pmin(1), xevalm);
xevalm = min(pmax(1), xevalm);
yevalm = max(pmin(2), yevalm);
yevalm = min(pmax(2), yevalm);

% Evaluate
[fevalm, ifail] = e02jf(xevalm, yevalm, coefs, iopts, opts);

print_mesh = false;

if print_mesh
fprintf('\nValues of computed spline at (x_i,y_j):\n\n');
fprintf('         x_i          y_i   f(x_i,y_i)\n');
for i = 1:nxeval
for j=1:nyeval
fprintf('%12.2f %12.2f %12.2f\n', xevalm(i),yevalm(j),fevalm(i, j));
end
end
else
fprintf('\nOutputting of the function values on the mesh is disabled\n');
end
```
```

Computing the coefficients of a C^1 spline approximation to Franke's function
Using a 6 by 6 grid
Using an averaged local approximation

Values of computed spline at (x_i,y_i):

x_i          y_i   f(x_i,y_i)
0.00         0.00         0.76

Outputting of the function values on the mesh is disabled

```

## Optional Parameters

Several optional parameters in nag_fit_2dspline_ts_sctr (e02jd) control aspects of the algorithm, methodology used, logic or output. Their values are contained in the arrays iopts and opts; these must be initialized before calling nag_fit_2dspline_ts_sctr (e02jd) by first calling nag_fit_opt_set (e02zk) with optstr set to ‘’.
Each optional parameter has an associated default value; to set any of them to a non-default value, or to reset any of them to the default value, use nag_fit_opt_set (e02zk). The current value of an optional parameter can be queried using nag_fit_opt_get (e02zl).
The remainder of this section can be skipped if you wish to use the default values for all optional parameters.
The following is a list of the optional parameters available. A full description of each optional parameter is provided in Section [Description of the optional parameters].

### Description of the Optional Parameters

For each option, we give a summary line, a description of the optional parameter and details of constraints.
The summary line contains:
• the keywords;
• a parameter value, where the letters a$a$, i​ and ​r$i\text{​ and ​}r$ denote options that take character, integer and real values respectively;
• the default value.
Keywords and character values are case insensitive.
For nag_fit_2dspline_ts_sctr (e02jd) the maximum length of the parameter cvalue used by nag_fit_opt_get (e02zl) is 6$6$.
Averaged Spline  a$a$
Default = 'NO'$\text{}=\text{'NO'}$
When the bounding box is triangulated there are 8 equivalent configurations of the mesh. Setting Averaged Spline = 'YES'${\mathbf{Averaged Spline}}=\text{'YES'}$ will use the averaged value of the 8$8$ possible local polynomial approximations over each triangle in the mesh. This usually gives better results but at (about 8 times) higher computational cost.
Constraint: Averaged Spline = 'YES'${\mathbf{Averaged Spline}}=\text{'YES'}$ or 'NO'$\text{'NO'}$.
Minimum Singular Value LPA  r$r$
Default = 1.0$\text{}=1.0$
A tolerance measure for accepting or rejecting a local polynomial approximation (LPA) as reliable.
The solution of a local least squares problem solved on each triangle subdomain is accepted as reliable if the minimum singular value σ$\sigma$ of the matrix (of Bernstein polynomial values) associated with the least squares problem satisfies ${\mathbf{Minimum Singular Value LPA}}\le \sigma$.
In general the approximation power will be reduced as Minimum Singular Value LPA is reduced. (A small σ$\sigma$ indicates that the local data has hidden redundancies which prevent it from carrying enough information for a good approximation to be made.) Setting Minimum Singular Value LPA very large may have the detrimental effect that only approximations of low degree are deemed reliable.
Minimum Singular Value LPA will have no effect if ${\mathbf{Polynomial Starting Degree}}=0$, and it will have little effect if the input data is ‘smooth’ (e.g., from a known function).
A calibration procedure (experimenting with a small subset of the data to be fitted and validating the results) may be needed to choose the most appropriate value for this parameter.
Constraint: ${\mathbf{Minimum Singular Value LPA}}\ge 0.0$.
Polynomial Starting Degree  i$i$
Default = 1$\text{}=1$
The degree to be used in the initial step of each local polynomial approximation.
At the initial step the method will attempt to fit with local polynomials of degree Polynomial Starting Degree. If the approximation is deemed unreliable (according to Minimum Singular Value LPA), the degree will be decremented by one and a new local approximation computed, ending with a constant approximation if no other is reliable.
Polynomial Starting Degree is bounded from above by the maximum possible spline degree, 3$3$.
The default value gives a good compromise between efficiency and accuracy. In general the best approximation can be obtained by setting ${\mathbf{Polynomial Starting Degree}}=3$.
Constraint: $0\le {\mathbf{Polynomial Starting Degree}}\le 3$.