Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

Fortran library for curve fitting with constraints

quentinz
Beginner
1,865 Views
Hi all,
I'm quite new at this so please excuse me if I did not see a thread that would already answer my question.
I am looking for a routine that would be able to fit a polynomial equation to a large set of data. But there is a slight twist: I need this function to be strictly monotonous; the first derivative should be strictly positive over the whole domain ofinterest, and thesecondderivative should be positive or null over the domain. (I was trying to use excel as a first go, but the resulting fitting curve was oscillating, I can't have that)
I know it is quite straightforward to check the first and second derivative of a polynomial equation when we have its coefficients, but how can I use this to constrain my fitting curve?
Thank you very much for your help
Cheers
Quentin
0 Kudos
3 Replies
Paul_Curtis
Valued Contributor I
1,865 Views
The code in the att. file performs a polynomial fit of arbitrary order to x,y data arrays.

Since, as noted, derivitives are easy to check, presumably this code will point the way, and these routines can be imbedded (by you) in a larger code context which prepares the raw data, and then evaluates the fit according to your criteria in some iterative manner.

The evaluation may be monotonous, but presumably you will be able to find a fit which is sufficiently monotonic.
0 Kudos
quentinz
Beginner
1,865 Views
Thank you Paul for your answer.
I don't quite understand how your code works though. could you please add some comments or at least explain what each subroutine is doing so that I can understand and modify your code to fit my needs.
In your program do you enter the X and Y values manually here:
! raw data to be fit
INTEGER, PARAMETER :: nvals = ! YOUR POINTCOUNT
REAL, DIMENSION(nvals) :: x = !(/ YOUR x DATA HERE /)
REAL, DIMENSION(nvals) :: y = !(/ YOUR y DATA HERE /)


I think if you were able to explain the function of each subroutine I should be able to get it but without any comment it is very hard to understand what it is doing.
Cheers
Quentin
0 Kudos
Paul_Curtis
Valued Contributor I
1,865 Views
The x() and y() arrays can be created, read or accessed in whatever manner you want; the code sample is just that, a sample, and you will need a bit of extra surrounding structure for your application, in which presumably the data will be fit iteratively multiple times until your monotonicity criterion is met.

The polynomial fit routine is an F90 update of SVDFIT which possibly came from Numerical Recipes or some similarly venerable reference; google provides tons of info on SVDFIT, it's well-known and well-proven.
0 Kudos
Reply