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.
29283 Discussions

Fortran library or subroutine needed for curve fitting

eriehml
Novice
8,303 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
DavidWhite
Valued Contributor II
6,591 Views
Quoting - eriehml
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.

The NAG libraries are probably only available via license. You may want to try Netlib (www.netlib.org) for a range of Fortran and other sources for many statistical and other operations.
0 Kudos
eriehml
Novice
6,591 Views
Thanks. I already had that done and netllib.org libraries where no help, they have a very good search engine so looking for stuff you need is not so painful. Such elementary stuff like what I need I hope is not on license but if NAG has to sell me the subroutine I need then I will be glad to pay. Thanks for your time.
0 Kudos
Peter
Beginner
6,591 Views
Quoting - eriehml
Thanks. I already had that done and netllib.org libraries where no help, they have a very good search engine so looking for stuff you need is not so painful. Such elementary stuff like what I need I hope is not on license but if NAG has to sell me the subroutine I need then I will be glad to pay. Thanks for your time.
NAG libraries are very expensive, if you are just looking for curve fitting.Intel Visual Fortran's (IVF) MKL libraries might be of help. But you need to buy a copy of IVF.
Alternatively try excel 2007!
0 Kudos
eos_pengwern
Beginner
6,591 Views
Quoting - Peter
NAG libraries are very expensive, if you are just looking for curve fitting.Intel Visual Fortran's (IVF) MKL libraries might be of help. But you need to buy a copy of IVF.
Alternatively try excel 2007!

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.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
6,591 Views
Quoting - eriehml
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).

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.
0 Kudos
anthonyrichards
New Contributor III
6,591 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.

Or find a friend with access to MathCad and ask to borrow it. It is very good for curve fitting.
0 Kudos
Greg_T_
Valued Contributor I
6,591 Views
Hello,
Another source for Fortran routines is the NIST "Guide to Available Mathematical Software": http://gams.nist.gov/
I think there are a number of routines related to polynomials and curve fitting. The web site has a search tool and directory tree to find what you're looking for. I've used a few routines from that web site with good success.

Regards,
Greg
0 Kudos
eriehml
Novice
6,591 Views
Quoting - Peter
NAG libraries are very expensive, if you are just looking for curve fitting.Intel Visual Fortran's (IVF) MKL libraries might be of help. But you need to buy a copy of IVF.
Alternatively try excel 2007!
Peter
Thanks for your reply. When I read the "try excel 2007!" I thought, Oh man, people with good sense of humor at this forums, so thanks for that laugh. I had no idea about the Intel Visual Fortran you mentioned so I really appreciate you said it. I am looking more into it as we speak and found only some info at
http://software.intel.com/sites/products/collateral/hpc/compilers/fwin_brief.pdf
but maybe you can answer some of my questions. Is this a stand alone plataform/program so that I can code and compile?, do you know if the it also has some ploting libraries?, can this be installed in a laptop?, any idea of the price? I'll keep looking into it but I would appreciate your comments. I just found out the cost is $699, Oh my!, that is so totally out my budget unless I hit Powerball tonight.
Thanks.
0 Kudos
eriehml
Novice
6,591 Views
Quoting - greg_thorwald
Hello,
Another source for Fortran routines is the NIST "Guide to Available Mathematical Software": http://gams.nist.gov/
I think there are a number of routines related to polynomials and curve fitting. The web site has a search tool and directory tree to find what you're looking for. I've used a few routines from that web site with good success.

Regards,
Greg
Greg
Thanks a lot. I am looking into it.
Erie
0 Kudos
anthonyrichards
New Contributor III
6,590 Views
Quoting - eriehml
Greg
Thanks a lot. I am looking into it.
Erie

I still think that if you want a quick solution with graphical display of results, MathCad is easily the quickest route. I frequently use MathCad 11 to test and debug my algorithms (and for quick display of intermediate results)before reprogramming them in Fortran for speed. You can buy MathCad 11 on E-bay for a pittance compared to getting a complete Fortran compiler + library of math functions. I attach a screen shot showing a sample fitting function that is available to a MathCad user.
0 Kudos
eliosh
Beginner
6,590 Views
Quoting - Peter
Quoting - eriehml
Thanks. I already had that done and netllib.org libraries where no help, they have a very good search engine so looking for stuff you need is not so painful. Such elementary stuff like what I need I hope is not on license but if NAG has to sell me the subroutine I need then I will be glad to pay. Thanks for your time.
NAG libraries are very expensive, if you are just looking for curve fitting.Intel Visual Fortran's (IVF) MKL libraries might be of help. But you need to buy a copy of IVF.
Alternatively try excel 2007!

You can use a free non-commercial copy of the Intel compiler for Linux.
(In this case you do not have to pay for Excel 2007 either ;) )

0 Kudos
Peter
Beginner
6,591 Views
Quoting - eriehml
Peter
Thanks for your reply. When I read the "try excel 2007!" I thought, Oh man, people with good sense of humor at this forums, so thanks for that laugh. I had no idea about the Intel Visual Fortran you mentioned so I really appreciate you said it. I am looking more into it as we speak and found only some info at
http://software.intel.com/sites/products/collateral/hpc/compilers/fwin_brief.pdf
but maybe you can answer some of my questions. Is this a stand alone plataform/program so that I can code and compile?, do you know if the it also has some ploting libraries?, can this be installed in a laptop?, any idea of the price? I'll keep looking into it but I would appreciate your comments. I just found out the cost is $699, Oh my!, that is so totally out my budget unless I hit Powerball tonight.
Thanks.
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 !!
0 Kudos
Paul_Curtis
Valued Contributor I
6,591 Views
See the attached, what the OP actually asked for.
0 Kudos
Paul_Curtis
Valued Contributor I
6,591 Views
My sample program was carved out of some real code, needs a minor correction in the output section, only apparent after uploading:
[cpp]DO j = n1, n2
    xx = x(j)
    yy = pxpand (norder, xx, a)
    WRITE (3,*) xx, y(j), yy, yy-y(j)
END DO
[/cpp]

0 Kudos
eriehml
Novice
6,591 Views
Quoting - Paul Curtis
See the attached, what the OP actually asked for.
Paul
Thanks for sending me the code. My plataform is Force 2.0 and reads only G77 or similar. I am going to download (hopefully I find it for free) a Fortran90 plataform so that I can check your code out. I have too many sets of data that I need to fit and the fit is only for background subtraction and just a part of the data massaging I have to perform. I really appreciate your help. I'll get to work right now and try to find a free fortran 90 compiler and editor to check your code out. Thanks a lot.
0 Kudos
eriehml
Novice
6,590 Views
Quoting - Paul Curtis
My sample program was carved out of some real code, needs a minor correction in the output section, only apparent after uploading:
[cpp]DO j = n1, n2
xx = x(j)
yy = pxpand (norder, xx, a)
WRITE (3,*) xx, y(j), yy, yy-y(j)
END DO
[/cpp]

Paul
Thanks. I managed to download a F95 plataform called PLATO, from Silverfrost which seems to work well. I performed the modifications in the DO LOOP you mentioned. When I compile though I still have problems
in line 434

DO j = order, 2, -1
polyval = xv*(polyval + coeff(j))
END DO

I am not sure what the problem would be, do you?

For starters I am only using

INTEGER, PARAMETER :: nvals = 5 ! YOUR POINTCOUNT
REAL, DIMENSION(nvals) :: x = (/ 1.0, 2.0, 3.0, 4.0, 5.0 /) !(/ YOUR x DATA HERE /)
REAL, DIMENSION(nvals) :: y = (/ 1.0, 16.0, 80.9, 256.5, 625.0 /) !(/ YOUR y DATA HERE /)

! polynomial order for fitting
norder = 4 ! YOUR FIT ORDER

Please let me know. Thanks.
0 Kudos
Paul_Curtis
Valued Contributor I
6,590 Views

This code compiles and runs perfectly under MS5.5, DVF, all CVF through 6.6, all IVF through v11. The svdfit routines are an F90 translation from the original F77 which I think may have come from Numerical Recipes or similar; very old (pre-dates PCs by decades), completely portable and with no vendor-specific features.

If your compiler can't handle this well-proven code and doesn't provide informative error messages, one solution might be to upgrade to a better compiler, maybe from a company that has invested in hosting a user forum for compiler support and language discussions.

FYI, here is the output from this program, using your data, as created by IVF (I have added some column headers):

Fit order is 4
1 -42.02048
2 79.64155
3 -48.84335
4 11.91672
x y polyfit diff.
1.000000 1.000000 0.6944389 -0.3055611
2.000000 16.00000 17.22299 1.222988
3.000000 80.90000 79.06549 -1.834511
4.000000 256.5000 257.7222 1.222229
5.000000 625.0000 624.6935 -0.3065186



0 Kudos
mavlik
Beginner
6,591 Views
Quoting - eriehml
<....> 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?

As I understand, E02ADF is least-squares polynomial approximation.

Try to use this link
http://iranyahoo.nag.com/numeric/fl/manual20/examples/source/e02adfe.f

If you need polynomial interpolation or other algorithms you can find it in "Numerical Recipes in Fortran"
(http://www.nrbook.com/a/)

0 Kudos
eriehml
Novice
6,591 Views
Quoting - Paul Curtis

This code compiles and runs perfectly under MS5.5, DVF, all CVF through 6.6, all IVF through v11. The svdfit routines are an F90 translation from the original F77 which I think may have come from Numerical Recipes or similar; very old (pre-dates PCs by decades), completely portable and with no vendor-specific features.

If your compiler can't handle this well-proven code and doesn't provide informative error messages, one solution might be to upgrade to a better compiler, maybe from a company that has invested in hosting a user forum for compiler support and language discussions.

FYI, here is the output from this program, using your data, as created by IVF (I have added some column headers):

Fit order is 4
1 -42.02048
2 79.64155
3 -48.84335
4 11.91672
x y polyfit diff.
1.000000 1.000000 0.6944389 -0.3055611
2.000000 16.00000 17.22299 1.222988
3.000000 80.90000 79.06549 -1.834511
4.000000 256.5000 257.7222 1.222229
5.000000 625.0000 624.6935 -0.3065186



Paul
Thanks. I see it looks like IVF is necessary, I am stuck on it though because it costs $699 and that is not an option at the moment. Gosh, I didn't think it was going to be hard to find a routine for polynomial fitting using any algorithm. I appreciate your patience and time. Enjoy.
0 Kudos
eriehml
Novice
5,883 Views
Quoting - mavlik

As I understand, E02ADF is least-squares polynomial approximation.

Try to use this link
http://iranyahoo.nag.com/numeric/fl/manual20/examples/source/e02adfe.f

If you need polynomial interpolation or other algorithms you can find it in "Numerical Recipes in Fortran"
(http://www.nrbook.com/a/)

Hi. Yes the E02ADF is a least-squares polynomial fit available through NAG libraries. The link you sent me I had checked on it and it is only an example on how to use e02adf, the actual subroutine is not available. Thanks.
Reply