← All examples
46

Canonical Grid model

Scientific Matrices — Inspect the Shape

Compare a scalar matrix with a nested-array container and recover a synthetic Beer–Lambert mixture.

Scale
Small
Source
chemistry-matrix-authoring.grid
Length
25 lines
Collection
Advanced language
Level
Intermediate
Runtime
Portable
Version
1.0.0
chemistry-matrix-authoring.grid
Get Grid
MODEL "Scientific Matrices — Inspect the Shape"
DESCRIPTION "Compare a scalar matrix with a nested-array container and recover a synthetic Beer–Lambert mixture."
VERSION "1.0.0"
AUTHOR "Grid Team"
TAGS "chemistry", "spectroscopy", "matrices", "authoring"

# Three wavelengths, two components; absorptivity in L mol^-1 cm^-1.
# Absorbance is dimensionless; the path length is 1 cm.
Absorptivities = {10000,2000;5000,8000;1000,12000}
Absorbances = {0.36;0.39;0.39}
output RecoveredConcentrations = MMULT(
  MINVERSE(MMULT(TRANSPOSE(Absorptivities),Absorptivities)),
  MMULT(TRANSPOSE(Absorptivities),Absorbances)
)
output ReferenceAnswer = "Both concentrations are 0.00003 mol/L (30 micromolar). Normal equations are instructional here; use QR or SVD for uncertain conditioning."

# These are different structures. The second transpose deliberately produces
# an advisory: retain it when the outer-container operation is your intent.
ScalarMatrix = {1,2;3,4;5,6}
NestedRows = [[1,2],[3,4],[5,6]]
output MatrixTranspose = TRANSPOSE(ScalarMatrix)
output OuterTranspose = TRANSPOSE(NestedRows)
output ShapeGuide = "MatrixTranspose is a 2-by-3 scalar matrix. OuterTranspose is a 3-by-1 container whose cells still contain row arrays. To transpose numerical rows, use semicolon-separated matrix syntax."

END MODEL