Go back to index /codes


The least squares algorithm of fitting a line to set of data as outlined in Numerical Recipes. The program is written in C.

To download the file bundle click: lsq.zip. Unpack the archive into a single directory. The files included in the distribution are:

1. lsq.c : source code
2. lsq.o : object file produced after doing gcc -c -mno-cygwin lsq.c on a Cygwin prompt
3. lsq.exe : executable produced after doing gcc -o lsq -mno-cygwin lsq.o on a Cygwin prompt

To run the program you might like to double-click on the lsq.exe. It should run under a DOS shell in Windows XP Pro or Windows 98. However, there is some chance that the executable will not run optimally (or at all). In that case, you will need to compile the source code on your machine. To do that you might like to download Cygwin which includes the gcc compiler.

To compile the source code on a Cygwin prompt do:

gcc -c -mno-cygwin lsq.c
gcc -o lsq -mno-cygwin lsq.o

To run the program then, you just have to double-click on the executable located in your Cygwin home directory. It will run under a DOS shell. In case you would like to run it under Cygwin, you only have to do gcc lsq.c -o lsq.exe on a Cygwin prompt and then ./lsq.exe.

The programme will produce three xls files with the data. The doc1.xls includes all the data points as given by the user. The doc2.xls includes all the data points of the output line function and the doc3.xls includes both data for easier plotting in your xls handling programme. Improvements are to be made and will be posted here.

To report any bugs or suggest improvements please email me at kele@physics.uoc.gr


kele@physics.uoc.gr Page Last Updated On: