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!