# Smoothing of a step function using smoothstep. (Curve fitting)

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.

• You question is unclear to me. What do yo mean by 'Smooth' ? Where does the problem come from? – AnyAD Feb 23 '19 at 21:48
• Sorry, actually we have a step function, darkened lines in the figure and since it is not continuous and smooth we try to make it smooth by inserting a function which is smooth at both the ends, for this it is recommended to use the function $f = 3x^2 -2x^3$, but I am finding it difficult to fit the function in between 2/3 to 5/6..en.m.wikipedia.org/wiki/Smoothstep – BAYMAX Feb 23 '19 at 21:58
• that is because your function looks misaligned... the value at $x=\frac{2}{3}$ is not 0, when it should be... I think you just messed up while solving one of the differential equations – Hiten Feb 23 '19 at 23:07

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).$$