From 2c2b69e1df183f118c45d74c18c7e84934aaff1f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 11 Oct 2010 02:38:46 -0400 Subject: Support systems of ODEs. --- tests/EquationSystem.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/EquationSystem.cpp (limited to 'tests/EquationSystem.cpp') 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 +#include +#include +#include + +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 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; + } +} -- cgit v1.2.3