Seldon provides matrix and vector structures (for numerical
computations) which are not part of the C++ standard library. Those
structures are a lot more convenient than basic arrays (like
float* vect = new float[5]
or double
mat[5][4]
). They can be resized, displayed, copied,
automatically destroyed, etc. The use of Seldon is therefore easy.
#define SELDON_DEBUG_LEVEL_3 #include "Seldon.hxx" using namespace Seldon; int main() { TRY; Matrix<double> A(3, 3); Vector<double> U, V; A.SetIdentity(); A(0, 1) = -1.0; U.Reallocate(A.GetN()); U.Fill(); U.Print(); V.Reallocate(A.GetM()); Mlt(2.0, A, U, V); cout << V << endl; END; return 0; }
The example above (also in file: example1.cpp) does the following:
try
block (macros TRY
and
END
). This is not required, but it may catch
Seldon exceptions.A
is set to the identity. Then its
element at (0, 1) (first row, second column) is set to -1.0.U
is reallocated so that its length is the number
of columns of A
. It is simply filled with 1, 2 and
3. Then it is displayed thanks to the method
Print
.Mlt
would call it.V
is displayed.The output is:
1 2 3 -2 4 6
#define SELDON_DEBUG_LEVEL_4 #include "Seldon.hxx" using namespace Seldon; int main() { TRY; Matrix<double> A(3, 3); A.Zero(); A(0, 3) = 2.0; END; cout << "The program should not reach this point..." << endl; return 0; }
The example above (also in file: example2.cpp) does the following:
A
of size 3 by 3 is
defined.A
is set to 0.END
) are executed.The output is:
ERROR! Column index out of range in Matrix_Pointers::operator(). Index should be in [0, 2], but is equal to 3.