// Author: Douglas Wilhelm Harder // Copyright (c) 2009 by Douglas Wilhelm Harder. All rights reserved. #include "Sparse.h" #include using namespace std; int main() { Matrix<10, 10> A; Vector<10> v; Vector<10> b; for ( int i = 0; i < 10; ++i ) { A.set( i, i, 1 + 0.1*i ); b(i) = i + 1; } for ( int i = 0; i < 9; ++i ) { A.set_symmetric( i, i + 1, 0.1 + 0.1*i ); } cout << A << endl; v = jacobi( A, b, 100, 1e-10 ); cout << v << endl; cout << norm( A*v - b ) << endl; v = gauss_seidel( A, b, 100, 1e-10 ); cout << v << endl; cout << norm( A*v - b ) << endl; v = steepest_descent( A, b, 100, 1e-10 ); cout << v << endl; cout << norm( A*v - b ) << endl; v = minimal_residual( A, b, 100, 1e-10 ); cout << v << endl; cout << norm( A*v - b ) << endl; v = residual_norm_steepest_descent( A, b, 1000, 1e-10 ); cout << v << endl; cout << norm( A*v - b ) << endl; return 0; }