summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-10-11 02:38:46 -0400
committerTavian Barnes <tavianator@gmail.com>2010-10-11 02:38:46 -0400
commit2c2b69e1df183f118c45d74c18c7e84934aaff1f (patch)
tree20b71268a0024c751c7075fbb7ac7210f827c4d7 /tests
parentc9d71b99d4bf8c7eef40c043c8d7726962847667 (diff)
downloadvz-2c2b69e1df183f118c45d74c18c7e84934aaff1f.tar.xz
Support systems of ODEs.
Diffstat (limited to 'tests')
-rw-r--r--tests/EquationSystem.cpp46
-rw-r--r--tests/Makefile.am22
2 files changed, 58 insertions, 10 deletions
diff --git a/tests/EquationSystem.cpp b/tests/EquationSystem.cpp
new file mode 100644
index 0000000..973dd30
--- /dev/null
+++ b/tests/EquationSystem.cpp
@@ -0,0 +1,46 @@
+#include "vZ.hpp"
+#include <cmath>
+#include <cstdlib>
+#include <iostream>
+#include <iomanip>
+
+typedef vZ::EquationSystem<2> Y;
+
+// y'' = y (y == C*exp(t))
+Y
+f(double t, Y y)
+{
+ Y r;
+ r[0] = y[1];
+ r[1] = y[0];
+ return r;
+}
+
+int
+main()
+{
+ Y y;
+ y[0] = 1.0;
+ y[1] = 1.0;
+ vZ::GenericEulerIntegrator<Y> integrator(f);
+ integrator.y(y).x(0.0).h(0.01);
+
+ integrator.integrate(2.0);
+
+ double actual = integrator.y()[0];
+ double expected = std::exp(2.0);
+
+ std::cout << std::setprecision(10)
+ << "Numerical: " << actual << std::endl
+ << "Expected: " << expected << std::endl
+ << "Iterations: " << integrator.iterations() << std::endl;
+
+ double error = std::fabs(expected - actual)/expected;
+ if (error > 0.01) {
+ std::cerr << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_FAILURE;
+ } else {
+ std::cout << "Error: " << 100.0*error << "%" << std::endl;
+ return EXIT_SUCCESS;
+ }
+}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5874419..1cd184d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,15 +27,17 @@ check_PROGRAMS = Euler-test \
BS23-test \
RKF45-test \
CK45-test \
- DP45-test
+ DP45-test \
+ EquationSystem-test
TESTS = $(check_PROGRAMS)
-Euler_test_SOURCES = Euler.cpp
-Midpoint_test_SOURCES = Midpoint.cpp
-Heun_test_SOURCES = Heun.cpp
-RK4_test_SOURCES = RK4.cpp
-HE12_test_SOURCES = HE12.cpp
-BS23_test_SOURCES = BS23.cpp
-RKF45_test_SOURCES = RKF45.cpp
-CK45_test_SOURCES = CK45.cpp
-DP45_test_SOURCES = DP45.cpp
+Euler_test_SOURCES = Euler.cpp
+Midpoint_test_SOURCES = Midpoint.cpp
+Heun_test_SOURCES = Heun.cpp
+RK4_test_SOURCES = RK4.cpp
+HE12_test_SOURCES = HE12.cpp
+BS23_test_SOURCES = BS23.cpp
+RKF45_test_SOURCES = RKF45.cpp
+CK45_test_SOURCES = CK45.cpp
+DP45_test_SOURCES = DP45.cpp
+EquationSystem_test_SOURCES = EquationSystem.cpp