#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include "matr_bvv.cpp"

void main() {
    matrix a(3, 3), c(3, 3), a4(3, 3), v(3, 3), b(3, 1), x(3, 1), err, eigv(3, 1), z;
    matrix a1(2, 2), a2(2, 2), a3(2, 2), a5(3, 3);
    a1(1, 1) = a1(1, 2) = 2;
    a1(2, 1) = a1(2, 2) = 1.0;
    a2 = a1 * 2;
    double d[3], eps = 0.1e-14, det;
    int i;
    printf("input matrix a1 and a2\n");
    z = a1 = a2;
    a1.print();
    a2.print();
    printf("summa a1+a2\n");
    a3 = a1 + a2;
    a3.print();
    printf("press any key for continue\n");
    getch();
    printf("z=");
    z.print();
    getch();
    a(1, 1) = 1;
    a(1, 2) = 2;
    a(1, 3) = 3;
    a(2, 1) = 2;
    a(2, 2) = 3;
    a(2, 3) = 5;
    a(3, 1) = 3;
    a(3, 2) = 5;
    a(3, 3) = 7;
    a5 = a4 = a;
    i = eigJ(a, eps, d, v);
    for (i = 0; i < 3; i++)printf("%e\n", d[i]);
    printf("error in eig\n");
    for (i = 1; i <= 3; i++) {
        eigv = v.column(i);
        err = a * eigv - d[i - 1] * eigv;
        err.print();
    }
    b(1, 1) = 3;
    b(2, 1) = 5;
    b(3, 1) = 11;
    //Solve system of linear equations a*x=b
    x = a | b;
    x.print();
    printf("error for Gauss\n");
    err = a * x - b;
    err.print();
    getch();
    printf("triangulation");
    c = +a4;
    a4.print();
    det = a5.det();
    printf("determinant=%e\n", det);
    getch();
}