# UTCI algorithm

I have been battling with the formula for UTCI. It has such an interesting, regular pattern; I was certain it could be coded into an algorithm more succinctly than coding the full 84-term (1.5 pages worth of page) expression. 22:27, Wednesday August 21st, I have my first (untested) draft of the algorithm:

By working term-by-term through the formula and grouping similar terms, I was able to extract the pattern for the second section (56 terms). This second group can be simplified from 56 terms to 21 terms. Further, the pattern can be expressed in the general form:

$\left\{\;\;(depth - n - k + 1)\; Ta^n\; Pa^k \;\;|\;\; \forall{n} \in (0, 1, .. depth), \forall{k} \in (depth - 1, depth - 2, .., 1)\;\;\right\} \newline where: \newline \indent \indent depth = the\; degree\; of\; the\; polynomial \newline \indent \indent Ta = ambient\; air\; temperature \newline \indent \indent Pa = vapour\; pressure$

An algorithm to generate all 56 terms looks like follows:

int depth = 6;
for (int n = 0; n <= depth; n ++) {
for (int k = (6 - n); k > 0; k --) {

yield (depth - n - k + 1) * Ta**n * Pa**k;
}
}


In Python, this could be written as a generator expression in a single line:

sum((7 - n - k)*Ta**n*Pa**k for n in range(7) for k in range(6 - n, 0, -1))


I have to say I am pretty happy with this. I still have to test it, make sure it actually works 🙂 But the logic is sound. The other challenge I have, is this algorithm doesn’t allow for the weightings applied to each term in the original formula. I need to figure out how to extract these weightings and apply an aggregate weight to the final sum.