pwtools.num.Spline.invsplev

Spline.invsplev(y0, x0=None, xab=None)[source]

Lookup x for a given y, i.e. “inverse spline evaluation”, hence the name. Find x where y(x) == y0 by calculating the root of y(x) - y0. We can use Newton’s (x0) or Brent’s (xab) methods. Use only one of them. If neither is given, we use xab=[x[0], x[-1]] and Brent.

There are a few caveats. The result depends the nature of the underlying x-y curve (is it strictly monotinic -> hopefully one root or oscillating -> possibly several roots) and on how good x0 or xab are. For instance, a bad x0 will cause the Newton method to converge to a different root (if there is one) or to converge not at all. Or an interval xab which contains no (or several) root(s) will cause the Brent method to error out or give wrong/unexpected results. Always plot you data before using.

Works only for scalar input (one point lookup). For many points, try to construct an inverse spline: Spline(y,x).

Parameters:
  • x0 (float) – start guess for Newton’s secant method

  • xab (sequence of length 2) – start bracket for Brent’s method, root must lie in between

Returns:

xx

Return type:

scalar