Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussions

Fortran library or subroutine needed for curve fitting

eriehml
Novice
8,278 Views
Hello all.
I am physics grad. student and I am returning to coding after 15 years so have some patience with me. I have experimental data points, X and Y which need to be fitted to an exponential or forth order polynomial (no other order is necessary and I could use forth order polynomial only if it easier). The purpose of the fitting is to subtract background. These X and Y are photoemission data (Valence Band) to be precise. So it is only necesarry to fit the curve (exponential or forth order polynomial) to the firsts and lasts data points. After the fit is obtained it will correspond to the background. Then I can subtract at any X, Y the background just calculated. Online I found this NAG library but I can not download anything but pdf files. In the NAG library there is a subroutine called E02ADF which might help me do the fiiting but I can not download it, any body knows how access NAG downloads? Either this subroutine or any other you might know I can give it a try as long as I can download it. As far as the minimization algorithm I am really not picky, LM or Simplex will do for me. I am coding in fortran using G77 compiler, windows Vista, plataform Force 2 in my laptop. My code is really simple I just need to handle too many data to fit manually each one of them. I appreciate your time, everyone's. Thanks for your help.
0 Kudos
31 Replies
eriehml
Novice
1,699 Views
Quoting - eos pengwern

Another very good source of Fortran source code for a host of scientific applications is Alan Miller's page. Whereas most of what's on NETLIB is in Fortran 77, Alan Miller's resources are generally in Fortran 90 so are a bit more user-friendly. This may not help you if you're using g77, however.
Thanks. I will check on it.
0 Kudos
eriehml
Novice
1,699 Views
Quoting - Peter
Hmm...I wasn't sarcastic about excel 2007, but it made you laugh !.
Excel can not be underestimated, because it is very powerful tool for most engineering and scientific applications (not powerful than fortran and c++). But based on your requirement it looks like you want fortran subroutines for curve fitting. I did not understand exactly what your project is about, but if you get the data from fortran and then transfer to excel 2007, you might be able to curvefit.

Regarding IVF, its a fortran 90 /03 compiler, which you can code and compile !. For most of my data applications I don't rely on fortran plotting routines. I export the data to matlab or excel which is very easy and time-saving !!
Peter
Hi, yes, the most important tip I have learned from asking for help at this forum is that IVF exists. I didn't know about it. It is very unfortunate though I can not afford $699 at the moment to purchase it (read, student hit by recesion). If I had IVF I would work like you say, edit and compile in IVF and finally plot using Origin or Excel. I find a bit odd that such a simple routine such a polynomial fit is not available out there for use. Thanks, I appreciate your time in trying to help me.
0 Kudos
Steven_L_Intel1
Employee
1,699 Views
Since you have CVF, see if the Compaq Extended Math Library has a routine you need. It is included with CVF.
0 Kudos
eriehml
Novice
1,699 Views
Quoting - Jugoslav Dujic

For polynomial fitting see:

http://rosettacode.org/wiki/Polynomial_Fitting#Fortran

LAPACK is part of Intel MKL, shipped with Intel Fortran Professional 11.0 onwards.
Jugoslav

Hi. I am still trying to solve my fitting problem. Although I have found plenty of very well educated advice at this forum my problem is still unsolved and it seems to get every time more complicated. Anyways. I was considering what you said. And although I do not have MKL nor IVF I have access to LAPACK through netlib.org. I have been looking more in the LAPACK routines offered there but for me is an ocean of confussion with so many options and so much stuff I do not understand. But I was wondering if specifically you know which routine in LAPACK would be useful for me to use to fit a forth order polynomial (or an exponential) to experimental data X and Y. Would you be kind to guide me to a routine I could use for this purpose? I would really appreciate it. Many thanks.
0 Kudos
eriehml
Novice
1,699 Views
Since you have CVF, see if the Compaq Extended Math Library has a routine you need. It is included with CVF.
Steve
Thanks for your reply. I do not have CVF, neither IVF, nor MKL. Yikes! I know pretty bad. I am surprised my simple problem remains unsolved. I thought it would be easy to find a routine to fit a forth order polynomial to simple experimental data X,Y, nothing fancy, any algorithm. But solution remains elusive. I have searched all the options given to me by contributors and I have inspected quite many tools I did not know. Going back to my original question. Do you know of any resource, maybe a book or a website, were I could get a forth order polynomial fit code to fit experimental data? I appreciate very much your help. Thanks.
0 Kudos
Paul_Curtis
Valued Contributor I
1,699 Views
The sample code I posted works perfectly and is a complete solution to your stated problem. If your compiler can't handle this code, get a better compiler.
0 Kudos
David_Kinniburgh
Beginner
1,699 Views
The VA05 routine (Minimize a sum of squares, derivatives not needed) written by Mike Powell many years ago is a fast and reliable unconstrained optimizer that is, I believe, still widely used for model fitting. It is one of the older Harwell Subroutine Library (HSL) packages that are now available in the HSL Archive without charge to anyone for non-commercial exploitation. You will need to register to get it along with its dependencies.

It can fit all sorts of models including polynomial models so will give you added flexibility if you ever want to change your model to a non-poynomial model.

http://hsl.rl.ac.uk/archive/hslarchive.html

0 Kudos
Les_Neilson
Valued Contributor II
1,699 Views
Quoting - eriehml
I am surprised my simple problem remains unsolved. I thought it would be easy to find a routine to fit a forth order polynomial to simple experimental data X,Y, nothing fancy, any algorithm. But solution remains elusive. I have searched all the options given to me by contributors ...

Did you try using the code posted by Paul Curtis?
If your compiler is old F77 and you got compile errors then you will need to backtrackthe codeto F77 style.
Try removing the INTENT(whatever) and the :: from the various places.
If it doesn't understand the INTERFACE block thenremove that too.
If it doesn't have IMPLICIT NONE remove it - but all variables will then be typed according to the first letter of their name. Make sure they are allthe correct type, or explicitly declare them. ( I haven't checked but I think they are all declared anyway )
Replace END SUBROUTINE (and END FUNCTION ) with just END
If it doesn't like DO-END DO then you need to do a bit of work replacing END DO with a labelled CONTINUE and adding the label to the corresponding DO statement.
CYCLE will also need to become a GO TO
0 Kudos
anthonyrichards
New Contributor III
1,699 Views
Since you have CVF, see if the Compaq Extended Math Library has a routine you need. It is included with CVF.

I have looked at the CXML pdf file and found names for linear algebra routines, but nowhere can I find any information on the argument list that each routine requires and hence no information on what the routines expect as input. Where can I find information onhow to call(for example) a routine called DGESSE or whatever for solving an equation such as
AY=X
for column vector X given elements of a n x n matrix A and a column vector Y?

The poster's problem will reduce to this type of equation, since a least-squares fit of a fourth order polynomial to a set of data (xi,yi, i=1,N) reduces to finding Y given a 5 x 5 matrix A containing elements formed by various sums of powers of Xi and vector X elements involve sums over the products ofpowers of xi and yi.
0 Kudos
Steven_L_Intel1
Employee
1,699 Views
CVF provided documentation for CXML - I forget exactly where it was, but it's probably in something like CXMLHELP.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,698 Views
Quoting - eriehml
Jugoslav

Hi. I am still trying to solve my fitting problem. Although I have found plenty of very well educated advice at this forum my problem is still unsolved and it seems to get every time more complicated. Anyways. I was considering what you said. And although I do not have MKL nor IVF I have access to LAPACK through netlib.org. I have been looking more in the LAPACK routines offered there but for me is an ocean of confussion with so many options and so much stuff I do not understand. But I was wondering if specifically you know which routine in LAPACK would be useful for me to use to fit a forth order polynomial (or an exponential) to experimental data X and Y. Would you be kind to guide me to a routine I could use for this purpose? I would really appreciate it. Many thanks.

I thought you had Intel Fortran already.

Have you followed my first link (http://rosettacode.org/wiki/Polynomial_Fitting#Fortran)? The sample code invokes LAPACK routines DGETRF and DGETRI. Their generic (not-too-optimized) versions are freely available at Netlib:

http://www.netlib.org/lapack/double/

Netlib also conveniently gives you a link to "Foo plus dependencies", where you can download all necessary routines at once. You can build the complete code using any F90 compiler, like ifort, gfortran or g95.

I'm not familiar with exponential fitting, sorry.
0 Kudos
Reply