/************************************************************************ // Solve a linear system using LU factorization. // // Usage: a.out < matrix.dat // // where matrix.dat is an ASCII file consisting of the // matrix size (M,N) followed by its values. For example, // // 3 2 // 8.1 1.2 4.3 // 1.3 4.3 2.9 // 0.4 1.3 6.1 // ************************************************************************/ typedef double Number; #include #include "BERTU.h" #include "vec.h" #include "fmat.h" #include "lu.h" using namespace std; using namespace BERTU; int main() { Fortran_Matrix A; cin >> A; Subscript N = A.dim(1); assert(N == A.dim(2)); Vector b(N, 1.0); // b= [1,1,1,...] Vector index(N); cout << "Original Matrix A: " << A << endl; Fortran_Matrix T(A); if (LU_factor(T, index) !=0) { cout << "LU_factor() failed." << endl; exit(1); } Vector x(b); if (LU_solve(T, index, x) != 0) { cout << "LU_Solve() failed." << endl; exit(1); } cout << "Solution x for Ax=b, where b=[1,1,...] " <