Computing the Composition of SRM-481

One of the Au-Ag wires is nominally 59.50±1.20% Au and 40.20±0.90% Ag according to the SRM certificate. We will use NeXLUncertainties and NeXLCore to compute various different representations of the composition (normalized, atom fraction, etc.)

using NeXLCore
using DataFrames

Let's set up the UncertainValues object containing the input values which include the mass fractions of each element and the nominal atomic weight of each element with uncertainties.

mat = "Au60Ag40"
inplbls = [ MassFractionLabel(mat,n"Ag"), AtomicWeightLabel(mat,n"Ag"),
            MassFractionLabel(mat,n"Au"), AtomicWeightLabel(mat,n"Au") ]
inpvals = [ 0.4020, 107.8682, 0.5950, 196.966570 ]
inpcovs = [ (0.0090)^2 0 0 0; 0 (0.0002)^2 0 0; 0 0 (0.0120)^2 0; 0 0 0 (0.000004)^2 ]
inputs = uvs(inplbls, inpvals, inpcovs)
LabelValueC[Ag,Au60Ag40]Az[Ag,Au60Ag40]C[Au,Au60Ag40]Az[Au,Au60Ag40]
C[Ag,Au60Ag40]4.02e-01(9.00e-03)²0.00e+000.00e+000.00e+00
Az[Ag,Au60Ag40]1.08e+02±0.00e+00(2.00e-04)²0.00e+000.00e+00
C[Au,Au60Ag40]5.95e-010.00e+000.00e+00(1.20e-02)²0.00e+00
Az[Au,Au60Ag40]1.97e+020.00e+000.00e+000.00e+00(4.00e-06)²

mf2comp(...) defined in NeXLCore takes the inputs and computes the atom fractions, normalized mass fractions, mean atomic number, and mean atomic weight while propagating uncertaities in the input variables into the output variables. In both the case of the atom fraction and the normalized mass fraction, the normalization step introduces correlations between the output values.

afs = mf2comp( mat, inputs)
LabelValueC[Ag,Au60Ag40]Az[Ag,Au60Ag40]C[Au,Au60Ag40]Az[Au,Au60Ag40]A[Ag,Au60Ag40]A[Au,Au60Ag40]N[Ag,Au60Ag40]N[Au,Au60Ag40]MeanZ[Au60Ag40]MeanAz[Au60Ag40]Σ[Au60Ag40]
C[Ag,Au60Ag40]4.02e-01(9.00e-03)²0.00e+000.00e+000.00e+004.98e-05-4.98e-054.85e-05-4.85e-053.81e-038.74e-038.10e-05
Az[Ag,Au60Ag40]1.08e+020.00e+00(2.00e-04)²0.00e+000.00e+00-9.17e-119.17e-110.00e+000.00e+000.00e+001.61e-080.00e+00
C[Au,Au60Ag40]5.95e-010.00e+000.00e+00(1.20e-02)²0.00e+00-5.98e-055.98e-05-5.82e-055.82e-051.14e-022.84e-021.44e-04
Az[Au,Au60Ag40]1.97e+020.00e+000.00e+000.00e+00(4.00e-06)²2.01e-14-2.01e-140.00e+000.00e+000.00e+009.52e-120.00e+00
A[Ag,Au60Ag40]5.52e-014.98e-05-9.17e-11-5.98e-052.01e-14(7.45e-03)²-5.55e-055.40e-05-5.40e-05-2.39e-03-6.41e-03-1.00e-05
A[Au,Au60Ag40]4.48e-01±-4.98e-059.17e-115.98e-05-2.01e-14-5.55e-05(7.45e-03)²-5.40e-055.40e-052.39e-036.41e-031.00e-05
N[Ag,Au60Ag40]4.03e-014.85e-050.00e+00-5.82e-050.00e+005.40e-05-5.40e-05(7.25e-03)²-5.26e-05-2.32e-03-6.24e-03-9.75e-06
N[Au,Au60Ag40]5.97e-01-4.85e-050.00e+005.82e-050.00e+00-5.40e-055.40e-05-5.26e-05(7.25e-03)²2.32e-036.24e-039.75e-06
MeanZ[Au60Ag40]6.59e+013.81e-030.00e+001.14e-020.00e+00-2.39e-032.39e-03-2.32e-032.32e-03(1.04e+00)²2.65e+001.52e-02
MeanAz[Au60Ag40]1.61e+028.74e-031.61e-082.84e-029.52e-12-6.41e-036.41e-03-6.24e-036.24e-032.65e+00(2.56e+00)²3.71e-02
Σ[Au60Ag40]9.97e-018.10e-050.00e+001.44e-040.00e+00-1.00e-051.00e-05-9.75e-069.75e-061.52e-023.71e-02(1.50e-02)²

The data can also be output as a DataFrame to simplify presentation and exporting to CSV files.

asa(DataFrame,afs)
11×13 DataFrame
 Row │ Variable          Values      C[Ag,Au60Ag40]  Az[Ag,Au60Ag40]  C[Au,
Au60Ag40]  Az[Au,Au60Ag40]  A[Ag,Au60Ag40]  A[Au,Au60Ag40]  N[Ag,Au60Ag40] 
 N[Au,Au ⋯
     │ String            Float64     Float64         Float64          Float
64         Float64          Float64         Float64         Float64        
 Float64 ⋯
─────┼─────────────────────────────────────────────────────────────────────
───────────────────────────────────────────────────────────────────────────
──────────
   1 │ C[Ag,Au60Ag40]      0.402         8.1e-5           0.0             0
.0             0.0             4.98218e-5     -4.98218e-5       4.84855e-5 
    -4.8 ⋯
   2 │ Az[Ag,Au60Ag40]   107.868         0.0              4.0e-8          0
.0             0.0            -9.1691e-11      9.1691e-11       0.0        
     0.0
   3 │ C[Au,Au60Ag40]      0.595         0.0              0.0             0
.000144        0.0            -5.98419e-5      5.98419e-5      -5.82369e-5 
     5.8
   4 │ Az[Au,Au60Ag40]   196.967         0.0              0.0             0
.0             1.6e-11         2.00857e-14    -2.00857e-14      0.0        
     0.0
   5 │ A[Ag,Au60Ag40]      0.552312      4.98218e-5      -9.1691e-11     -5
.98419e-5      2.00857e-14     5.5513e-5      -5.5513e-5        5.40241e-5 
    -5.4 ⋯
   6 │ A[Au,Au60Ag40]      0.447688     -4.98218e-5       9.1691e-11      5
.98419e-5     -2.00857e-14    -5.5513e-5       5.5513e-5       -5.40241e-5 
     5.4
   7 │ N[Ag,Au60Ag40]      0.40321       4.84855e-5       0.0            -5
.82369e-5      0.0             5.40241e-5     -5.40241e-5       5.25751e-5 
    -5.2
   8 │ N[Au,Au60Ag40]      0.59679      -4.84855e-5       0.0             5
.82369e-5      0.0            -5.40241e-5      5.40241e-5      -5.25751e-5 
     5.2
   9 │ MeanZ[Au60Ag40]    65.899         0.003807         0.0             0
.011376        0.0            -0.00238589      0.00238589      -0.0023219  
     0.0 ⋯
  10 │ MeanAz[Au60Ag40]  160.558         0.00873732       1.608e-8        0
.0283632       9.52e-12       -0.00641268      0.00641268      -0.00624068 
     0.0
  11 │ Σ[Au60Ag40]         0.997         8.1e-5           0.0             0
.000144        0.0            -1.00202e-5      1.00202e-5      -9.75142e-6 
     9.7
                                                                           
                                                                    4 colum
ns omitted

To access a single value, you can use bracket notation and the label associated with the desired parameter.

afs[MeanAz(mat)], afs[AtomicFractionLabel(mat,n"Au")], afs[NormMassFractionLabel(mat,n"Au")]
(161 ± 3, 0.4477 ± 0.0075, 0.5968 ± 0.0073)

Or you can iterate over all the labels. Note this style of presentation is suitable if these numbers are to be reported as the final value in a calculation. The full values+covariance matrix representation is required if the values will be used in subsequent calculations.

map(lbl->(lbl => afs[lbl]),labels(afs))
11-element Vector{Pair{A, UncertainValue} where A}:
   C[Ag,Au60Ag40] => 0.4020 ± 0.0090
  Az[Ag,Au60Ag40] => 107.8682 ± 0.0002
   C[Au,Au60Ag40] => 0.595 ± 0.012
  Az[Au,Au60Ag40] => 196.9666 ± 0.0000
   A[Ag,Au60Ag40] => 0.5523 ± 0.0075
   A[Au,Au60Ag40] => 0.4477 ± 0.0075
   N[Ag,Au60Ag40] => 0.4032 ± 0.0073
   N[Au,Au60Ag40] => 0.5968 ± 0.0073
  MeanZ[Au60Ag40] => 66 ± 1
 MeanAz[Au60Ag40] => 161 ± 3
      Σ[Au60Ag40] => 0.997 ± 0.015

Let's time this...

using BenchmarkTools
@btime mf2comp( mat, inputs);
68.400 μs (826 allocations: 100.61 KiB)

Not too shabby!?