Don’t.
From [1] : (I copy-paste here because MathJax doesn’t load anywore on my website, so LaTeX doesn’t render for now).
The software then translates the parameters into 2D nodes that will be fed to the interpolation algorithm:
- grey = \{\text{G}_{l} ; \text{G}_{d} \} \\= \{ \frac{- \text{black}_{EV}}{ \text{DR}} ; 0.18^{1/\gamma} \}
- black = \{ 0 ; 0 \}
- white = \{ 1 ; 1 \}
- latitude, bottom = \{ \text{T}_{l} ; \text{T}_{d} \} \\= \{ \text{G}_{l} × \left(1 – \frac{\text{latitude}}{ \text{DR}} \right) ; \text{C} × \left(\text{T}_{l} – \text{G}_{l}\right) + \text{G}_{d} \}
- latitude, top = \{ \text{S}_{l} ; \text{S}_{d} \} \\= \{ \text{G}_{l} + \frac{\text{L}}{\text{DR}} × (1 – \text{G}_{l}) ; \text{C} × (\text{S}_{l} – \text{G}_{l}) + \text{G}_{d} \}
\begin{cases} P_1′(x) &= \text{C}\\ P_1(\text{T}_{l}) &= \text{T}_{d}\\ P_0(0) &= 0\\ P_0′(0) &= 0\\ P_0(\text{T}_{l}) &= \text{T}_{d}\\ P_0′(\text{T}_{l}) &=P_1′(\text{T}_{l}) \\ P_0”(\text{T}_{l}) &=P_1”(\text{T}_{l}) \\ P_2(1) &= 1 \\ P_2′(1) &= 0 \\ P_2(\text{S}_{l}) &= \text{S}_{d} \\ P_2′(\text{S}_{l}) &= P_1′(\text{S}_{l}) \\ P_2”(\text{S}_{l}) &= P_1”(\text{S}_{l}) \\ \end{cases}
Each polynom needs to satisfy 5 conditions, therefore we need 4th order polynoms. Let us parametrize such functions \forall \{x, a, b, c, d, e, f, g, h, i, j, k, l\} \in \mathbb{R}^{13} :
\begin{cases} P_0(x) &= a x^4 + b x^3 + c x^2 + d x + e\\ P_1(x) &= f x + g\\ P_2(x) &= h x^4 + i x^3 + j x^2 + k x + l\\ \end{cases} \\ \Rightarrow \begin{cases} P_0′(x) &= 4 a x^3 + 3 b x^2 + 2 c x + d \\ P_1′(x) &= f \\ P_2′(x) &= 4 h x^3 + 3 i x^2 + 2 j x + k \\ \end{cases} \\ \Rightarrow \begin{cases} P_0”(x) &= 12 a x^2 + 6 b x + 2 c \\ P_1”(x) &= 0 \\ P_2”(x) &= 12 h x^4 + 6 i x + 2 j \\ \end{cases}
This can be split into 3 linear sub-systems for faster resolution, the last two being solvable in parallel :
P_1 : \begin{bmatrix} 1 & 0 \\ \text{T}_l & 1\\ \end{bmatrix} \cdot \begin{bmatrix}f\\g\\\end{bmatrix} = \begin{bmatrix} \text{C}\\ \text{T}_d\\ \end{bmatrix}
P_0 : \begin{bmatrix} 0 & 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 1 & 0\\ \text{T}_l^4 & \text{T}_l^3 & \text{T}_l^2 & \text{T}_l & 1\\ 4 \text{T}_l^3 & 3 \text{T}_l^2 & 2 \text{T}_l & 1 & 0\\ 12 \text{T}_l^2 & 6 \text{T}_l & 2 & 0 & 0\\ \end{bmatrix} \cdot \begin{bmatrix}a\\b\\c\\d\\e\\ \end{bmatrix} = \begin{bmatrix} 0\\ 0\\ \text{T}_d\\ f\\ 0\\ \end{bmatrix}
P_2 : \begin{bmatrix} 1 & 1 & 1 & 1 & 1\\ 4 & 3 & 2 & 1 & 0 \\ \text{S}_l^4 & \text{S}_l^4 & \text{S}_l^2 & \text{S}_l & 1 \\ 4 \text{S}_l^3 & 3 \text{S}_l^2 & 2 \text{S}_l & 1 & 0\\ 12 \text{S}_l^2 & 6 \text{S}_l & 2 & 0 & 0\\ \end{bmatrix} \cdot \begin{bmatrix}h\\i\\j\\k\\l\end{bmatrix} = \begin{bmatrix} 1\\ 0\\ \text{S}_d\\ f\\ 0\end{bmatrix}
Solving the polynomial coefficients for the input nodes can be achieved through a gaussian elimination, then, in a vectorized SIMD/SSE setup of 4 single precision floats using Fused Multiply-Add, a fast evaluation of S(y) should be possible such that:
S(y) = \left[ \begin{bmatrix} e \\ g \\ l\\ 0\\\end{bmatrix}+ y \cdot \left(\begin{bmatrix} d \\ f \\ k\\ 0\\\end{bmatrix} + y \cdot \left(\begin{bmatrix} c \\ 0 \\ j\\ 0\\\end{bmatrix} + y \cdot \left(\begin{bmatrix} b \\ 0 \\ i \\ 0\\\end{bmatrix} + y \cdot \begin{bmatrix} a \\ 0 \\ h \\ 0\\\end{bmatrix} \right) \right) \right) \right] \cdot \begin{bmatrix} (y < \text{T}_l)\\ (\text{T}_l \leq y \leq \text{S}_l)\\ (y > \text{S}_l)\\ 0\\ \end{bmatrix}^T the last matrix being an boolean mask where lines are set to 1 where the condition is met, or 0 otherwise.
Just note that the curve is applied in log normalized space, so y = \dfrac{\log_2 \left(\frac{x}{\text{grey}}\right) – \text{black}_{EV}}{\text{white}_{EV} – \text{black}_{EV}}