Michael
03-17-2002, 01:15 AM
Great idea that we have such a forum! My question is, can I use the matrix library Newmat (by Robert Davies http://webnz.com/robert/ ) with NR in C++? How do I do that?
Thanks!
Saul Teukolsky
03-18-2002, 04:20 PM
Hi Michael,
Yes, you should be able to use newmat with NR in C++. As discussed in Section
1.3, here's what you need to do:
1) Edit nrtypes.h to include nrtypes_lib.h instead of nrtypes_nr.h
2) Edit nrutil.h to include a new file that you fill create, nrutil_newmat.h,
instead of nrutil_nr.h.
3) Create the file nrutil_newmat.h. You can start with nrutil_tnt.h as
a template. You have to edit the lines starting with
#include "tnt/tnt.h"
through the end of the NRMat class.
First, include the appropriate newmat .h files. Then change the
private variables myvec and &myref to be newmat vectors, and similarly
for mymat and its &myref. Then go through the implementation of
each function in the classes and use the appropriate newmat version.
Most of the code will be unchanged. Things to look out for are
the order of arguments in constructors: myvec(n,a) or myvec(a,n), for
example. Also, in NRMat, you want operator[] to return a pointer to
row i, and the return type must be whatever myref[i] would be for
a newmat matrix. Since newmat seems to do "deep copying" (i.e., a=b
copies the contents of matrices, not just the references), everything
else should be pretty much like tnt.
When you get it to work, please consider sending it to us so we can post
it online for other users.
Best wishes,
Saul Teukolsky