# source:projects/ckbs/trunk/test/kuhn_tucker_ok.m@95

Last change on this file since 95 was 35, checked in by bradbell, 11 years ago

File size: 1.9 KB
Line
1% -------------------------------------------------------------------
2% ckbs: Constrained Kalman-Bucy Smoother Program: Copyright (C) 2006
4%          Gianluigi Pillonetto: giapi at dei dot unipd dot it
6% -------------------------------------------------------------------
7% \$begin kuhn_tucker_ok.m\$\$ \$newlinech %\$\$
8% \$spell
9%       ckbs
10%       Bdiag
11%       blk
12%       blkdiag
13%       mul
14%       Kuhn
15%       mu
16%       Bdia
17%       Hdia
18%       Hlow
19% \$\$
20%
21% \$section ckbs_kuhn_tucker Example and Test\$\$
22%
23% \$index ckbs_kuhn_tucker, example and test\$\$
24% \$index kuhn_tucker, example and test\$\$
25% \$index example, kuhn_tucker\$\$
26% \$index test, kuhn_tucker\$\$
27%
29% \$newlinech \$\$ \$codep
30function [ok] = kuhn_tucker_ok()
31ok = true;
32% -------------------------------------------------------------
33% You can change these parameters
34m    = 5;
35n    = 4;
36N    = 3;
37% -------------------------------------------------------------
38rand('seed', 123);
39p     = n * N;
40r     = m * N;
41mu    = 1.5;
42s     = rand(r, 1);
43y     = rand(p, 1);
44u     = rand(r, 1);
45b     = rand(r, 1);
46d     = rand(p, 1);
47Bdia  = rand(m, n, N);
48Hdia  = rand(n, n, N);
49Hlow  = rand(n, n, N);
50B     = zeros(r, p);
51H     = zeros(p, p);
52blk_n = 1 : n;
53blk_m = 1 : m;
54for k = 1 : N
55        B(blk_m, blk_n) = Bdia(:,:, k);
56        H(blk_n, blk_n) = Hdia(:,:, k);
57        blk_n           = blk_n + n;
58        blk_m           = blk_m + m;
59end
60blk_n = 1 : n;
61for k = 2 : N;
62        blk_minus           = blk_n;
63        blk_n               = blk_n + n;
64        H(blk_n, blk_minus) = Hlow(:,:, k);
65        H(blk_minus, blk_n) = Hlow(:,:, k)';
66end
67% -------------------------------------
68F = ckbs_kuhn_tucker(mu, s, y, u, b, d, Bdia, Hdia, Hlow);
69% -------------------------------------
70check = [ ...
71        s + b + B * y; ...
72        H * y + B' * u + d; ...
73        s .* u - mu ...
74];
75ok    = ok & ( max(abs(F - check)) < 1e-10 );
76return
77end
78% \$\$ \$newlinech %\$\$
79% \$end
Note: See TracBrowser for help on using the repository browser.