GSL

Reference Manual

http://www.gnu.org/software/gsl/manual/html_node/index.html

Ex: Matrix Diagonalization (Eigenvalues and Eigenvectors)

Example Code

http://www.gnu.org/software/gsl/manual/html_node/Eigenvalue-and-Eigenvector-Examples.html

Usage

Run or add to .bashrc:

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/Reichman/files/libraries/gsl/lib/

$ gcc test_eig.c -o test_eig.x -lm -L/home/Reichman/files/libraries/gsl/lib -I/home/Reichman/files/libraries/gsl/include -lgsl -lgslcblas
$ ./test_eig.x

Fitting

Python Polynomial Fit

Code

import numpy
import sys
data = numpy.loadtxt(sys.argv[1])
order= int(sys.argv[2])
x=data[:,0]
y=data[:,1]

print numpy.polyfit(x,y,order)

Usage

./samplefit.py DATA_FILE POLYNOMIAL_ORDER

Sample

echo -e "1 1\n2 4\n3 9\n4 16" > test_data

./samplefit.py test_data 2

Return Value

[ 1.00000000e+00 1.64544831e-15 -7.39171276e-16]

Note: this is in reverse order so this would be 1x^2 + 0 x + 0

Gnuplot Fit

gnuplot> f(x)=a+b*x+c*x**2
gnuplot> fit f(x) "test_data" via a,b,c

ReichmanCodeSnippets (last edited 2011-01-12 23:32:54 by noway)