C++ equivalent of matlab regress() function - c++

I'm looking for C++ equivalent of regress() function in Matlab. It's a multi-linear regression using least square algorithm.
Currently I'm looking at the Armadillo library. I'm not quite sure whether it supports this algorithm or not.

Try one of the orthogonal decomposition methods, they are supported by Armadillo.
(I don't know Matlab or what it's regress() function does.)

Related

MATLAB Coder: sparse matrix

MATLAB Coder seems to be fancy and can speed up MATLAB code much by converting the code into C/C++ or MEX.. But it seems that it does not support sparse matrix, or the matlab function sparse which is essential to my code. Does anyone have any idea about how to overcome this problem? Many thanks!
The eigen library can be used to handle the Matlab function sparse and it is in c language.
As said by "libill", You could also just generate MEX code for the portions of your MATLAB code which doesn't use sparse to speed those portions up.
And for sparse part use above library.
My understanding of Matlab coder maybe wrong but I think it is a tool that convert your Matlab codes to C/C++ codes. I am not sure performance optimization is the goal of Matlab coder.
Take a look at suitesparse. It's a C Library that handle a lot of sparse operations. The Matlab "\" operator in the case of sparse matrix actually uses suitesparse. So I think it may be easier for you to modify the Matlab generated C codes.
HTH
I just am not sure what do you mean by converting. I assume you mean writing your own mex function.
Sparse packages usually deal sparse matrices differently and Matlab has also its unique way to treat them.
However mostly they use CSC (or CSR) format. Matlab is also saving the matrix as CSC format.
You can look at lots of sparse packages mex functions to see how it is done.
The point is Matlab will not let you save explicit zeros in its sparse data structure.
DO NOT try to save explicit zeros on Matlab mex function. Matlab will choke on you!

convert Matlab built-in functions to C/C++

Is there's away to convert the built-in functions that doesn't have a .m file to C++
I'm read in some paper that neither the Matlab compiler nor the Matlab coder could convert it
so I'm wondering those seem to be the most basic functions is there's another way to convert it or perhaps a C++ library with its equivalent
Check the Boost C++ Library (which also contains ode solvers and many other things) or LAPACK (for linear algebra operations).
For deployment solutions, MathWorks publishes lists of supported toolboxes and functions by each product: MATLAB Coder and MATLAB Compiler

Implementing MATLAB function in c++ using Intel C++ compiler

I have developed a MATLAB program with Visual C++. I am using IntelĀ® Integrated Performance Primitives because speed of program is important issue and I have done a lot of efforts for implementing some MATLAB functions. For example, for Min and Max functions over a vector i use ippsMaxIndx_32f; but, there is function in MATLAB like Find.
Here is a description of the Find method in MATLAB:
Description
I need a function which implements this find function of MATLAB with high speed.
Are there any functions inside Intel Ipp, that works like the Find function in MATLAB?
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, 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++.
You can check to these to see if you can find the function you are looking for! As i am not sure for that.
I've used ippsFind_* and they have worked just fine.

Where to get free math libraries for C/C++

Are there free C/C++ libraries taht do the types of functions that matlab does - something complicated i mean, like discrete laplacian, etc? Is the best option to create some kind of interface in matlab and build my own library?
Thanks
Have you looked at Boost.Math?
http://www.boost.org/doc/libs/1_46_1/libs/math/doc/html/index.html
If you are on windows, there is a very easy to use installer by BoostPro:
http://www.boostpro.com/download/
If you want something that was a matlab clone but free, you could use Octave http://www.gnu.org/software/octave/
I haven't used it in a C++ program, but it apparently has a C++ API:
http://octave.sourceforge.net/doxygen/html/index.html
Depending on what you want to do there are various packages available.
Arbitrary Precision
mostly integers: GMP, MPIR (similar codebases, MPIR has VC builds)
floats: MPFR
complex: MPC
Specialist:
Number Theory: Flint
Linear Algebra: Boost Numeric uBLAS
PDEs: libMesh
Computational Fluid Dynamics: OpenFoam
Graph Theory: Boost Graph
General:
TNT (was LAPACK++ (TNT=do everything, LAPACK++=Linear Alg.)
SciMath (Commercial)
GNU Scientific Library
and that's just a few. I haven't repeated ones others have listed like libpari.
Just in case you're wondering, Maple, Mathematica, Matlab etc all use the GNU MP for their arbitrary precision calculations.
PARI could be a good choice, although I am not familiar with using it:
Official Site for PARI
PARI is a C library, and if you want an independent software, they have PARI-GP there.
Below is the description of PARI on the website above:
PARI/GP is a widely used computer
algebra system designed for fast
computations in number theory
(factorizations, algebraic number
theory, elliptic curves...), but also
contains a large number of other
useful functions to compute with
mathematical entities such as
matrices, polynomials, power series,
algebraic numbers etc., and a lot of
transcendental functions. PARI is also
available as a C library to allow for
faster computations.
Hope this could be useful!
P.S. It is said that Octave functions could be called from C++, and that could be an excellent substitution for MATLAB.
Have a look at armadillo for simplifying your handling of matrices. Then for solving PDEs you'll have to do the job yourself, ie. construct explicitly your Laplacian matrix, and solve it the way you want.
There is Intel MKL too (not free though) which adds some value: iterative solvers (GMRES, BCG) and some black-boxes for solving the Laplacian / Poisson equation on simple domains (cubes and spheres).
I use OpenCV for a lot of image processing and matrix manipulation, which is generally what I use matlab for.
http://opencv.willowgarage.com/wiki/
May be overkill depending on what kind of math your trying to do, but it's great for computer vision.
The GNU Scientific Library is a free numerical library for C and C++ programmers.
With the Coder toolbox (requires MATLAB R2011a), you can also turn your MATLAB code into C or C++.
you can use octave runtime:
http://en.wikipedia.org/wiki/GNU_Octave#C.2B.2B_Integration

Implement matlab code in C++?

I have a certain code written in Matlab. I wanted to obtain similar results using a c++ code. I wanted to know whether a c++ library exists for matrix manipulations? My current Matlab code consists of matrix multiplications,inverse and complements.
There are dozens of linear algebra libraries for C++. Here is another one not mentioned in the other links so far:
http://www.alglib.net/
I have used Newmat in a similar situation.
Not sure if this would help you, or your company/university have licenses for it but matlabcoder can export your matlab code to c++ without much extra work.
http://www.mathworks.com/products/matlab-coder/