1function Xval = ljcd_interpolate(nvec, cutoffs, table, K)
2% LJCD_INTERPOLATE Multi-linear interpolation
for LJCD scaling tables
4% Xval = LJCD_INTERPOLATE(nvec, cutoffs, table, K)
6% Performs multi-linear interpolation of a throughput value from an LJCD
7% scaling table
for non-integer population vectors.
10% nvec - [n1, n2, ..., nK] continuous population vector (clamped to cutoffs)
11% cutoffs - [N1, N2, ..., NK] per-
class cutoffs
12% table - Linearized throughput table (1-D array indexed by ljd_linearize)
16% Xval - Interpolated throughput value
18% For K
classes, interpolates between 2^K corner points of the hypercube
19% containing the population vector
using multi-linear interpolation.
21% Copyright (c) 2012-2026, Imperial College London
24% Get floor and ceiling
for each dimension
29nFloor = max(0, min(nFloor, cutoffs));
30nCeil = max(0, min(nCeil, cutoffs));
32% Compute fractional parts (weights)
35% Handle edge
case: all integer values
36if all(abs(frac) < 1e-10)
37 idx = ljd_linearize(nFloor, cutoffs);
38 if idx <= length(table)
46% Multi-linear interpolation over 2^K corners
50for corner = 0:(numCorners - 1)
51 % Build corner point: bit i determines floor (0) or ceil (1) for class i
57 % Use ceiling for this dimension
58 cornerPoint(i) = nCeil(i);
59 weight = weight * frac(i);
61 % Use floor for this dimension
62 weight = weight * (1 - frac(i));
66 % Look up table value at corner point
67 idx = ljd_linearize(cornerPoint, cutoffs);
68 if idx <= length(table)
69 Xval = Xval + weight * table(idx);