#include #include #include #include #include #include #include #include "jacobi.hpp" char* cmdname; void usage() { std::cerr << "Usage: " << cmdname << " eps n" << std::endl; exit(1); } template bool next_arg(int& argc, char**& argv, T& val) { if (argc == 0) return false; std::istringstream arg(*argv++); --argc; return !!(arg >> val); } int main(int argc, char** argv) { double eps; unsigned int n; cmdname = *argv++; --argc; if (!next_arg(argc, argv, eps) || eps <= 0) usage(); if (!next_arg(argc, argv, n) || n == 0) usage(); if (argc > 0) usage(); const double E_POWER_MINUS_PI = pow(M_E, -M_PI); using T = double; using namespace hpc::matvec; GeMatrix A(n+2, n+2, StorageOrder::RowMajor); jacobi([=](T x, T y) -> T { if (y == 0) { return sin(M_PI * x); } else if (y == 1) { return sin(M_PI * x) * E_POWER_MINUS_PI; } else { return 0; } }, A, eps); using namespace hpc::aux; auto pixbuf = create_pixbuf(A, [](double val) -> HSVColor { return HSVColor((1-val) * 240, 1, 1); }, 8); gdk_pixbuf_save(pixbuf, "jacobi.jpg", "jpeg", nullptr, "quality", "100", nullptr); }