12 const unsigned int max_iters,
17 auto PrintIterationInfo = [](
unsigned int i,
const VecDbl& x_i,
21 std::stringstream output;
22 output <<
"Iteration " << std::setw(3) << i <<
": x_i=";
23 for (
auto value : x_i)
24 output << std::showpos << std::scientific << std::setprecision(3)
27 for (
auto value : F_x_i)
28 output << std::showpos << std::scientific << std::setprecision(3)
30 output <<
"L2_norm_F_x_i=" << L2_norm_F_x_i;
37 VecDbl F_x_i = non_linear_function.
F(x_i);
42 if (verbose) PrintIterationInfo(0, x_i, F_x_i, L2_norm_F_x_i);
46 while (L2_norm_F_x_i >= epsilon and i < max_iters)
49 x_i = x_i -
MatMul(J_x_i_inv, F_x_i);
51 F_x_i = non_linear_function.
F(x_i);
56 if (verbose) PrintIterationInfo(i, x_i, F_x_i, L2_norm_F_x_i);
std::vector< VecDbl > MatDbl
std::vector< double > VecDbl
LogStream Log(LOG_LVL level=LOG_0)
virtual MatDbl J(const VecDbl &x) const
virtual VecDbl F(const VecDbl &x) const
MatDbl Inverse(const MatDbl &A)
VecDbl NewtonIteration(const NonLinearFunction &non_linear_function, const VecDbl &x_0, unsigned int max_iters, double epsilon, bool verbose=false)
MatDbl MatMul(const MatDbl &A, const double c)
double Vec2Norm(const VecDbl &x)