Introduction
Matrix<LIB> is a Matlab-compatible C++ matrix class library designed
for the development of advanced scientific high-level C++ code. The library
includes over 500 mathematical functions, among which are basic operators,
powerful indexing capabilities, signal processing, file I/O, linear algebra,
string operations, and graphics. The linear algebra functions are based
on the well-known LINPACK and EISPACK codes. Complex matrices are fully
supported.
The library is built on the target system, enabling the selection of
compiler optimization flags and local BLAS libraries. A main design objective
was to keep the C++ source code clear and similar to the equivalent Matlab
code, making your shift from Matlab to C++ easier. If you know how to program
Matlab, you already know how to use the Matrix<LIB> C++ Math Library.
The code was also carefully optimized for maximal performance. Matrix<LIB>
V3 is also included in the MATCOM V3 distribution.
Code Example
C++ Code
M <double> x("x",0,0), q, r, u, s, v;
x=randM(3.0);
matlibout << x;
qr(x,i_o,q,r);
matlibout << (q*r);
svd(x,i_o,u,s,v);
matlibout << (u*s*transpose(v));
Results
x =
0.219 0.6793 0.5194
0.04704 0.9347 0.831
0.6789 0.3835 0.03457
ans =
0.219 0.6793 0.5194
0.04704 0.9347 0.831
0.6789 0.3835 0.03457
ans =
0.219 0.6793 0.5194
0.04704 0.9347 0.831
0.6789 0.3835 0.03457
Performance
The library is built locally by your optimizing C++ compiler, making possible
the tweaking of compiler optimization flags to your liking. Local BLAS
1 and 3 libraries are utilized. Matrix<LIB> V3 introduces support for
parallel processing on Windows NT and Solaris operating systems featuring
dual (or more) processors and programmer-designated scalar variable support.
Together, Matrix<LIB> features increased performance and lower memory
requirements for your programs.
The MathTools Accelerator provides additional performance gains for
programs using linear algebra and matrix multiplication. These gains are
achieved using assembler routines optimized for the Pentium, Pentium II,
and Pentium-Pro processors, with popular C++ compilers.
Integration
The created source code highly resembles the original code using C++ language
features. The C++ code and our free, redistributable matrix library can
be directly used in C++ environments such as Visual C++, MFC and Borland
C++ Builder.
Other non-C++ programming environments such as IDL, Excel, Visual Basic,
Delphi, ObjectAda and XMath are supported with automatic compilation of
your programs to DLLs. This enables you to easily use your algorithms within
your favorite development tools.
Matrices
The basic data type is the template class M. Declaration of a 2x3 matrix
of doubles looks like:
Constructors from scalars and strings are provided, as well as safe element
access functions.
Memory
Matrix<LIB> supports compiling whole applications with float-type matrices.
When compiled this way, applications use only half the memory ordinarily
used with double-type matrices. In addition, the platform-dependent type
long double is supported. This provides five to ten extra decimal digits
of precision over double.
Complex Math
Complex matrices are fully supported. Matrix can be complex or real; real
matrix uses half the memory. The iscomplex function is provided to distinguish
between the two.
Unary and Binary Operators
The C++ operators < > <= >= == != || && + - * / are overloaded
to work on the matrix class. This enables you to write clear expressions
such as:
y = a + b * x + (c - 1) * x * x;
f = (c && d) || e;
Many more functions are supplied, including sqrt, min, max, abs, log, sum,
and prod.
Console I/O
Basic console I/O is implemented: disp, error, format, input, menu, and
pause. This can be extended by using the standard C/C++ library or MFC.
The library is fully streamable: upon init, you supply input stream, output
stream, and an error stream.
Powerful Indexing Capabilities
All of Matlab indexing capabilities can be used in the expected syntax:
// a(1)=b
a(1)=b;
// a(:,v)=c
a(c_p,v)=c;
// x(:,i)=a*x(:,i)+b(:,i)
x(c_p,i)=a*x(c_p,i) + b*y(c_p,i);
// x(:,1)=[]
x(c_p,1)=nop_M;
The c_p symbol is equivalent to : .
nop_M is a predefined empty matrix [] .
Trigonometric
Functions supplied include cos, sin, tan, sec, csc, and cot. Inverse, hyperbolic
and inverse hyperbolic versions are also supplied.
Signal Processing
High-speed versions of filter, ltitr, and ltifr are included. Use these
to build rich algorithms.
File I/O
C-Style vectorized file I/O system. fopen, fclose, fprintf, fscanf, fread,
fwrite, fseek, and ftell are implemented. The functions can read and write
to little-endian or big-endian files. In addition, the standard load/save
functions are supported.
Linear Algebra
The linear algebra functions are based on the well known LINPACK and EISPACK.
Cholesky, Hessenberg, LU, QR, QZ, Schur, and SVD matrix decompositions
are supplied.
String Operations
Matlab-style strings are implemented with a conversion function:
a=TM("MNABTURDIIXN");
v=colon(1,2,9);
cout<<a(v);
outputs 'MATRIX'.
Graphics
2D and 3D Graphics are supported in standalone applications using the free-of-charge
graphics package, Gnuplot. Flexible collection of plotting commands (plot,
plot3, axis, title, subplot, legend) enable you to display the data in
exactly the way you want them to be seen.
Multi-platform
Matrix<LIB>/UNIX supports:
- Linux,
- SunOS,
- Solaris,
- Irix,
- AIX,
- HPUX,
- OSF1, and
- Ultrix.
gcc or the vendor-supplied C++ compiler can be used.
Matrix<LIB>/PC supports:
- Windows 3.11,
- Windows 9x,
- Windows NT,
- OS/2, and
- QNX.
Visual C++, Borland C++, Borland C++ Builder, Watcom C++, and DJGPP can
be used.




Stefan Steinhaus, webmaster@steinhaus-net.de