I need to solve a system of linear equations in my program. Is there a simple linear algebra library for C++, preferably comprised of no more than a few headers? I've been looking for nearly an hour, and all the ones I found require messing around with Linux, compiling DLLs in MinGW, etc. etc. etc. (I'm using Visual Studio 2008.)
问题:
回答1:
I think Eigen is what you're looking for.
http://eigen.tuxfamily.org/index.php?title=Main_Page
It is a headers only library and compiles on many compilers. It even uses exotic assembly for faster math.
This is the page that shows off the linear solver api.
http://eigen.tuxfamily.org/dox-2.0/TutorialAdvancedLinearAlgebra.html
It has a few solvers with a simple api.
回答2:
Boost has some basic linear algebra stuff.
回答3:
You can use the C++ bindings of LAPACK. A quick google turned up this link to some LAPACK for Windows libraries. Depending on the how big your systems are all this might be overkill though.
回答4:
I am a big fan of Armadillo but your compiler may be an issue here according to the the end of the download page:
Windows
The development and testing of Armadillo has so far been done mainly on UNIX-like platforms, however there should be little or no platform specific code. While rudimentary tests were done on a Windows machine, the developers are interested in hearing how well Armadillo works in more thorough tests.
If you're having trouble with the 'MS Visual C++ 2008 Express Edition' compiler (due to its incomplete support for the C++ standard), you may want to try the following alternative free compilers:
- Intel's C++ compiler
- GCC (part of MinGW)
- GCC (part of CygWin)
It is worth trying out as this is a well-designated (and mostly templated) library.
Otherwise, maybe try Eigen2 which lists your compiler as supported.
Edit: In response to the comment, Armadillo does not require Lapack but works better with it (and better still with tuned Blas):
Q: What other libraries do I need to make full use of Armadillo ?
A: Armadillo can work without external libraries. However it is recommended to install the LAPACK and ATLAS libraries in order to get added functionality. Armadillo will use ATLAS routines in lieu of LAPACK wherever possible.Q: How well will Armadillo work without LAPACK/ATLAS ?
A: Basic functionality will be available (e.g. matrix addition and multiplication), but things like eigen decomposition will not be. Matrix multiplication (mainly for big matrices) will not be as fast.