30 December, 2003
This library provides some functions to simplify calling routines from Numerical Recipes in C++ when you are using Newmat for defining and manipulating your matrices.
It does this by using Newmat's Matrix and ColumnVector classes for the Numerical Recipes in C++ classes for Mat_DP, Mat_I_DP, Mat_O_DP, Mat_IO_DP and Vec_DP, Vec_I_DP, Vec_O_DP, Vec_IO_DP.
You need to
Then anywhere where Numerical Recipes in C++ uses Vec_DP, Vec_I_DP, Vec_O_DP or Vec_IO_DP you can use ColumnVector and where it uses Mat_DP, Mat_I_DP, Mat_O_DP or Mat_IO_DP you can use Matrix.
See the file nrx_ex1.cpp as an example. This fills up a symmetric matrix using a random number generator from NRC++ then gets the eigenvalues and eigenvectors, first using the NRC++ routine and then using the Newmat routine. It checks that the decompositions are valid and that the eigenvalues agree. See the output in nrx_ex1.txt. (The timing comparison in this program is slightly unfair to NRIC++ as the subscript operations introduced by Newmat are slightly slower than the ones they replace in the unmodified array package in NRIC++).
I suggest you put the Numerical Recipes files (from all the subdirectories of directory cpp) and the Newmat files in the same directory (rename the Numerical Recipes files sort.cpp and jacobi.cpp as sort1.cpp and jacobi1.cpp). Copy the files from this package into the same directory overwriting nr.h, nrtypes.h, nrutil.h.
For compiling with Visual C++, Borland Builder or Dev-C++ using their IDEs see my instructions for compiling Newmat and include the Numerical Recipes files that you need.
I have included make files for Borland Builder, MS Visual C++, Gnu G++, Intel C++ and Sun CC for compiling all the Numerical Recipes in C++ example files and my example file. See the list of files. The make files were generated with my genmake program. You may need to look at the genmake documentation (go here to see the version on my website) to see how to run the make files.
Then the appropriate make file will compile all the NRC++ example files and my example file. There will be some warnings but there should be no fatal errors. I haven't looked to see if the warning messages matter. I have tried a few of the NRC++ example files, but otherwise have only checked that they compile. I have done this in console mode with Borland Builder 5 and 6, MS Visual C++ 6 and 7, Intel C++ for Windows 5 and 8, Gnu G++ 3 under Linux, Intel C++ for Linux 5 and 7. It won't work without more editing under Gnu G++ 2.96.
Note that the library file generated by this process will not work with programs developed on Microsoft's or Borland's IDEs. You need to make the library files using the appropriate IDE.
To compile your program, if it is in just a single file, you could just put it in nrx_ex1.cpp and use the existing make file.
Otherwise you will need to make a new makefile. You can use genmake to do this. Edit nrx_targ.txt to include the nrx.lfl and just the names of the files containing your main programs (give it a new name). Then follow the genmake instructions. It is somewhat slow because the genmake program goes through all the NRIC++ files, so take a short break.
| nr.h | Replacement for NRC++ nr.h |
| nrtyp_nm.h | My edited version of nrtypes_lib.h - called from nrtypes.h |
| nruti_nm.h | My edited version of nruti_nr.h - called from nrutil.h |
| nrtypes.h | Replacement for nrtypes.h |
| nrutil.h | Replacement for nrutil.h |
| nrtyp_nm.cpp | Body file for my version of print_array |
| nruti_nm.cpp | Body file for nruti_nm.h |
| nrx_ex1.cpp | Example |
| nrx_b55.mak | Make file for Borland Builder 5 |
| nrx_b56.mak | Make file for Borland Builder 6 |
| nrx_i5.mak | Make file for Windows Intel compiler |
| nrx_il5.mak | Make file for Linux Intel compiler |
| nrx_m6.mak | Make file for Visual C++ 6 and 7 |
| nrx_gnu.mak | Make file for G++ |
| nrx_cc.mak | Make file for Sun CC compiler (not tested) |
| nrx.lfl | Library definition used by genmake |
| nrx_targ.txt | Target file for genmake |
| nrx_ex1.txt | Output from example |