diff --git a/src/test-gradient-method.cc b/src/test-gradient-method.cc index 9174af838a2d0df937e48f0e81f2a3f7d8a7cc45..9c33600628ec9bfb0d74bcb35649cd6e08b729ee 100644 --- a/src/test-gradient-method.cc +++ b/src/test-gradient-method.cc @@ -8,6 +8,8 @@ #include "samplefunctional.hh" +#include <cassert> + template <int dim, class Function> void functionTester( Dune::SampleFunctional<dim, Function> J, @@ -42,6 +44,19 @@ void testSampleFunction() { SampleFunctional::SmallVector start = b; start *= 17; + /* + j(x) + = Ax - b + 2/|x| x + = 17*(6, 9.5) - (1, 2) + 2/sqrt(5) (1, 2) + = (102 - 1 + 2/sqrt(5), 161.5 - 2 + 4/sqrt(5)) + */ + SampleFunctional::SmallVector error; + error[0] = -(102 - 1 + 2 / sqrt(5)); + error[1] = -(161.5 - 2 + 4 / sqrt(5)); + SampleFunctional::SmallVector returned = J.descentDirection(start); + error -= returned; + assert(error.two_norm() < 1e-10); // FIXME: 1e-10 sounds reasonable. Is it? + functionTester(J, start, 6); } @@ -63,6 +78,19 @@ void testTrivialFunction() { SampleFunctional::SmallVector start = b; start *= 17; + /* + j(x) + = Ax - b + = 17*(6, 9.5) - (1, 2) + = (102 - 1, 161.5 - 2) + */ + SampleFunctional::SmallVector error; + error[0] = -101; + error[1] = -159.5; + SampleFunctional::SmallVector returned = J.descentDirection(start); + error -= returned; + assert(error.two_norm() < 1e-10); // FIXME: 1e-10 sounds reasonable. Is it? + functionTester(J, start, 5); }