Ask Your Question
5

Interpolating function?

asked 2011-03-07 19:56:56 +0100

Mike Witt gravatar image

updated 2015-01-22 21:33:32 +0100

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
5

answered 2011-03-08 14:58:24 +0100

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

Comments

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

FrédéricC gravatar imageFrédéricC ( 2015-02-06 11:02:18 +0100 )edit
5

answered 2011-03-07 20:08:09 +0100

Shashank gravatar image

updated 2011-03-07 20:08:22 +0100

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...

edit flag offensive delete link more

Comments

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

Mike Witt gravatar imageMike Witt ( 2011-03-07 20:49:20 +0100 )edit
1

answered 2016-02-25 10:37:49 +0100

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

3 followers

Stats

Asked: 2011-03-07 19:56:56 +0100

Seen: 6,284 times

Last updated: Feb 25 '16