1. ## nonlinear curve fitting

hi,

i have a rather long non-linear equation with 8 variables that i need to optimize. is there some package/library of ready-made curve fitting c codes that i can use?

thanks!

2. Have you any idea of the type of curve you need. There are so many.

I suggest you load your data into Excel. That offers a wide range of curve fitting tools. Use this to experiment, and you'll soon lock on to the class of curve fitting you need.

Have you thought about multiple regression - just a guess as you haven't provided much detail.

3. Gnuplot has some very nice curve fitting tools.

4. If your objective is to implement a nonlinear model already tested and parameterized, your task is not difficult. However, if you have a set of data, and want to find an equation, I recommend you to give a quick look at the GNU Scientific Library.

Overall, I believe that the most straightforward way to solve your problem is to fit your curve using a standard package (R, GRaphPad Prism), get the equation, and code it in C.

5. hi, thanks for the replies. i use the curve-fitting solver tool in Excel quite frequently for my other straightforward curve-fitting problems. however, right now, what i need to do is to apply curve-fitting to an image, meaning that i have to iterate this curve-fitting on a pixel by pixel basis (there are about 15million pixels in my image), so Excel is definitely not the way to go.

and yes, i already have a model that i want to optimize, so all i need to do is to vary the model parameters. the model is quite complicated, with exponential, trigonometric, as well as quadratic terms.

what i am hoping to do is to use a readily-available source code for this kind of curve-fitting, and pluck it into my c program. however, i have yet to find any that is easy to understand and implement. there are some links here Levenbergâ€“Marquardt algorithm - Wikipedia, the free encyclopedia but i have yet to try them out.

any other suggestions?

6. ## levmar c source

levmar is the way to go.

Attached is a ZIP of free C source. It also has TXT files with lots of references, info on how to use, links, etc.

Hope this helps.

For some reason ZIPs are not allowed as attachments, so it's renamed as LEVMAR.TXT. Please detach and rename back to ZIP before use.

7. thanks for the suggestions. i have downloaded the levmar algorithm from the levmar website, and then following the instructions in the FAQ and accompanying readme, i then went on to get lapack. i got lapack from the synaptic package manager (i am running ubuntu 8.04 hardy). as i was not sure which lapack package to get from the list, i installed the 2 that i thought were most likely: liblapack3gf, and, liblapack-dev.

next, i cd-ed into the levmar folder in a terminal, then typed 'make'. this was what i got:

Code:
```
gcc   -O3 -funroll-loops -Wall    -c -o lm.o lm.c
gcc   -O3 -funroll-loops -Wall    -c -o Axb.o Axb.c
gcc   -O3 -funroll-loops -Wall    -c -o misc.o misc.c
gcc   -O3 -funroll-loops -Wall    -c -o lmlec.o lmlec.c
gcc   -O3 -funroll-loops -Wall    -c -o lmbc.o lmbc.c
gcc   -O3 -funroll-loops -Wall    -c -o lmblec.o lmblec.c
gcc   -O3 -funroll-loops -Wall    -c -o lmbleic.o lmbleic.c
ar crv liblevmar.a lm.o Axb.o misc.o lmlec.o lmbc.o lmblec.o lmbleic.o
a - lm.o
a - Axb.o
a - misc.o
a - lmlec.o
a - lmbc.o
a - lmblec.o
a - lmbleic.o
ranlib liblevmar.a
gcc   -O3 -funroll-loops -Wall    -c -o lmdemo.o lmdemo.c
gcc -L/usr/local/lib  -L. lmdemo.o -o lmdemo -llevmar -llapack -lblas -lf2c  -lm
/usr/bin/ld: cannot find -lf2c
collect2: ld returned 1 exit status
make: *** [lmdemo] Error 1```
may i know how to solve this problem?

also, will the algorithm be usable after this, or am i missing some more steps? i would like to try out the expfit.c demo that comes with levmar.

8. Library for linking to fortran code. Since I don't see any fortran source files in the log you posted, try removing the -lf2c from the Makefile. Alternatively there may be a libf2c package on your system that provides a libf2c.

9. i think i will just use some routines from numerical recipes for my problem. levmar is a bit difficult for me at the moment. thanks for your help.