Given a function f
and a list of interested value [y1, y2, ..., yn]
, how do you do to find the list [x1, x2, ..., xn]
such that f(xi)=yi
for each i
.
I know there are many root finding algorithms and we can use any of those to find the root of f-yi
to find xi
. However, at least for the bisect method, if I can reuse the evaluated values, then the total time should be decreased, especially if evaluating f
is time consuming, right?
For example, using bisect method, I want find the [x1, x2]
such that f([x1, x2])=[1, 5]
. When finding y1=1
, these values are evaluated
+------+-----+----+
| iter | x | y |
+------+-----+----+
| 1 | 8 | 14 |
+------+-----+----+
| 2 | 4 | 6 |
+------+-----+----+
| 3 | 2 | 2 |
+------+-----+----+
| 4 | 1 | 0 |
+------+-----+----+
| 5 | 1.5 | 1 |
+------+-----+----+
and therefore x1=1.5
. When finding y2=5
, if we can make use of the evaluated values and find
+------+-----+---+
| iter | x | y |
+------+-----+---+
| 1 | 3 | 4 | <- because 2, 4 are evaluated
+------+-----+---+
| 2 | 3.5 | 5 |
+------+-----+---+
with less iterations than not using.
Do you know any algorithm that make use of this, any language is fine? Or would you explain why there isn't any?
You can make a function table over the given range, xs=arange(xa,xb,h)
with some sensible values for interval and sample density, compute the function table via ys = f(xs)
and then use reverse interpolation to get the starting point(s) for the root seeking method, xi0 = interp(yi,ys,xs)
. For the bisection or any other bracketing method one could then start with the interval [xi0-h, xi0+h]
.
This is the most systematic use you can make of global information of the function values. The values obtained in the root finder are then too local to contribute essential improvements to the above function table.
But go ahead and experiment. Starting with a large h
and merging the computed values into the table is a bit more of a coding effort, but there might be some cross-over where it indeed produces a more adapted sampling.