# Interpolating function? Does Sage (or python) have anything similar to the MMA InterpolatingFunction?

In other words, I have a 2 dimensional table of data, and I want to create the function u(x,t) such that I can fill it in with the data I have, and then plot it, and do whatever numeric operations with it.

I hope the question makes sense.

edit retag close merge delete

Sort by » oldest newest most voted I have to do it very frequently. I use scipy for that purpose. I am not sure whether you are looking for a analytic function or a callable function. Have a look at following links

http://www.scipy.org/Cookbook/Fitting...

http://docs.scipy.org/doc/scipy/refer...

more

You can use splines to interpolate. For example:

sage: from sage.gsl.all import spline
sage: values = [ (x,sin(x)) for x in range(10)]
sage: interpolation = spline(values)
sage: interpolation(2.5)
0.59648316868924223
sage: sin(2.5)
0.598472144103957
sage: plot(interpolation,(0,10)) + list_plot(values) + plot(sin,(0,10),color='red')

more

Correct, but this does not allow to ask for values outside the interpolation range. For one-dimensional data, here is another possibility, using the lagrange_polynomial method:

sage: data6
[(-1/6, 512/693*sqrt(6)),
(-1/3, 16/15*sqrt(3)),
(-1/2, 1/3*(4*sqrt(2))),
(-2/3, 1/4*sqrt(6)*pi),
(-5/6, integrate(e^(-u)/sqrt(-6/5*e^(-5/6*u) + 6/5), u, 0, +Infinity)),
(-1, 2)]
sage: anneau=RDF['x']
sage: anneau.lagrange_polynomial(data6)
0.0002415622388688374*x^5 + 0.0027759117124809404*x^4 + 0.011064333541062326*x^3 + 0.014644177822466752*x^2 - 0.22142334301181213*x + 1.7724624632331714

more