[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 4fad56c 5/5: Recapitulate solve trace upon re
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 4fad56c 5/5: Recapitulate solve trace upon return |
Date: |
Sun, 18 Jul 2021 08:13:55 -0400 (EDT) |
branch: master
commit 4fad56c1276fddd9fd1dd2434a1860840a0476ef
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Recapitulate solve trace upon return
---
zero.hpp | 41 +++++++++++++++++++++++++++++++++++++++--
zero_test.cpp | 3 +++
2 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/zero.hpp b/zero.hpp
index 48367e1..dbaab9c 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -27,10 +27,10 @@
#include "null_stream.hpp"
#include "round_to.hpp"
-#include <cfloat> // DBL_EPSILON
+#include <cfloat> // DBL_EPSILON, DECIMAL_DIG
#include <cmath> // fabs(), pow()
#include <functional> // function(), identity()
-#include <iomanip> // setw()
+#include <iomanip> // setprecision(), setw()
#include <limits>
#include <ostream>
#include <utility> // forward()
@@ -310,6 +310,21 @@ root_type lmi_root
;
};
+ auto recapitulate = [&]()
+ {
+ os_trace
+ << n_iter
+ << " iterations; final interval:\n"
+ << std::setprecision(DECIMAL_DIG)
+ << std::showpos
+ << " b " << std::setw(12) << b
+ << " fb " << std::setw(12) << fb << "\n"
+ << " c " << std::setw(12) << c
+ << " fc " << std::setw(12) << fc
+ << std::endl
+ ;
+ };
+
double t = tolerance;
a = round_dec(bound0);
@@ -317,6 +332,7 @@ root_type lmi_root
if(a == b)
{
+ recapitulate();
return {a, improper_bounds, n_iter};
}
@@ -324,6 +340,7 @@ root_type lmi_root
++n_iter;
if(0.0 == fa) // Note 0.
{
+ recapitulate();
return {a, root_is_valid, n_iter};
}
@@ -332,12 +349,14 @@ root_type lmi_root
expatiate();
if(0.0 == fb) // Note 0 [bis].
{
+ recapitulate();
return {b, root_is_valid, n_iter};
}
// f(a) and f(b) must have different signs.
if((0.0 < fa) == (0.0 < fb))
{
+ recapitulate();
return {0.0, root_not_bracketed, n_iter};
}
@@ -375,10 +394,12 @@ root_type lmi_root
|| bias_higher == bias && 0.0 <= fb
)
{
+ recapitulate();
return {b, root_is_valid, n_iter};
}
else if(std::fabs(m) <= 2.0 * epsilon * std::fabs(c) + t)
{
+ recapitulate();
return {c, root_is_valid, n_iter};
}
else
@@ -569,6 +590,21 @@ double brent_zero
;
};
+ auto recapitulate = [&]()
+ {
+ os_trace
+ << n_iter
+ << " iterations; final interval:\n"
+ << std::setprecision(DECIMAL_DIG)
+ << std::showpos
+ << " b " << std::setw(12) << b
+ << " fb " << std::setw(12) << fb << "\n"
+ << " c " << std::setw(12) << c
+ << " fc " << std::setw(12) << fc
+ << std::endl
+ ;
+ };
+
fa = f(a);
++n_iter;
fb = f(b);
@@ -668,6 +704,7 @@ double brent_zero
else
{goto extrapolate;}
}
+ recapitulate();
return b;
}
diff --git a/zero_test.cpp b/zero_test.cpp
index bfcdf60..0601cfb 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -608,6 +608,9 @@ void test_celebrated_equation()
12 Q 2.0945514815423265 -8.8817841970012523e-16 2.0945514815423274
9.7699626167013776e-15 2.0945566700001779 5.7910818359374616e-05
12 j 2.0945514815423265 -8.8817841970012523e-16 2.0945514815423274
9.7699626167013776e-15 2.0945514815423265 -8.8817841970012523e-16
12 k 2.0945514815423274 9.7699626167013776e-15 2.0945514815423265
-8.8817841970012523e-16 2.0945514815423274 9.7699626167013776e-15
+12 iterations; final interval:
+ b +2.09455148154232650981 fb -8.88178419700125232339e-16
+ c +2.09455148154232739799 fc +9.76996261670137755573e-15
)--cut-here--";
LMI_TEST_EQUAL(verified, oss.str());