0

I'm writing an interpolation method without using a library functions which does it directly. The signature of the function is:

def interpolate(self, f: callable, a: float, b: float, n: int) -> callable:
        """
        Parameters
        ----------
        f : callable. it is the given function
        a : float
            beginning of the interpolation range.
        b : float
            end of the interpolation range.
        n : int
            maximal number of points to use.

        Returns
        -------
        The interpolating function.
        """

Right now my implementation is straight forward "Lagrange Interpolation" as explained here: https://www.codesansar.com/numerical-methods/python-program-lagrange-interpolation-method.htm

However, this kind of implementation is O(n^2) and I'm looking for a more efficient solution which runs in O(n).

(Maybe Bézier Curves can help here somehow?)

  • Chebyshev transform will be nlogn. B-splines O(n). – user14717 Feb 06 '21 at 16:08
  • I guess this sort of question should go to the [Computational Science SE](https://scicomp.stackexchange.com). – Lith Feb 06 '21 at 19:37
  • 1
    What are the demands on the interpolation? Just to produce a function table and fill the gaps in a reasonable way? That the resulting function be differentiable of a specific order? That the interpolation be polynomial? – Lutz Lehmann Feb 06 '21 at 20:58

1 Answers1

0

I am doing the same thing and I thought of NumPy elementwise calculation, here is my line of code that solves your question:

for xi, yi in zip(x,y): yp += yi*np.prod((xp-x[x!=xi])/(xi-x[x!=xi]))