4. Numerical Constrained Differentiation
Numerical differentiation [
36,
37] is a practical alternative for analytic differentiation to obtain values for the sensitivity coefficients. This method is introduced here to enable propagating measurement uncertainty through involved models, such as the GERG-2008 [
24] and the AGA8-DC92 [
26,
27] equations of state, and algorithms.
At first glance, it is not straightforward to perturb a composition and still satisfy the condition given in equation (
2). Consider a normalised direction vector
. For constrained differentiation with respect to compositions, it is required that
is also a valid composition for a sufficiently small
. In this case, the constraint (
2) can be expressed as
where
.
is a valid composition if
is orthogonal to
. From the requirement that
is a valid composition, it follows that the sum of the elements of
is zero.
To illustrate how a composition
can be perturbed by a small shift, let us consider a ternary mixture (
),
. A change in
should be compensated by changes in
,
or both, so that the perturbed input vector
should again be a composition. Consequently, the sum of the elements of the perturbation
should be zero. Amongst the infinitely many options to satisfy this condition, one option is to orthogonally project the vectors
and
onto the hyperplane
containing
and with as normal vector
, the gradient of the constraint. Using the resulting projection
P (see also equation (
4)) yields the normalized perturbation directions
such that it becomes physically meaningful and mathematically feasible to assess the change in the property of interest when the composition is changed from
to either of the compositions
where
and
are some sufficiently small numbers
1.
Given a function f having as one of its arguments a composition , the derivatives with respect to amount fractions of the components in the composition can be obtained numerically as follows.
For the numerical differentiation, instead of computing the limit in equation (
13), a finite, small value for
will be used instead
To evaluate the partial derivative exactly at the value of the estimates
, the directional derivative can be approximated by
For the numerical evaluation of the constrained partial derivatives, the following algorithm can be used:
Choose a small value for so that for all components i
Choose an orthogonal matrix Q with columns , which are all perpendicular to the vector
Compute the directional derivatives
using equation (
19), or (
20) for symmetric partial derivatives
Now,
where
C denotes the sensitivity matrix in the sense of ISO/IEC Guide 98-3 and ISO/IEC Guide 98-3/Supplement 2 [
5,
7]. (In the case of a scalar function
fm
C takes the form of a row vector, or, equivalently, an
matrix.)
The algorithm can be readily further generalised to multivariate functions
, which can be used for propagating measurement uncertainty using the LPU from ISO/IEC Guide 98-3/Supplement 2 [
7].
The algorithm is based on the consideration that if the directions
(see equation (
10)) are chosen normalized and mutually orthogonal, the matrix
becomes orthogonal so that
. This matrix
enables formulating the particularly form of the algorithm, cf. equation (
21). In more detail, the matrix
Q from the algorithm in
Section 4 corresponds to the first
columns of
such that
and let
From equation (
9), it follows that
so the algorithm provides a sensitivity matrix
C that meets the descriptions in the GUM [
5,
7]. In the case that
J cannot be evaluated because the function
f is not defined outside the region defined by the constraint, the covariance matrix associated with
cannot be defined and evaluated by means of equation (
9). In this case however, the sensitivity matrix defined in equation (
21) can be used instead. This case is currently not covered by the GUM [
5,
7].
A complementary viewpoint is obtained by considering the orthogonal projection
P which was introduced in equation (
4). Noting that an orthogonal projection fulfils
and
, it follows from equation (
12) that for a well-formed covariance matrix [
20,
21] it holds that
This matrix as orthogonal projection of J on offers an alternative definition to the matrix as constructed in the algorithm. In the next section it is shown that is actually identical to K if is of rank .
If the degeneracy of
is solely due to the constraint, then
has rank
and its unique Cholesky factor
L has also rank
. Assume that by specific choices of the matrix
Q, the projection operator of equation (
22) or any other method two constrained sensitivity matrices
and
would have been obtained, i.e.,
Then
, and as
L has rank
and
, it must hold that
for some scalar
. In view of equations () and () this is only possible if
, i.e., if
. As the factors
and
occur twice in (
23), the uniqueness is actually up to a sign, so,
.
Therefore, if
has rank
, the constrained sensitivity matrix is essentially unique and equal to
from equation (
22), i.e., the orthogonal projection of the Jacobian applied from the right side or, equivalently, the transpose of the orthogonal projection of the transposed Jacobian.
The matrix
Q can be obtained in different ways. One such way is using a matrix derived from the Helmert matrix [
41], which is available as the function
ilrBase in the
R package ’compositions’ [
42]. Alternatively, the (modified) Gram-Schmidt algorithm can be used [
43]. For a composition, the following orthogonal matrix can be used. For each column
, the first
j elements are equal to
and the following element is equal to
The remaining elements are zero. For
, using these formulæ,
Using the matrix
Q from (
26) and the composition of a five-component natural gas in
Table 1, the sensitivity coefficients are evaluated for the molar mass of the natural gas using the model of ISO 6976 [
18]. The molar mass is given by [
18]
where
denotes the (normalised) amount fraction of component
i,
its molar mass and
the molar mass of the mixture. The numerical method given in equations (
21) and (
26) are compared with the values obtained using the analytic formula, viz. [
23],
In
Table 1, the sensitivity coefficients are given using the numerical method (
) versus analytic differentiation including the constraint on the
(
). The sensitivity coefficients are obtained using equation (
19).
The sensitivity coefficients in the ultimate two columns of
Table 1 are identical up to four decimal figures, which is sufficient for the propagation of measurement uncertainty using the LPU. In the numerical evaluation of the sensitivity coefficients,
was chosen to be 1 % of the smallest amount fraction in the composition. This choice ensures that
are valid compositions. According to ISO/IEC Guide 98-3 [
44], clause 5.1.3 NOTE 2], a perturbation in the order of a standard uncertainty is adequate for the purpose of propagating measurement uncertainty. This choice of
just does that. The only concern can be that for compositions involving components at the μmol mol
−1-level, this choice may lead to unacceptable cancellation in the calculation of the differences.
Using a constant value of
and the first order formula (
19), there are in total
N calls to the function
f needed. For equations like equation (
27), this feature is not important, but the more involved the evaluation of
f is, the more important this deliberation gets. The differences between the sensitivity coefficients using equation (
19) and the ones obtained using analytic differentiation are in the order of 10
−12 g mol
−1. Using equation (
20) instead, thus obtaining the symmetric partial derivatives, the errors are slightly smaller in absolute value but still in the order of 10
−12 g mol
−1. This computation requires
calls to the function
f.
Table 2 shows the same comparison, but now for an 11-component natural gas mixture. The differences between the numerically evaluated sensitivity coefficients and the ones obtained through analytic differentiation are in the order of 10
−9 g mol
−1. This performance is also sufficient for propagating the measurement uncertainty when computing the molar calorific value
H or the compressibility factor
Z.
The calculations can be readily performed in any kind of software, from mainstream spreadsheet software to environments like R [
45] or Python [
46]. The arguments of a function
f that do not belong to the composition can be handled as usual. They can be evaluated numerically directly using the approach described in GUM:1995 [
5], clause 5.1.3 NOTE 2].