1

Does anyone know the name of this algorithm for finding the inverse of a function? I came up with it for solving a particular problem, but the algorithm is so simple that I think it must be known already. I just can't find it anywhere.

Given some value $y \in \mathbb{R}$ and function $f : \mathbb{R} \rightarrow \mathbb{R}$, we want to find the value $x \in \mathbb{R}$ so that $f(x) = y$. We do not know how $f$ is defined in general so it should be considered a "black box".

The algorithm consists of starting with some guess $x_0$ and then iterating as follows: $$ x_{i+1} = x_i \cdot \frac{y}{f(x_i)} $$ so the value $x_{i+1}$ is simply the value $x_i$ multiplied by the fraction between $y$ and $f(x_i)$. Intuitively this works if a change in $x$ corresponds roughly to a change in $y$, as we keep adjusting $x$ by how much $f(x)$ is off from $y$ until we are close enough.

Here is an example in Python where the function is $f(x) = |x|^a$ for some $a>0$:

import numpy as np

def f(x, a): return np.abs(x) ** a

def solve(x_start, y, a, num_iter=20): x = x_start

for i in range(num_iter):
    f_x = f(x, a)
    print(f'i={i}\tx={x:.3e}\tf(x)={f_x:.3e}')
    x = x * y / f_x

Here is a test-run with $x_0=0.1$, $y=4.321$ and $a=0.5$ (i.e. the square-root). After about 20 iterations the algorithm has converged to the correct solution:

solve(x_start=0.1, y=4.321, a=0.5)

Output:

i=0 x=1.000e-01 f(x)=3.162e-01 i=1 x=1.366e+00 f(x)=1.169e+00 i=2 x=5.051e+00 f(x)=2.247e+00 i=3 x=9.711e+00 f(x)=3.116e+00 i=4 x=1.347e+01 f(x)=3.670e+00 i=5 x=1.586e+01 f(x)=3.982e+00 i=6 x=1.721e+01 f(x)=4.148e+00 i=7 x=1.792e+01 f(x)=4.234e+00 i=8 x=1.829e+01 f(x)=4.277e+00 i=9 x=1.848e+01 f(x)=4.299e+00 i=10 x=1.858e+01 f(x)=4.310e+00 i=11 x=1.862e+01 f(x)=4.315e+00 i=12 x=1.865e+01 f(x)=4.318e+00 i=13 x=1.866e+01 f(x)=4.320e+00 i=14 x=1.867e+01 f(x)=4.320e+00 i=15 x=1.867e+01 f(x)=4.321e+00 i=16 x=1.867e+01 f(x)=4.321e+00 i=17 x=1.867e+01 f(x)=4.321e+00 i=18 x=1.867e+01 f(x)=4.321e+00 i=19 x=1.867e+01 f(x)=4.321e+00

For this particular function $f(x) = |x|^a$ the algorithm works until $a=2$ at which point the algorithm starts to behave strangely, and for $a>2$ it seems to diverge rapidly.

I am using this algorithm to solve a problem where $x$, $y$, and $f(x)$ are all vectors, and it works really well for my problem. So I wonder if the algorithm and its convergence properties are already known under some name?

Thanks!

  • Somebody immediately downvoted this question after I had posted it. Should I take that to mean, that we are not supposed to ask questions here anymore?! – questiondude Jan 24 '22 at 10:48

1 Answers1

2

This is called a fixed-point method.

If it converges, it will obviously converge to a value such that

$$x_{\infty}=x_\infty\frac y{f(x_\infty)}$$ or $$y=f(x_\infty).$$

Depending on $f$ and $y$, the iterations can converge or not. Convergence criteria are known. They essentially say that a new iterate must be closer to the solution. https://en.wikipedia.org/wiki/Fixed-point_iteration


When the function is differentiable, one can use the so-called Newton's iterations (also a fixed-point method),

$$x_{i+1}=x_i-\frac{f(x_i)-y}{f'(x_i)}$$ which converge very quickly in general.

enter image description here

  • 2
    Note that use of Newton's method requires that not only does the derivative exist but that it can be computed effectively. – Somos Jan 22 '22 at 18:32
  • Newton's iteration does not necessarily converge, see for example https://math.stackexchange.com/q/1472515/42969. – Martin R Jan 22 '22 at 19:54
  • @MartinR: that's why I said in general. –  Jan 23 '22 at 13:21
  • Thanks for the quick reply! A few more questions: 1) Did you write the fraction for the converged value upside-down? 2) The Wikipedia page shows the update-rule is of the form $x_{i+1} = f(x_i)$, so does my "fractional" update-rule have a special name that I might be able to find some literature on? 3) Please have a look at this question as that is the problem I am actually solving with this little algorithm, but nobody has been able to answer my questions, so perhaps you can? Thanks again! – questiondude Jan 24 '22 at 10:47
  • sorry, typo; but both are possible. 2) I doubt it. Alternative forms can be used to meet the convergence criteria, this is case-dependent. The ratio form can break if $f(x)=0$.
  • –  Jan 24 '22 at 11:11
  • How would you reformulate my ratio-based update-rule to a non-ratio update-rule for finding the inverse of a function? And why is that better? – questiondude Jan 24 '22 at 11:17
  • @questiondude: stop believing that the ratio form always converges and is a panacea. –  Jan 24 '22 at 11:20
  • @Somos: why this remark ? The function itself must also be computed effectively. –  Jan 24 '22 at 11:29
  • @BobbyLaspy I know the ratio-form doesn't always converge, and I wrote that in my question. But is there another and possibly better way of finding the inverse of a function without using derivatives? – questiondude Jan 24 '22 at 12:53
  • 1
    @questiondude: there are many methods to solve nonlinear univariate equations. This is a big chapter in numerical analysis. https://en.wikipedia.org/wiki/Root-finding_algorithms Without derivatives, regula falsi is a good choice. For a bulletproof method, check Brent's. But more than anything, understanding the function behavior is a prerequisite. –  Jan 24 '22 at 13:21
  • @BobbyLaspy Yes, the function must be computed effectively, but if it is a black box, for example, then how to calculate the derivative? At most, you can use updated difference quotients to approximate the derivative at a point. If you have the full definition or source for the function, then in that case, you may use Automatic differentiation to compute the derivatives. – Somos Jan 24 '22 at 17:34
  • @Somos: purchase the optional derivative accessory that comes with the black box. PS: the derivative of $\sqrt x$ is $\dfrac1{2\sqrt x}$. –  Jan 24 '22 at 17:40
  • Thanks again for answering this, I have marked this post as the correct answer. If anyone in the future has more information about this "ratio" version of a fixed-point iteration, then please write another post below with your insights. – questiondude Feb 01 '22 at 13:51