问题
Does anyone know a resource where we can obtain FREE C++ libraries for MATLAB functions? For example, linear algebra problems can be solved using LAPACK and BLAS.
Also, MATLAB in a .NET project is out of the question - I'm talking about direct C++ implementations of popular MATLAB functions (I don't know which functions I need in C++ yet but the functions used are not going to be esoteric).
Any suggestions about such resources?
回答1:
I've never heard of a comprehensive port of matlab functionality to C++. That being said, almost everything matlab does exists within a C/C++ library somewhere, some off the top of my head:
- LAPACK, BLAS, you already mentioned these, and there are a few good implementations, the most notable (free) one being ATLAS.
- FFT is implemented in matlab via the fftw library
- There are loads of fast open-source image libraries out there, ie. interpolation, filtering.
- There are really good OOP matrix libraries out there, boost has a nice one.
After that, well figure out what you need and there is a good chance someone has implemented it in C/C++.
回答2:
I also like
- Armadillo (templated C++ library)
- Eigen (another templated C++ library)
- Newmat (an older but well-tested C++ matrix library)
Beyond that, your original question isn't really specific enough for better pointers.
回答3:
Sorry for reviving an old question but I am currently working on an open source C++ library that exactly answers this question:
KeyCpp is an open source C++ library that provides MATLAB/Octave-like syntax to several useful numerical methods and also some plotting functionality. Currently there are functions for eig
, ode45
, fft
, linsolve
, svd
, interp1
, plot
, and many other common MATLAB functions.
While there are other (very good) libraries that provide many of these functions (such as Armadillo, Eigen, etc), most are not complete numerical libraries and most of their syntax is dissimilar to MATLAB's syntax. While KeyCpp is also not yet a complete numerical library (but is improving all the time!), the syntax is as close to MATLAB's as the C++ language allows.
In KeyCpp, to plot the vectors t
and y
we use the following syntax: (Go here for a more extensive example)
#include <iostream>
#include <keycpp/keycpp.h>
using namespace keycpp;
int main(int argc, char** argv)
{
// Lets create some data: y = sin(t)
std::vector<double> t = linspace(-pi,pi,100);
std::vector<double> y = sin(t);
Figure h;
h.plot(t,y,"-b");
h.grid_on();
h.legend({"Series 1"});
h.title("Example Plot");
h.xlabel("time");
h.ylabel("y");
return 0;
}
The functionality of the KeyCpp library takes advantage of LAPACK, Gnuplot, and odeint (from Boost). The following open source projects have been incorporated into this library: Kiss FFT, Gnuplot-cpp.
Doxygen documentation for most of the functions is located here
回答4:
Beyond the good suggestions already given, you may also be able to lift the code you need from the source code of Octave or Scilab. Both of these have GPL-style licenses, though, which may not suit your needs.
回答5:
Read your Matlab documentation very carefully and have a poke around the DLLs and other components it installs on your hard disks. I think you'll find that Matlab uses a version of BLAS for what BLAS does, possibly also LAPACK and others.
来源:https://stackoverflow.com/questions/1329994/matlab-functions-in-c