MNP02/main.cpp
Kacper Donat af9dfe6f8c solvers
2018-05-02 23:29:41 +02:00

46 lines
1.0 KiB
C++

#include "matrix.h"
#include "solver.h"
#include <iostream>
#include <utility>
const size_t N = 10;
std::pair<Matrix<double>, Matrix<double>> prepare(size_t index, size_t n)
{
double a1, a2, a3;
a2 = a3 = -1;
a1 = 5 + (index / 100) % 10;
auto M = Matrix<double>::diag(n, a1)
+ Matrix<double>::diag(n, a2, 1) + Matrix<double>::diag(n, a2, -1)
+ Matrix<double>::diag(n, a3, 2) + Matrix<double>::diag(n, a3, -2);
Matrix<double> b(n, 1);
for (size_t i = 0; i < n; ++i) {
b(i, 0) = sin((i + 1)*((index / 1000) % 10 + 1));
}
return std::make_pair(M, b);
}
int main(int argc, const char* argv[])
{
auto tuple = prepare(165581, N);
auto M = std::get<0>(tuple);
auto b = std::get<1>(tuple);
JacobiSolver jacobi;
std::cout << jacobi.solve(M, b);
GaussSolver gauss;
std::cout << gauss.solve(M, b);
LUSolver lu;
auto pair = LUSolver::decompose(M);
auto L = std::get<0>(pair);
auto U = std::get<1>(pair);
std::cout << lu.solve(L, U, b);
}