2

Let's say I have the function $$f(x)=\begin{Bmatrix} x & \textrm{,} & \textrm{if } x\leqslant 1.5\\ \frac{x}{3}+1 & \textrm{,} & \textrm{otherwise} \end{Bmatrix}$$ which has a sharp edge at 1.5, i.e. a discontinuity in the first derivative. I would like to smooth that transition with some other function. In practice I would like to set a window around the sharp edge in which the transition happens: $$f(x)=\begin{Bmatrix} x & \textrm{, } & \textrm{if } x\leqslant 1.5-t\\ s(x) & \textrm{, } & \textrm{if } 1.5-t\leqslant x\leqslant 1.5+t\\ \frac{x}{3}+1 & \textrm{, } & \textrm{otherwise} \end{Bmatrix}$$ with s(x) being my transition function and t being half the window width. I could choose a quadratic but that would create a sharp edge in the first derivative (i.e. a discontinuity in the second derivative). I'd like a function f(x) that ends up with no discontinuities in any of the derivatives and is monotonically nondecreasing.

If anyone can point me in the right direction of what I'm looking for, I'd be thankful.

  • 1
    Sorry, I accidentally copied the wrong function. It should be correct now, 1.5x + 3 should've been x/3 + 1 – Agiltohr Jan 12 '20 at 16:49

2 Answers2

3

Take a look at the Wikipedia articles on bump functions and non-analytic smooth functions, in the latter especially the section on smooth transition functions. The function

$$ g(x)=\frac{f(x)}{f(x)+f(1-x)} $$

with $f(x)=\mathrm e^{-\frac 1x}$ has all derivatives zero at $x=0$ and $x=1$, and $f(0)=0$, $f(1)=1$. Here’s the image from Wikipedia:

enter image description here

And here’s a Wolfram|Alpha plot.

Thus the function

$$ h(x)=g(x)a_2(x)+(1-g(x))a_1(x) $$

smoothly interpolates between the functions $a_1(x)$ for $x\le0$ and $a_2(x)$ for $x\ge1$. You can obtain your function $s(x)$ by an appropriate rescaling.

joriki
  • 238,052
0

I see 3 solutions :

1) Convolving the initial function with an adequate bump function (https://en.wikipedia.org/wiki/Bump_function) ; or in general using mollifiers (https://en.wikipedia.org/wiki/Mollifier).

2) Using "clothoids" (aka as "Euler spirals" en.wikipedia.org/wiki/Euler_spiral or Cornu spirals). This kind of curves that have been used for long for the connection of railway straight rails like in your issue.

3) If you are happy with functions that are $C^{n-1}$ but not $C^n$, it suffices to use spline curves of degree $n$.

For example, here is a 3rd degree spline function connecting the first and the second affine functions in the case $t=0.5$ (your notations) giving a $C^2$ but not $C^3$ solution. See the following figure :

enter image description here

Fig. 1 : The connecting third degree spline curve $\frak{S}$ (in red) that guarantees a continuous second derivative everywhere, and in particular at the connection points. The little circles represent the control points of curve $\frak{S}$, i.e., $A(1,1)$, $(4/3,4/3)$, $(5/3,14/9)$, $(2,5/3)$. Please note that the abscissas of $A,B,C,D$ are regularly spaced with $AB$ prolongating the first straight line and $CD$ prolongating the second straight line.

See https://en.wikipedia.org/wiki/Spline_interpolation for an algorithm giving the spline interpolation.

Jean Marie
  • 81,803
  • Thanks for your answer. I'll look into this! – Agiltohr Jan 12 '20 at 18:50
  • I think this solution is C1, but not C2. – bubba Jan 17 '20 at 10:03
  • @bubba : it is $C^2$ because at both extremities we have f''(x)=0 (see https://en.wikipedia.org/wiki/Spline_interpolation) – Jean Marie Jan 17 '20 at 22:28
  • I realize now that there is an $C^{\infty}$ alternative solution by using a so-called "clothoid" (aka as Euler spiral https://en.wikipedia.org/wiki/Euler_spiral or Cornu spiral) – Jean Marie Jan 17 '20 at 22:31
  • @bubba : it is $C^2$ because at both extremities we have f''(x)=0 (see https://en.wikipedia.org/wiki/Spline_interpolation) if we are managing splines, not simple Bezier curves as I wrote at first. Sorry for the confusion. – Jean Marie Jan 17 '20 at 22:34
  • @JeanMarie The connecting curve is just a Bezier cubic, right? I don't see why f"(x) is zero at its end-points.If you want to specify start and end points, start and end slopes, and you also want f"(x) to be zero at both ends, then that's 6 constraints, which is too many for a cubic curve. – bubba Jan 18 '20 at 07:07
  • @bubba In fact, I agree with you that if it was a Bézier curve (my fault to call it a "Bézier" function instead of a "spline" function), it wouldn't work. With a spline curve (here made of 3 B'zier curves, we can fulfill all the constraints (take a look at Figure 2 of the reference I gave https://en.wikipedia.org/wiki/Spline_interpolation). – Jean Marie Jan 18 '20 at 07:44