]> gitweb.michael.orlitzky.com - octave.git/blob - tests/preconditioned_conjugate_gradient_method_tests.m
Add the first working version of the preconditioned CGM.
[octave.git] / tests / preconditioned_conjugate_gradient_method_tests.m
1 A = [5,1,2; ...
2 1,6,3; ...
3 2,3,7];
4
5 M = eye(3);
6
7 b = [1;2;3];
8
9 x0 = [1;1;1];
10
11 ## Solved over the rationals.
12 cgm = conjugate_gradient_method(A, b, x0, 1e-6, 1000);
13 pcgm = preconditioned_conjugate_gradient_method(A, M, b, x0, 1e-6, 1000);
14 diff = norm(cgm - pcgm);
15
16 unit_test_equals("PCGM agrees with CGM when M == I", ...
17 true, ...
18 norm(diff) < 1e-6);
19
20
21 ## Needs to be symmetric!
22 M = [0.97466, 0.24345, 0.54850; ...
23 0.24345, 0.73251, 0.76639; ...
24 0.54850, 0.76639, 1.47581];
25
26 pcgm = preconditioned_conjugate_gradient_method(A, M, b, x0, 1e-6, 1000);
27 diff = norm(cgm - pcgm);
28
29 unit_test_equals("PCGM agrees with CGM when M != I", ...
30 true, ...
31 norm(diff) < 1e-6);