# Bounded approximation to a bounded function

I have a non-negative function $f(x) \ge 0$ defined on the interval $[a,b]$. I would like to have a finite-dimensional approximation to this function that is guaranteed to be non-negative on $[a,b]$. What would be a good way to do this (say assuming $f$ is a smooth function)?

The reason I want to do this is that I would like to solve a functional equation $T(f)=0$ by using a collocation method and $T$ is defined only for non-negative $f$.

• How accurate an approximation do you want ? If you do piecewise linear interpolation after making a partition as in FEM, you will get a positive approximation. Other option is as in the answer of David Z. You can make a transformation $g(x) = \log(f(x)+1)$ to avoid zero values. – cfdlab May 7 '17 at 3:53

## 2 Answers

You could try approximation by Bernstein polynomials. For the interval $[0,1]$, they are defined by $$B_n(f)(x)=\sum^n_{k=0}\binom{n}{k}\,f\left(\frac{k}{n}\right)\,x^k\,(1-x)^{n-k}.$$ Those are naturally non-negative for non-negative $f$. Approximation order is not exciting, though, and the resulting system of equations may have bad condition.

My first thought is to use a logarithmic change of variables, $g(x) = \ln f(x)$, then rewrite your functional equation in terms of $g$. Of course, this can be problematic if $f$ is zero at many points. If it's acceptable for your use case, you can put a lower bound on the log-transformed function, $$g(x) = \ln \max\bigl(f(x), C\bigr)$$ where $C$ is some small positive constant like $10^{-100}$ or $10^{-40}$. This means that $g$ will no longer be smooth, but hopefully you can still come up with a smooth approximation to it that will be always nonnegative.

• Might it not be easier to use $g(x)=\sqrt{f(x)}$, since zero points are not an issue here and the square of the approximation of $g(x)$ would be slightly cheaper to evaluate than exponentiation. – fibonatic May 8 '17 at 1:17
• Using sqrt doesn't provide the main benefit of logs, though, namely that the range of $g$ corresponding to positive $f$ is unbounded. – David Z May 8 '17 at 1:53