summaryrefslogtreecommitdiffstats
path: root/tests/Heun.cpp
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-10-06 20:44:32 -0400
committerTavian Barnes <tavianator@gmail.com>2010-10-06 20:44:32 -0400
commitd5639168232d1c111d6924b10c6abd74204abec1 (patch)
tree225caf58d60a885f2283b8e1eb0a220f6a2ab772 /tests/Heun.cpp
parentbc0b87a5cb49cda5f79f1f1374c33a26725d2dde (diff)
downloadvz-d5639168232d1c111d6924b10c6abd74204abec1.tar.xz
Add Heun's method.
Diffstat (limited to 'tests/Heun.cpp')
-rw-r--r--tests/Heun.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/Heun.cpp b/tests/Heun.cpp
new file mode 100644
index 0000000..758524b
--- /dev/null
+++ b/tests/Heun.cpp
@@ -0,0 +1,37 @@
+#include "vZ.hpp"
+#include <cmath>
+#include <cstdlib>
+#include <iostream>
+#include <iomanip>
+
+// y' = y (y == C*exp(t))
+double
+f(double t, double y)
+{
+ return y;
+}
+
+int
+main()
+{
+ vZ::HeunIntegrator integrator(f);
+ integrator.y(1.0).x(0.0).h(0.02);
+
+ integrator.integrate(2.0);
+
+ double actual = integrator.y();
+ double expected = std::exp(2.0);
+
+ std::cout << std::setprecision(10)
+ << "Numerical: " << actual << std::endl
+ << "Expected: " << expected << std::endl;
+
+ double error = std::fabs(expected - actual)/expected;
+ if (error > 1.4e-4) {
+ std::cerr << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_FAILURE;
+ } else {
+ std::cout << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_SUCCESS;
+ }
+}