Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Generating a function from data
Replies: 1   Last Post: Mar 11, 2013 10:39 PM

 Derek Goring Posts: 3,644 Registered: 12/7/04
Re: Generating a function from data
Posted: Mar 11, 2013 10:39 PM

On Tuesday, March 12, 2013 2:58:17 PM UTC+13, Jerome wrote:
> >
>
> > I agree with dpb.
>
> > Unless there is a theoretical reason why your function should be a polynomial, why try fitting a polynomial? Or any other function for that matter.
>
> >
>
> > Interpolation, using splines, is the answer. And if splines don't work, try PCHIP - in my experience PCHIP always works, whereas splines don't always.
>
> >
>
> >
>
>
>
>
>
>
>
> There is absolutely no mathematical reason why this function should be polynomial. In fact it is a very bad fit for a polynomial. The only reason I am doing this is so I can define a function that can be used in numerical integration routines as a driving function
>
>
>
> i.e.
>
>
>
> df/dt = terrible polynomial(t) + another function
>
>
>
> (the parameters passed to the ode routines are the polynomial coefficients) I know this is currently a horrendous, and I am trying to improve it
>
>
>
>
>
>
>
> can this spline iterpolation sort this? I am looking into it now, but I am quite bad at matlab and would definetly appreciate comments if you know of anything in particular.

There's nothing much to look into.
help interp1
gives it all.
You will probably want to invoke this:
PP = INTERP1(X,Y,METHOD,'pp')
described lower down in the help so that you don't have to recalculate the knots everytime you evaluate your function.

help ppval
will also be useful.