]> gitweb.michael.orlitzky.com - octave.git/blobdiff - tests/conjugate_gradient_method_tests.m
Add first implementation of the conjugate gradient method and its tests.
[octave.git] / tests / conjugate_gradient_method_tests.m
diff --git a/tests/conjugate_gradient_method_tests.m b/tests/conjugate_gradient_method_tests.m
new file mode 100644 (file)
index 0000000..56987a5
--- /dev/null
@@ -0,0 +1,16 @@
+A = [5,1,2; ...
+     1,6,3;
+     2,3,7];
+
+b = [1;2;3];
+
+x0 = [1;1;1];
+
+## Solved over the rationals.
+expected = [2/73; 11/73; 26/73];
+actual = conjugate_gradient_method(A, b, x0, 1e-6);
+diff = norm(actual - expected);
+
+unit_test_equals("CGM works on an example", ...
+                true, ...
+                norm(diff) < 1e-6);