d01gy calculates the optimal coefficients for use by (D01GCF not in this release) d01gd, for prime numbers of points.

# Syntax

C#
public static void d01gy(
int ndim,
int npts,
double[] vk,
out int ifail
)
Visual Basic
Public Shared Sub d01gy ( _
ndim As Integer, _
npts As Integer, _
vk As Double(), _
<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void d01gy(
int ndim,
int npts,
array<double>^ vk,
[OutAttribute] int% ifail
)
F#
static member d01gy :
ndim : int *
npts : int *
vk : float[] *
ifail : int byref -> unit

#### Parameters

ndim
Type: System..::..Int32
On entry: $n$, the number of dimensions of the integral.
Constraint: ${\mathbf{ndim}}\ge 1$.
npts
Type: System..::..Int32
On entry: $p$, the number of points to be used.
Constraint: ${\mathbf{npts}}$ must be a prime number $\text{}\ge 5$.
vk
Type: array<System..::..Double>[]()[][]
An array of size [ndim]
On exit: the $n$ optimal coefficients.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

The Korobov (1963) procedure for calculating the optimal coefficients ${a}_{1},{a}_{2},\dots ,{a}_{n}$ for $p$-point integration over the $n$-cube ${\left[0,1\right]}^{n}$ imposes the constraint that
 (1)
where $p$ is a prime number and $a$ is an adjustable parameter. This parameter is computed to minimize the error in the integral
 $3n∫01dx1⋯∫01dxn∏i=1n1-2xi2,$ (2)
when computed using the number theoretic rule, and the resulting coefficients can be shown to fit the Korobov definition of optimality.
The computation for large values of $p$ is extremely time consuming (the number of elementary operations varying as ${p}^{2}$) and there is a practical upper limit to the number of points that can be used. Method d01gz is computationally more economical in this respect but the associated error is likely to be larger.

# References

Korobov N M (1963) Number Theoretic Methods in Approximate Analysis Fizmatgiz, Moscow

# Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{ndim}}<1$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{npts}}<5$.
${\mathbf{ifail}}=3$
 On entry, npts is not a prime number.
${\mathbf{ifail}}=4$
The precision of the machine is insufficient to perform the computation exactly. Try a smaller value of npts, or use an implementation of higher precision.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The optimal coefficients are returned as exact integers (though stored in a real array).

# Parallelism and Performance

None.

The time taken is approximately proportional to ${p}^{2}$ (see [Description]).
This example calculates the Korobov optimal coefficients where the number of dimensions is $4$ and the number of points is $631$.