1
$\begingroup$

I'm currently trying to interpolate three data points $(x_0,y_0)$, $(x_1,y_1)$, and $(x_1,y_1')$ to a logistic-like function, where $y_1'$ is the slope at $(x_1,y_1)$. The function is $$ f(x) = \frac{L}{1+C\cdot\exp(-kx)} $$ where $C$ can be either negative or positive. The solution for assigning $k$, $C$, and $L$ yields $$ \begin{align*} k &= \frac{y_1(y_1-y_0)W_n(\Phi) + y_1'y_0(x_1-x_0)}{y_1(y_1-y_0)(x_0-x_1)}\\ C &= \frac{y_1 - y_0}{y_0\cdot \exp(-k x_0) - y_1 \cdot \exp(-k x_1)}\\ L &= y_1 (1 + C \cdot \exp(-k x_1)) \end{align*} $$ $W_n$ is the Lambert W function, with $n$ being either $0$ or $-1$, depending on a separate condition, and $$ \Phi = \frac{y_1' y_0 \cdot \exp\left(\frac{y_1' y_0 (x_0-x_1)}{y_1 (y_1-y_0)}\right) (x_0-x_1)}{y_1 (y_1-y_0)} $$ The problem I'm running into is that I have many circumstances where both $k$ and $L$ are on the order of magnitude of $\mathcal{O}(10^{-15})$ or smaller. This has caused the resulting logistic fit to be very numerically unstable often providing a step-like function, seen here in red (ignore the blue).

Jagged, step-like logistic interpolation (red) due to floating-point error

where $k=5.4138\times 10^{-16}$, $L=-5.9212\times 10^{-17}$, and $C=-1$. I would like to know if there is any way I can either re-write how I express the logistic function itself or how to express the solutions for $k$, $C$, and $L$ that will regain some precision in the fit.

EDIT: Had the wrong formula for $C$. Fixed now

$\endgroup$
0

0