[Math] Smoothing of a step function using smoothstep. (Curve fitting)

approximation-theorycalculuscurvesgraphing-functions

I was trying to smoothen the step function (zero when $x$ is less than $2/3$ and equal to $1$ when $x$ is greater then $5/6$) as in the picture below. Trying to fit $f$ in between $2/3$ and $5/6$ using smoothstep $f(x)=3x^2- 2x^3$. Also used the stretching/contraction of $x$ axis and translation of $x$ axis but could not actually fit it.

enter image description here

Best Answer

The following function as in your link, $$ \texttt{SmoothStep}:[0,1]\to \mathbb R, \\ \texttt{SmoothStep}(x) = 3x^2 - 2x^3$$ interpolates between 0 and 1 while having zero derivative at the endpoints $0,1$. You want to $(A)$ squish this to an interval of length $\frac56 - \frac23 = \frac16$ and $(B)$ make the function start at $2/3$ instead of 0. Lets do these one at a time.

  • $(A)$ squishing a function horizontally amounts to making the function run through its input faster. For instance $2x$ over $x\in[0,2]$ goes from 0 to 4. If you want it to end up at 4 when $x=0.1$, you're gonna need to use $2(2x/0.1)=40x$ instead. Therefore, to accomplish $(A)$, you want to use $$ f_1(x) = \texttt{SmoothStep}(6x)$$
  • $(B)$ Moving a function to the right corresponds to moving the inputs to the left. This slight awkwardness is behind the fact that e.g. $x-3$ has root $+3$, not $-3$. So our final result is $$ f_2(x) = f_1(x-2/3) = \texttt{SmoothStep}\Big(6(x-2/3)\Big).$$

Plots to verify this is correct:

enter image description here

Related Question