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)
Labels | Values | C[Ag,Au60Ag40] | Az[Ag,Au60Ag40] | C[Au,Au60Ag40] | Az[Au,Au60Ag40] | |
---|---|---|---|---|---|---|
C[Ag,Au60Ag40] | 4.02e-01 | (9.00e-03)² | 0.00e+00 | 0.00e+00 | 0.00e+00 | |
Az[Ag,Au60Ag40] | 1.08e+02 | ± | 0.00e+00 | (2.00e-04)² | 0.00e+00 | 0.00e+00 |
C[Au,Au60Ag40] | 5.95e-01 | 0.00e+00 | 0.00e+00 | (1.20e-02)² | 0.00e+00 | |
Az[Au,Au60Ag40] | 1.97e+02 | 0.00e+00 | 0.00e+00 | 0.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)
Labels | Values | C[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+00 | 0.00e+00 | 0.00e+00 | 4.98e-05 | -4.98e-05 | 4.85e-05 | -4.85e-05 | 3.81e-03 | 8.74e-03 | 8.10e-05 | |
Az[Ag,Au60Ag40] | 1.08e+02 | 0.00e+00 | (2.00e-04)² | 0.00e+00 | 0.00e+00 | -9.17e-11 | 9.17e-11 | 0.00e+00 | 0.00e+00 | 0.00e+00 | 1.61e-08 | 0.00e+00 | |
C[Au,Au60Ag40] | 5.95e-01 | 0.00e+00 | 0.00e+00 | (1.20e-02)² | 0.00e+00 | -5.98e-05 | 5.98e-05 | -5.82e-05 | 5.82e-05 | 1.14e-02 | 2.84e-02 | 1.44e-04 | |
Az[Au,Au60Ag40] | 1.97e+02 | 0.00e+00 | 0.00e+00 | 0.00e+00 | (4.00e-06)² | 2.01e-14 | -2.01e-14 | 0.00e+00 | 0.00e+00 | 0.00e+00 | 9.52e-12 | 0.00e+00 | |
A[Ag,Au60Ag40] | 5.52e-01 | 4.98e-05 | -9.17e-11 | -5.98e-05 | 2.01e-14 | (7.45e-03)² | -5.55e-05 | 5.40e-05 | -5.40e-05 | -2.39e-03 | -6.41e-03 | -1.00e-05 | |
A[Au,Au60Ag40] | 4.48e-01 | ± | -4.98e-05 | 9.17e-11 | 5.98e-05 | -2.01e-14 | -5.55e-05 | (7.45e-03)² | -5.40e-05 | 5.40e-05 | 2.39e-03 | 6.41e-03 | 1.00e-05 |
N[Ag,Au60Ag40] | 4.03e-01 | 4.85e-05 | 0.00e+00 | -5.82e-05 | 0.00e+00 | 5.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-05 | 0.00e+00 | 5.82e-05 | 0.00e+00 | -5.40e-05 | 5.40e-05 | -5.26e-05 | (7.25e-03)² | 2.32e-03 | 6.24e-03 | 9.75e-06 | |
MeanZ[Au60Ag40] | 6.59e+01 | 3.81e-03 | 0.00e+00 | 1.14e-02 | 0.00e+00 | -2.39e-03 | 2.39e-03 | -2.32e-03 | 2.32e-03 | (1.04e+00)² | 2.65e+00 | 1.52e-02 | |
MeanAz[Au60Ag40] | 1.61e+02 | 8.74e-03 | 1.61e-08 | 2.84e-02 | 9.52e-12 | -6.41e-03 | 6.41e-03 | -6.24e-03 | 6.24e-03 | 2.65e+00 | (2.56e+00)² | 3.71e-02 | |
Σ[Au60Ag40] | 9.97e-01 | 8.10e-05 | 0.00e+00 | 1.44e-04 | 0.00e+00 | -1.00e-05 | 1.00e-05 | -9.75e-06 | 9.75e-06 | 1.52e-02 | 3.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);
174.200 μs (848 allocations: 99.56 KiB)
Not too shabby!?