Date: Dec 12, 2013 2:48 PM
Author: Derek Goring
Subject: Re: Numerical integration of polyfit coefficients

On Friday, December 13, 2013 7:59:28 AM UTC+13, John D'Errico wrote:
> "Rajin " <patelr37@aston.ac.uk> wrote in message <l8ctcd$jrp$1@newscl01ah.mathworks.com>...
>

> > Hello,
>
> >
>
> > I have the coefficients of a polynomial of order 12 given to me using polyfit (it was fitted to model a probability density function). I now need to use the given polynomial f(x), multiply it by x^2, and integrate it over a given boundary.
>
> >
>
> > I have tried using the integral function: integral(fun,xmin,xmax), where:
>
> > fun = @(x) poly2sym(f) and f is the coefficients given by polyfit, but this doesn't work.
>
> >
>
> > Any ideas? Apologies if this seems trivial, I have tried everything!
>
> >
>
> > Thanks in advance,
>
> > Rajin
>
>
>
> Why use a mack truck to carry a pea to Boston?
>
>
>
> % Assume that p12 is a 12th degree polynomial.
>
> P12 = rand(1,13);
>
>
>
> % Multiply by x^2, to get a 14th degree polynomial
>
> % Remember, these are just the coefficients of the polynomial.
>
> P14 = [P12,0,0];
>
>
>
> % integrate
>
> Pint = [P14./(15:-1:1),0];
>
>
>
> Having done this, use of a 12th degree polynomial like
>
> this is a numerical obscenity. I don't really care who gave
>
> you the polynomial.
>
>
>
> Polynomials are a terrible way to fit distribution functions
>
> in general. Think of it like this: The PDF of these functions
>
> must go to zero at +/- inf. In fact, all of the derivatives
>
> go to zero too. No polynomial has this behavior.
>
>
>
> What tends to happen is the polynomial fits the data
>
> points used in the fit, but then it does execrable, nasty
>
> things between the points. This is a common behavior
>
> of high order polynomials, but it is especially true for
>
> this kind of model.
>
>
>
> So I'd go back to your source, and suggest use of a
>
> better model. A spline is often a good idea. For example
>
> there are very nice shape preserving splines to be found.
>
>
>
> John


My question is: why fit a curve at all?
Why not do numerical integration of the histogram/pdf?