# What are systematic ways of approximating a non-smooth (non-continuously differentiable) system dynamic to be n-smooth?

I have a system dynamic that is non-smooth because it has several signum and absolute value functions in it (three-tank level control). I can obviously choose different sigmoid functions to approximate the dynamics in a way that they become n-times continuously differentiable. Can somebody point me out to a systematic approach for doing this? Or are there even some integrators that can automatically deal with the discontinuities?

I can think of many ways to approximate the functions but it is difficult for me to decide on the "best" one. Right now I would base my decision on the following criteria:

• smoothness (differentiability class)

• numerical computation effort (especially concerning integration)

An example term that I would want to be smooth would be:

$$h(x) = \mathrm{sign}(x_1 - x_2) \sqrt{|x_1 - x_2|}$$

The context of my question is nonlinear model predictive control.

Assuming $$x\neq0$$ we can say that:

$$\mathrm{sign}(x_1 - x_2) = \frac{x_1 - x_2}{|x_1 - x_2|}$$

One of the approximations that I "tested" (How would I do this properly?) is:

$$|x_1 - x_2| \approx \sqrt{(x_1 - x_2)^2 + \epsilon}$$

with $$\epsilon \ll 1$$.

In my case I chose $$\epsilon = 10^{-6}$$ by trade off between smoothing and proper representation around 0.

Two systematic ways of smoothing a function $$h$$ would be:

1. Join the piecewise smooth parts of your function using Hermite interpolation so that the derivatives are matched to your satisfaction.

2. Convolve your function $$h(x)$$ with a heat kernel of the form $$f(x) = \frac{\exp\left\{-\frac{x^2}{2 \sigma^2}\right\}}{\sqrt{2 \pi \sigma^2}}$$ so that instead of working with $$h(x)$$ you would deal with

$$g(x) = \int_{-\infty}^{\infty} f(x - y) h(y) \, \mathrm{d} y.$$

The $$\sigma > 0$$ parameter determines how close $$g$$ is to $$h$$ and by the properties of the solution to the heat equation, it is guaranteed that $$g$$ is infinitely smooth.

Example for second approach

An example of the second approach on $$h(x) = \text{sign}(x) \, \sqrt{| x |}$$, which is non-smooth at $$x=0$$, using $$\sigma$$ values 0.05, 0.1 and 0.01 is shown in the figure below. MATLAB (2019a) code for symbolic integration and plotting:

syms x_1 x_2 x_int x x_hk sigma
h(x_1, x_2) = sign(x_1-x_2)*sqrt(abs(x_1-x_2))
h(x_int) = subs(h(x_1, x_2), x_1-x_2, x_int)

heat_kernel(x_hk, sigma) = exp(-(x_hk)^2/(2*sigma^2))/(sqrt(2*pi*sigma^2))
assume(sigma, {'real', 'positive'})
g(x, sigma) = int(heat_kernel(x-x_int, sigma)*h(x_int), x_int, -inf, inf)

fplot(h(x_int), [-0.4, 0.4])
hold on
fplot(g(x, 0.05), [-0.4, 0.4])
fplot(g(x, 0.1), [-0.4, 0.4])
fplot(g(x, 0.01), [-0.4, 0.4])
legend(["h(x)", "g(x, 0.05)", "g(x, 0.1)", "g(x, 0.01)"], 'Location', 'NorthEastOutside')

• Regarding the second approach: This does not result in a simple, analytic expression (composed of elementary functions) in the sense that I could implement it in an optimization code without solving the integral every time the function g(x) is evaluated. Is that right? Thanks a lot for your answer, I will take a look on Hermite interpolation now. – hcl734 Jun 17 at 7:05
• That's right. In general, you won't get closed-form expressions out of the second approach and you'll have to evaluate the convolution numerically. – Juan M. Bello-Rivas Jun 17 at 14:22
• Regarding 2.: [Intro to Hermite Interpolation] I want e.g. $h(x)$ to become $C^1$. I am choosing points $x_1 < 0$, $x_2 = 0$ and $x_3 > 0$ to interpolate between and I demand the following for my approximation function $g(x)$ around 0: $$g(x_1) = h(x_1)\\ g'(x_2=0) = C\\ g(x_3) = h(x_3)$$ with $C\in \mathbb{R}>>0$ And obtain g from the Hermite interpolation. Defining then $h_{\text{smooth}}(x) = \left\{\begin{matrix} & h(x): x \in (x_1, x_3)\\ & g(x): x \in \mathbb{R} \setminus (x_1, x_3) \end{matrix}\right.$ . : youtube.com/watch?v=bPFRSFLWi2k – hcl734 Jun 17 at 15:03