Ask Your Question

Interpolating function?

asked 2011-03-07 12:56:56 -0500

Mike Witt gravatar image

updated 2015-01-22 14:33:32 -0500

FrédéricC gravatar image

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 flag offensive close merge delete

3 answers

Sort by » oldest newest most voted

answered 2011-03-07 13:08:09 -0500

Shashank gravatar image

updated 2011-03-07 13:08:22 -0500

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

edit flag offensive delete link more


This looks like the kind of thing that I need. Thanks!

Mike Witt gravatar imageMike Witt ( 2011-03-07 13:49:20 -0500 )edit

answered 2011-03-08 07:58:24 -0500

Volker Braun gravatar image

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)
sage: sin(2.5)
sage: plot(interpolation,(0,10)) + list_plot(values) + plot(sin,(0,10),color='red')
edit flag offensive delete link more


Correct, but this does not allow to ask for values outside the interpolation range.

FrédéricC gravatar imageFrédéricC ( 2015-02-06 04:02:18 -0500 )edit

answered 2016-02-25 03:37:49 -0500

FrédéricC gravatar image

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2011-03-07 12:56:56 -0500

Seen: 1,959 times

Last updated: Feb 25 '16