# Approximation matching asymptotes

**URL:** <https://discourse.julialang.org/t/approximation-matching-asymptotes/72648>\
**Category:** Numerics\
**Tags:** question\
**Created:** [December 6, 2021, 11:20am UTC](https://discourse.julialang.org/t/approximation-matching-asymptotes/72648 "2021-12-06T11:20:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 6, 2021, 11:20am UTC](https://discourse.julialang.org/t/approximation-matching-asymptotes/72648/1 "2021-12-06T11:20:52Z")

</div>

I have a function f: \mathbb{R} \to \mathbb{R} that is expensive to calculate (implicitly defined, needs iterative methods). But otherwise f is well-behaved: continuous, differentiable, and strictly increasing on all the domain.

It would be nice to use an approximation, but I really need the whole domain. I know that the limits converge to an asymptote, ie

\lim\_{x\to\infty} \frac{f(x)}{x} = a \quad\text{and}\quad \lim\_{x\to-\infty} \frac{f(x)}{x} = b

One thing that occured to me is to define a function g with the same asymptotic behavior that is cheap to evaluate, and approximate f - g with a rational transformation of Chebyshev polynomials to \mathbb{R}.

However, g should be smoothly differentiable because I need derivatives, so eg

```julia
g(x) = (x > 0 ? a : b) * x

```

is not good enough.

Any suggestions for specific forms of g or other approaches would be appreciated.

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [December 6, 2021, 11:33am UTC](https://discourse.julialang.org/t/approximation-matching-asymptotes/72648/2 "2021-12-06T11:33:59Z")

</div>

Sigmoid or tanh can be made to give that.

```julia
f(x) = x*((a+b)+(a-b)*tanh(x))/2

```

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [December 6, 2021, 12:53pm UTC](https://discourse.julialang.org/t/approximation-matching-asymptotes/72648/3 "2021-12-06T12:53:11Z")

</div>

Use TransformVariables 😉 On top of a regular approximator that is.

---

<div class="post-metadata">

**Author:** ![cgeoga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cgeoga/32/216186_2.png) [@cgeoga](https://discourse.julialang.org/u/cgeoga)\
**Post date:** [December 6, 2021, 7:36pm UTC](https://discourse.julialang.org/t/approximation-matching-asymptotes/72648/4 "2021-12-06T19:36:46Z")

</div>

If you think a CDF would be appropriate, and particularly if you’re concerned with the rate at which f approaches its asymptotes, the CDF of [this distribution](https://onlinelibrary.wiley.com/doi/abs/10.1002/env.2658) is available in [this package](https://github.com/mlkrock/BulkAndTails.jl) and could easily be transformed to fit your needs. It is a seven parameter family of univariate distributions that contains a lot of natural special cases like normal and T-distributions as well as covering a very wide range of tail behaviors. The derivative is of course a PDF that is very convenient to use as well. So if any univariate parametric CDF function would work, this is probably a pretty good contender.
