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

  • 3
    $\begingroup$ 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. $\endgroup$
    – cfdlab
    Commented May 7, 2017 at 3:53

2 Answers 2


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.

  • $\begingroup$ 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. $\endgroup$
    – fibonatic
    Commented May 8, 2017 at 1:17
  • $\begingroup$ Using sqrt doesn't provide the main benefit of logs, though, namely that the range of $g$ corresponding to positive $f$ is unbounded. $\endgroup$
    – David Z
    Commented May 8, 2017 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.