Function to find least square cubic polynomial coefficient amongst a x,y dataset

Function to find least square cubic polynomial coefficient amongst a x,y dataset

Hi experts,

I'm looking for a function that would recieve a set of data and would return the coefficent of a 3th degree polynome that match those data at best.

I'm able to do it with excel by ploting the value (x,y) and asking for a polynomial trendline of order 3. Then display the equation on the chart. I'm also able to use the LinEst function of Excel but now I would like to do it in Fortran.

I'm sure that there is already something out there that would do it. Any one know it ?

Many thanks,

Vincent

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I use routine in attachment (uses MKL functions) may be some interfaces are missing, but it can be found in documentation

Attachments: 

AttachmentSize
Downloadapplication/octet-stream polyfit.f901.54 KB

Quba's routine forms the normal equations for the least squares problem explicitly, and then factorizes ATA. This may work for small problems, but this approach is afflicted by bad conditioning. It is far better to use the MKL/Lapack routine specifically designed for such problems, namely, GELS, which uses the QR factorization of A..

For details, see the section "LAPACK Routines: Least Squares and Eigenvalue Problems" in the MKL documentation.

Leave a Comment

Please sign in to add a comment. Not a member? Join today