detsymm_test.cpp

//===========================================================================
//===========================================================================
#include <iostream>
#include "Array/ArrayIo.h"
#include "LinAlg/LinAlg.h"

using namespace std;


int main()
{
    Array2D< double > A(3, 3);   // input matrix
    Array2D< double > x(3, 3);   // matrix for eigenvectors
    Array  < double > lambda(3); // vector for eigenvalues
    unsigned          curr_row,  // currently considered matrix
    curr_col;  // row/column
    double            det(0.);   // determinate of input matrix

    // Initialization values for input matrix:
    double bottom_triangle[9] =
        {
            7.,  0.,  0.,

            -2.,  6.,  0.,

            0., -2.,  0.
        };

    // Initializing matrices and vector:
    for (curr_row = 0; curr_row < 3; curr_row++) {
        for (curr_col = 0; curr_col < 3; curr_col++) {
            A(curr_row, curr_col) = bottom_triangle[curr_row*3+curr_col];
            x(curr_row, curr_col) = 0.;
        }
        lambda(curr_row) = 0.;
    }

    // Output of input matrix:
    cout << "input matrix:" << endl;
    writeArray(A, cout);

    // Calculating the determinate, eigenvectors and eigenvalues of the matrix:
    det = detsymm(A, x, lambda);

    // Output of determinate:
    cout << "the determinate of the matrix is " << det << endl << endl;

    // Output of eigenvector matrix and eigenvalue vector:
    cout << "matrix of eigenvectors:" << endl;
    writeArray(x, cout);
    cout << "vector of eigenvalues:" << endl;
    writeArray(lambda, cout);

    // lines below are for self-testing this example, please ignore
    if(fabs(det- -28)<1.e-6) exit(EXIT_SUCCESS);
    else exit(EXIT_FAILURE);
}