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

void main() {
    matrix a(3, 3), c(3, 3), a4(3, 3), b(4, 1), err;
    matrix a1(2, 2), a2(2, 2), a3(2, 2);
    matrix a6(4, 4), v6(4, 4), eigv6(4, 1), x6(4, 1);
    a1(1, 1) = a1(1, 2) = 2;
    a1(2, 1) = a1(2, 2) = 1.0;
    a2 = a1 * 2;
    double d6[4], eps = 0.1e-11;
    int i;
    printf("input matrix a1 and a2\n");
    a1.print();
    a2.print();
    printf("summa a1+a2\n");
    a3 = a1 + a2;
    a3.print();
    printf("press any key for continue\n");
    //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;
    */
    a6(1, 1) = 1;
    a6(1, 2) = 2;
    a6(1, 3) = 3;
    a6(1, 4) = 2;
    a6(2, 1) = 2;
    a6(2, 2) = 3;
    a6(2, 3) = 5;
    a6(2, 4) = 3;
    a6(3, 1) = 3;
    a6(3, 2) = 5;
    a6(3, 3) = 7;
    a6(3, 4) = 5;
    a6(4, 1) = 2;
    a6(4, 2) = 3;
    a6(4, 3) = 5;
    a6(4, 4) = 0.762;
    i = eigJ(a6, eps, d6, v6);
    for (i = 0; i < 4; i++)printf("d= %e\n", d6[i]);
    printf("error in eig\n");
    for (i = 1; i <= 4; i++) {
        eigv6 = v6.column(i);
        err = a6 * eigv6 - d6[i - 1] * eigv6;
        err.print();
    }
    b(1, 1) = 3;
    b(2, 1) = 5;
    b(3, 1) = 11;
    b(4, 1) = 0.674;
    //Solve system of linear equations a*x=b
    x6 = a6 | b;
    x6.print();
    printf("error for Gauss\n");
    err = a6 * x6 - b;
    err.print();
    //getch();
    printf("triangulation");
    c = +a6;
    a6.print();
}