Which type of equation produce this kind of multiple decay function? I am working on an algorithm to update a value. One part of it reqires a value to be updated in a way that is drawn on a picture here:

Could anyone please point me in the right direction, to find an equation of a function like this? Could be either first or the second from the picture.
Thanks
 A: Notice that both of these functions look like familiar, continuous functions on certain intervals. This should tell you that it will be easier to define them as piecewise functions.
I'll walk you through building a function like in the first picture. It looks like you want a continuous function that is piecewise linear, increases from to a maximum $M$ and decreases from $M$ to $0$ on each interval where a "spike" occurs. Let's say that the $n$-th interval with such a spike is $I_n = \lbrack a_n, b_n\rbrack$, and let's also assume that we know the point $x_n \in I_n$ at which $f(x_n) = M$. Then we have no option regarding how to define our function! The slope of $f(x)$ for $a_n < x < x_n$ must then be
$\frac{M}{x_n - a_n}$ and similarly the slope of $f(x)$ for $x_n < x < b_n$ must be $-\frac{M}{b_n - x_n}$. Using this and $f(a_n) = f(b_n) = 0$ gives us that
$$
f(x) = \begin{cases}
           \frac{M}{x_n-a_n} x -\frac{M}{x_n-a_n} a_n &\text{ if }x \in \lbrack a_n, x_n\rbrack\\
          -\frac{M}{b_n-x_n} x +\frac{M}{b_n-x_n} b_n &\text{ if }x \in \lbrack x_n,b_n\rbrack,
       \end{cases}
$$
for each $n$. For example, if you wanted $I_n = \lbrack n^2,(n+1)^2 \rbrack$, $M = 1$, and $f(n+1) = 1$ for each $n \geq 0$, then
$$
f(x) = \begin{cases}
           x - n^2 &\text{ if }x \in \lbrack n, n+1\rbrack\\
          -\frac{1}{n^2 + n} x +\frac{1}{n^2+n}(n+1)^2 &\text{ if }x \in \lbrack n+1,(n+1)^2\rbrack,
       \end{cases}
$$
does the trick.
For the second function, what needs to be modified in this construction? It looks like your function should no longer be linear on the right-hand side of where it peaks. So you could try, e.g., to replace the definition of $f(x)$ above on $\lbrack x_n,b_n\rbrack$ with a higher-degree polynomial. For example, $f(x) = \frac{M}{(a_n-b_n)^2}(x-b_n)^2$ for $a_n < x < x_n$ could work.
