Using Numerical Recipes
This shows how to write programs that call Numerical Recipres functions, how to compile and link these programs. The Numerical Recipes Library libnrecc.a is located in the directory /usr/local/nrcp/ in the machines in the Physics Computer Lab. All the header files are also in this directory. The source code is available in the directory /usr/local/nrcp/C/ansi-c/ .Download the files libnrecc.a, nrutil.h and nr.h into your working directory if you not using a computer in the Physics Lab. The compiling and linking commands are also slightly different.
The program nrcp_test.cintegrates two functions f(x)=1 and g(x)=x from the limits 0 to 1. It uses the function qsimp to do the integration.
To compile and link the program in the Physics Lab
cc -c nrcp_test.c -I/usr/local/nrcp/
cc -o nrcp_test nrcp_test.o -L/usr/local/nrcp/ -lnrecc -lm
To compile and link the program in CIC or elsewhere
cc -c nrcp_test.c
cc -o nrcp_test nrcp_test.o -lnrecc -lm
To run
./nrcp_test
Sample program (prog.c) for solving a set of orinary differential equations (ODEs) using the Numerical Recipes function odeint(). This program evolves the position and momentum of a simple harmonic oscillalor which starts from rest at x=1.