// Solving by Robinkin
#include "mtrix.h" #include "mtl / mtl.h" #include "mtl / utils.h" #include "mtl / tinalg_vec.h"
/ *
X1 = 8;
2 * x1 2 * x2 = 43;
4 * x2 5 * x3 = 86;
6 * x3 7 * x4 = 137
result:
[x1, x2, x3, x4] = [8, 9, 10, 11,]
/ * Sample Output A: [[1,], [2, 3,], [0, 4, 5,], [0, 0, 6, 7,],] B: [8, 43, 86, 137,] A ^ -1 * B: [8, 9, 10, 11,]
* /
Using namespace MTL;
Typedef Matrix
INTMAIN () {const INT n = 4;
Matrix a (n, n);
Set_diagonal (a, 1);
// C 1 8 // C A = 2 3 b = 43 // C 4 5 86 // C 6 7 137
A (1, 1) = 3; A (2, 2) = 5; A (3, 3) = 7; A (1, 0) = 2; A (2, 1) = 4; A (3, 2 ) = 6;
Double DB [] = {8, 43, 86, 137}; vector b (db, n);
Std :: Cout << "A:" << std :: endl; print_row (a);
Std :: cout << "B: << std :: endl; print_vector (b);
Tri_solve (a, b);
Std :: cout << "A ^ -1 * b:" << std :: endl;
Print_vector (b);
Return 0;}