As a first example we present a simple program that solves a linear system of equations with a tridiagonal matrix. We use for this the Gauss elimination method.
#include "OFELI.h" using namespace OFELI; int main(int argc, char *argv[]) { size_t n=atoi(argv[1]); TrMatrix<double> A(n); Vect<double> b(n), x(n); } |
for (size_t i=2; i<n; i++) { A(i,i) = 2.0; A(i,i-1) = -1.0; A(i,i+1) = -1.0; } A(1,1) = 2.0; A(1,2) = -1.0; A(n,n-1) = -1.0; A(n,n) = 2.0; b = 0.0; b(n) = n+1; |
LinearSolver<double> ls(A,b,x); ls.setSolver(DIRECT_SOLVER); ls.solve(); |
cout << "Solution:\n" << x << endl; return 0; } |