2 #ifndef HDNUM_NEWTON_HH 3 #define HDNUM_NEWTON_HH 43 result[0] = x[0]*x[0] - a;
70 : maxit(25), linesearchsteps(10), verbosity(0),
71 reduction(1e-14), abslimit(1e-30), converged(false)
108 typedef typename M::number_type N;
122 std::cout <<
"Newton " 123 <<
" norm=" << std::scientific << std::showpoint
124 << std::setprecision(4) << R0
129 for (size_type i=1; i<=maxit; i++)
151 for (size_type k=0; k<linesearchsteps; k++)
159 std::cout <<
" line search " << std::setw(2) << k
160 <<
" lambda=" << std::scientific << std::showpoint
161 << std::setprecision(4) << lambda
162 <<
" norm=" << std::scientific << std::showpoint
163 << std::setprecision(4) << newR
164 <<
" red=" << std::scientific << std::showpoint
165 << std::setprecision(4) << newR/R
168 if (newR<(1.0-0.25*lambda)*R)
172 std::cout <<
" step" << std::setw(3) << i
173 <<
" norm=" << std::scientific << std::showpoint
174 << std::setprecision(4) << newR
175 <<
" red=" << std::scientific << std::showpoint
176 << std::setprecision(4) << newR/R
184 if (k==linesearchsteps-1)
187 std::cout <<
" line search not converged within " << linesearchsteps <<
" steps" << std::endl;
197 std::cout <<
"Newton converged in " << i <<
" steps" 198 <<
" reduction=" << std::scientific << std::showpoint
199 << std::setprecision(4) << R/R0
208 std::cout <<
"Newton not converged within " << maxit <<
" iterations" << std::endl;
213 bool has_converged ()
const 220 size_type linesearchsteps;
224 mutable bool converged;
244 : maxit(25), linesearchsteps(10), verbosity(0),
245 reduction(1e-14), abslimit(1e-30), sigma(1.0), converged(false)
288 typedef typename M::number_type N;
297 std::cout <<
"Banach " 298 <<
" norm=" << std::scientific << std::showpoint
299 << std::setprecision(4) << R0
304 for (size_type i=1; i<=maxit; i++)
320 std::cout <<
" " << std::setw(3) << i
321 <<
" norm=" << std::scientific << std::showpoint
322 << std::setprecision(4) << newR
323 <<
" red=" << std::scientific << std::showpoint
324 << std::setprecision(4) << newR/R
331 if (R<=reduction*R0 || R<=abslimit)
335 std::cout <<
"Banach converged in " << i <<
" steps" 336 <<
" reduction=" << std::scientific << std::showpoint
337 << std::setprecision(4) << R/R0
346 bool has_converged ()
const 353 size_type linesearchsteps;
358 mutable bool converged;
Class with mathematical vector operations.
Definition: vector.hh:28
void solve(const M &model, Vector< typename M::number_type > x) const
do one step
Definition: newton.hh:286
void lr_fullpivot(DenseMatrix< T > &A, Vector< std::size_t > &p, Vector< std::size_t > &q)
lr decomposition of A with full pivoting
Definition: lr.hh:107
void permute_backward(const Vector< std::size_t > &q, Vector< T > &z)
apply permutations to a solution vector
Definition: lr.hh:176
Example class for a nonlinear model F(x) = 0;.
Definition: newton.hh:20
void solveR(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume R = upper triangle of A and solve R x = b.
Definition: lr.hh:243
std::size_t size_type
export size_type
Definition: newton.hh:24
void set_verbosity(size_type n)
control output given 0=nothing, 1=summary, 2=every step, 3=include line search
Definition: newton.hh:267
Solve nonlinear problem using a fixed point iteration.
Definition: newton.hh:237
void set_maxit(size_type n)
maximum number of iterations before giving up
Definition: newton.hh:249
Newton()
constructor stores reference to the model
Definition: newton.hh:69
std::size_t size() const
return number of componentes for the model
Definition: newton.hh:35
void set_linesearchsteps(size_type n)
maximum number of steps in linesearch before giving up
Definition: newton.hh:81
void row_equilibrate(DenseMatrix< T > &A, Vector< T > &s)
perform a row equilibration of a matrix; return scaling for later use
Definition: lr.hh:192
void set_abslimit(double l)
basolute limit for defect
Definition: newton.hh:273
void apply_equilibrate(Vector< T > &s, Vector< T > &b)
apply row equilibration to right hand side vector
Definition: lr.hh:213
N number_type
export number_type
Definition: newton.hh:27
Vector & update(const REAL alpha, const Vector &y)
Update vector by addition of a scaled vector (x += a y )
Definition: vector.hh:194
void solveL(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume L = lower triangle of A with l_ii=1, solve L x = b.
Definition: lr.hh:225
Banach()
constructor stores reference to the model
Definition: newton.hh:243
void F_x(const Vector< N > &x, DenseMatrix< N > &result) const
jacobian evaluation needed for implicit solvers
Definition: newton.hh:47
void set_sigma(double sigma_)
damping parameter
Definition: newton.hh:255
void set_reduction(double l)
reduction factor
Definition: newton.hh:99
void set_linesearchsteps(size_type n)
maximum number of steps in linesearch before giving up
Definition: newton.hh:261
This file implements a generic and dynamic vector class.
Class with mathematical matrix operations.
Definition: densematrix.hh:26
void set_verbosity(size_type n)
control output given 0=nothing, 1=summary, 2=every step, 3=include line search
Definition: newton.hh:87
void solve(const M &model, Vector< typename M::number_type > &x) const
do one step
Definition: newton.hh:106
void F(const Vector< N > &x, Vector< N > &result) const
model evaluation
Definition: newton.hh:41
void set_maxit(size_type n)
maximum number of iterations before giving up
Definition: newton.hh:75
void permute_forward(const Vector< std::size_t > &p, Vector< T > &b)
apply permutations to a right hand side vector
Definition: lr.hh:160
Definition: densematrix.hh:21
void set_abslimit(double l)
basolute limit for defect
Definition: newton.hh:93
Solve nonlinear problem using a damped Newton method.
Definition: newton.hh:63
SquareRootProblem(number_type a_)
constructor stores parameter lambda
Definition: newton.hh:30
void set_reduction(double l)
reduction factor
Definition: newton.hh:279