/* Example programs from the book Scientific and Engineering Programming in C++: An Introduction with Advanced Techniques and Examples, Addison-Wesley, 1994. (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES CORPORATION 1994. ALL RIGHTS RESERVED. See README file for further details. */ #include "SciEng/NumericalLimits.h" template T LinearizationIterator:: default_correction_convergence(NumericalLimits::epsilon); template LinearizationIterator:: LinearizationIterator(IteratedEquations& eqn, const Array1d& init_values, int max_iters, T limit) : the_eqns(eqn), cur(init_values), the_max_iters(max_iters), correction_convergence(limit), the_iters(0), correction_norm(0.) { } template Boolean LinearizationIterator::more() const { if (the_iters == 0) return Boolean::true; // no info yet. return the_iters < the_max_iters && !the_eqns.converged() && correction_norm >= correction_convergence; } template void LinearizationIterator::advance(){ correction_norm = the_eqns.update(cur); the_iters++; } template void LinearizationIterator::solve() { while (more()) { advance(); cout << *this << endl; } } // Needs iostream and iomanip... #include #include template ostream& operator<<(ostream& os, const LinearizationIterator& l) { os << "Iteration: " << l.the_iters << " correction norm: " << setw(10) << setprecision(3) << l.correction_norm << " Parameters:" << l.current(); return os; }