First time here? Check out the FAQ!

Ask Your Question
5

Interpolating function?

asked 14 years ago

Mike Witt gravatar image

updated 10 years ago

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.

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
5

answered 14 years ago

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')
Preview: (hide)
link

Comments

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

FrédéricC gravatar imageFrédéricC ( 10 years ago )
5

answered 14 years ago

Shashank gravatar image

updated 14 years ago

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

Preview: (hide)
link

Comments

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

Mike Witt gravatar imageMike Witt ( 14 years ago )
1

answered 9 years ago

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
Preview: (hide)
link

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: 14 years ago

Seen: 6,410 times

Last updated: Feb 25 '16