Fix up preconditioned CGM code.
[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 b = [1;2;3];
7 x0 = [1;1;1];
8
9 cgm = conjugate_gradient_method(A, b, x0, 1e-6, 1000);
10 pcgm = preconditioned_conjugate_gradient_method(A, M, b, x0, 1e-6, 1000);
11 diff = norm(cgm - pcgm);
12
13 unit_test_equals("PCGM agrees with CGM when M == I", ...
14 true, ...
15 norm(diff) < 1e-6);
16
17 pcgm_simple = simple_preconditioned_cgm(A, M, b, x0, 1e-6, 1000);
18 diff = norm(pcgm_simple - pcgm);
19
20 unit_test_equals("PCGM agrees with SimplePCGM when M == I", ...
21 true, ...
22 norm(diff) < 1e-6);
23
24 ## Needs to be symmetric!
25 M = [0.97466, 0.24345, 0.54850; ...
26 0.24345, 0.73251, 0.76639; ...
27 0.54850, 0.76639, 1.47581];
28
29 pcgm = preconditioned_conjugate_gradient_method(A, M, b, x0, 1e-6, 1000);
30 diff = norm(cgm - pcgm);
31
32 unit_test_equals("PCGM agrees with CGM when M != I", ...
33 true, ...
34 norm(diff) < 1e-6);
35
36
37 pcgm_simple = simple_preconditioned_cgm(A, M, b, x0, 1e-6, 1000);
38 diff = norm(pcgm_simple - pcgm);
39
40 unit_test_equals("PCGM agrees with Simple PCGM when M != I", ...
41 true, ...
42 norm(diff) < 1e-6);