source: projects/ckbs/stable/0.20100228/doc/_printable.htm @ 92

Last change on this file since 92 was 92, checked in by bradbell, 12 years ago

[ckbs/trunk] Change download instructions

ckbs.omh: move from here to ckbs.omh.
ckbs.omh: move to here from omh/ckbs.omh and change download instructions.

The changes in doc/* were automatically transferred from ckbs.omh.
_ckbs_xml.js:
ckbs.htm:
ckbs.xml:
index.htm:
_external.htm:
_printable.htm:
index.xml:
_external.xml:
_ckbs_htm.js:
_printable.xml:
copy_doc.sh:
build_doc.sh:

File size: 257.6 KB
Line 
1<html>
2<head><title>ckbs-0.20100228.0: A Constrained Kalman-Bucy Smoother</title></head>
3<body>
4
5<hr>
6<code>
7<span style='white-space: nowrap'>&nbsp;\newcommand{\T}{{\rm&nbsp;T}}</span></code>
8
9<code>
10<span style='white-space: nowrap'>&nbsp;\newcommand{\R}{{\bf&nbsp;R}}</span></code>
11
12
13
14
15
16<center><b><big><big>ckbs-0.20100228.0: A Constrained Kalman-Bucy Smoother</big></big></b></center>
17<br>
18<b><big><a name="a" id="a">a: MathML</a></big></b>
19<br>
20This documentation is in XHTML + MathML.
21If you have trouble viewing it in your browser see
22Viewing MathML on the web page
23<code><span style='white-space: nowrap'><br>
24&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></code>
25        <a href="http://www.seanet.com/~bradbell/packages.htm" target="_top"><span style='white-space: nowrap'>http://www.seanet.com/~bradbell/packages.htm</span></a>
26
27
28<br>
29<br>
30<b><big><a name="b" id="b">b: System Requirements</a></big></b>
31<br>
32This constrained Kalman-Bucy smoother runs under both the
33<a href="http://www.mathworks.com/" target="_top"><span style='white-space: nowrap'>Matlab&#174;</span></a>
34 (http://www.mathworks.com/)
35and
36<a href="http://www.gnu.org/software/octave/" target="_top"><span style='white-space: nowrap'>Octave</span></a>
37 (http://www.gnu.org/software/octave/)
38While it will work under MS windows,
39these download instructions are for the Unix operating system.
40
41<br>
42<br>
43<b><big><a name="c" id="c">c: Download</a></big></b>
44
45
46<br>
47<br>
48<b><a name="c.a" id="c.a">c.a: Release Tarballs</a></b>
49<br>
50You can download a tarball release of ckbs from the directory
51<code><span style='white-space: nowrap'><br>
52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></code>
53<a href="http://www.coin-or.org/download/source/CoinBazaar" target="_top"><span style='white-space: nowrap'>http://www.coin-or.org/download/source/CoinBazaar</span></a>
54
55<code><span style='white-space: nowrap'><br>
56</span></code>Theses releases are named
57
58<code><font color="blue"><span style='white-space: nowrap'><br>
59&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>ext</span></font></i><font color="blue"><span style='white-space: nowrap'><br>
60</span></font></code>
61where
62<code><i><font color="black"><span style='white-space: nowrap'>yyyy</span></font></i></code>
63 is the year,
64
65<code><i><font color="black"><span style='white-space: nowrap'>mm</span></font></i></code>
66 is the month,
67
68<code><i><font color="black"><span style='white-space: nowrap'>dd</span></font></i></code>
69 is the day,
70
71<code><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
72 is the release number,
73and
74<code><i><font color="black"><span style='white-space: nowrap'>ext</span></font></i></code>
75 is <code><font color="blue">tgz</font></code> or <code><font color="blue">zip</font></code>.
76<code><span style='white-space: nowrap'><br>
77<br>
78</span></code>If
79<code><i><font color="black"><span style='white-space: nowrap'>ext</span></font></i></code>
80 is <code><font color="blue">tgz</font></code> the command
81
82<code><font color="blue"><span style='white-space: nowrap'><br>
83&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tar&nbsp;-xvzf&nbsp;ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>.tgz<br>
84</span></font></code>
85will create the
86<code><font color="blue"><span style='white-space: nowrap'>ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
87 directory.
88<code><span style='white-space: nowrap'><br>
89<br>
90</span></code>If
91<code><i><font color="black"><span style='white-space: nowrap'>ext</span></font></i></code>
92 is <code><font color="blue">zip</font></code> the command
93
94<code><font color="blue"><span style='white-space: nowrap'><br>
95&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unzip&nbsp;ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>.zip<br>
96</span></font></code>
97will create the
98<code><font color="blue"><span style='white-space: nowrap'>ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
99 directory.
100
101<br>
102<br>
103<b><a name="c.b" id="c.b">c.b: Using Subversion</a></b>
104<br>
105For each release listed in the
106<a href="http://www.coin-or.org/download/source/CoinBazaar" target="_top"><span style='white-space: nowrap'>download&nbsp;directory</span></a>
107 (http://www.coin-or.org/download/source/CoinBazaar)
108you can use subversion to download the release with the commands
109
110<code><font color="blue"><span style='white-space: nowrap'><br>
111&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;web=&quot;https://projects.coin-or.org/svn/CoinBazaar/projects/ckbs&quot;<br>
112&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;svn&nbsp;checkout&nbsp;$web/releases/0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>&nbsp;ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'><br>
113</span></font></code>
114This will create the
115<code><font color="blue"><span style='white-space: nowrap'>ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
116 directory.
117
118<br>
119<br>
120<b><a name="c.c" id="c.c">c.c: Latest Version</a></b>
121<br>
122You can download the most recent version of ckbs (called the trunk)
123using the commands
124
125<code><font color="blue"><span style='white-space: nowrap'><br>
126&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;web=&quot;https://projects.coin-or.org/svn/CoinBazaar/projects/ckbs&quot;<br>
127&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;svn&nbsp;checkout&nbsp;$web/trunk&nbsp;ckbs-0.20100228.0<br>
128</span></font></code>
129This will create the <code><font color="blue">ckbs-0.20100228.0</font></code> directory.
130
131<br>
132<br>
133<b><big><a name="d" id="d">d: Test Install</a></big></b>
134<br>
135Using Matlab&#174; or Octave, to change into the directory
136
137<code><font color="blue"><span style='white-space: nowrap'><br>
138&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>/test<br>
139</span></font></code>
140and run the program <code><font color="blue">all_ok.m</font></code>.
141It will print the test results for all the components of <code><font color="blue">ckbs</font></code>.
142
143<br>
144<br>
145<b><big><a name="e" id="e">e: Documentation</a></big></b>
146<br>
147If you download a release, a copy of the documentation for the release
148can be found be viewed in your browser by opening the file
149
150<code><font color="blue"><span style='white-space: nowrap'><br>
151&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ckbs-0.</span></font><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i><font color="blue"><span style='white-space: nowrap'>.</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>/doc/ckbs.xml<br>
152<br>
153</span></font></code>
154If you download the latest version (the trunk),
155a copy of the documentation for this version can
156be built by executing the commands
157<code><font color='blue'><pre style='display:inline'> 
158        cd ckbs-0.20100228.0
159        ./build_doc.sh
160</pre></font></code>
161
162You can then view the documentation in your browser by opening the file
163
164<code><font color="blue"><span style='white-space: nowrap'><br>
165&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ckbs-0.20100228.0/doc/ckbs.xml<br>
166</span></font></code>
167<br>
168<b><big><a name="f" id="f">f: Contents</a></big></b>
169<br>
170<table>
171<tr><td><a href="#1" target="_top">_contents:&nbsp;1</a></td><td>Table&nbsp;of&nbsp;Contents</td></tr><tr><td><a href="#2" target="_top">license:&nbsp;2</a></td><td>Your&nbsp;License&nbsp;to&nbsp;use&nbsp;the&nbsp;ckbs&nbsp;Software</td></tr><tr><td><a href="#3" target="_top">ckbs_nonlinear:&nbsp;3</a></td><td>The&nbsp;Nonlinear&nbsp;Constrained&nbsp;Kalman-Bucy&nbsp;Smoother</td></tr><tr><td><a href="#4" target="_top">ckbs_affine:&nbsp;4</a></td><td>Constrained&nbsp;Affine&nbsp;Kalman&nbsp;Bucy&nbsp;Smoother</td></tr><tr><td><a href="#5" target="_top">utility:&nbsp;5</a></td><td>ckbs&nbsp;Utility&nbsp;Functions</td></tr><tr><td><a href="#6" target="_top">all_ok.m:&nbsp;6</a></td><td>Run&nbsp;All&nbsp;Correctness&nbsp;Tests</td></tr><tr><td><a href="#7" target="_top">whatsnew:&nbsp;7</a></td><td>Changes&nbsp;and&nbsp;Additions&nbsp;to&nbsp;ckbs</td></tr><tr><td><a href="#8" target="_top">_reference:&nbsp;8</a></td><td>Alphabetic&nbsp;Listing&nbsp;of&nbsp;Cross&nbsp;Reference&nbsp;Tags</td></tr><tr><td><a href="#9" target="_top">_index:&nbsp;9</a></td><td>Keyword&nbsp;Index</td></tr><tr><td><a href="#10" target="_top">_external:&nbsp;10</a></td><td>External&nbsp;Internet&nbsp;References</td></tr></table>
172<hr>Input File: ckbs.omh
173
174<hr>
175<center><b><big><big>
1761: Table of Contents</big></big></b></center>
177
178<pre>
179ckbs-0.20100228.0: A Constrained Kalman-Bucy Smoother: <a href="#">: ckbs</a>
180    Table of Contents: <a href="#1">1: _contents</a>
181    Your License to use the ckbs Software: <a href="#2">2: license</a>
182    The Nonlinear Constrained Kalman-Bucy Smoother: <a href="#3">3: ckbs_nonlinear</a>
183        Simple ckbs_nonlinear Example and Test: <a href="#3.1">3.1: nonlinear_ok_simple.m</a>
184            Example Constraint Function: nonlinear_ok_simple_f: <a href="#3.1.1">3.1.1: nonlinear_ok_simple_f.m</a>
185            Example Transition Function: nonlinear_ok_simple_g: <a href="#3.1.2">3.1.2: nonlinear_ok_simple_g.m</a>
186            Example Measurement Function: nonlinear_ok_simple_h: <a href="#3.1.3">3.1.3: nonlinear_ok_simple_h.m</a>
187        ckbs_nonlinear Box Constrained Tracking Example and Test: <a href="#3.2">3.2: nonlinear_ok_box.m</a>
188            Example Constraint Function: nonlinear_ok_box_f: <a href="#3.2.1">3.2.1: nonlinear_ok_box_f.m</a>
189            Example Transition Function: nonlinear_ok_box_g: <a href="#3.2.2">3.2.2: nonlinear_ok_box_g.m</a>
190            Example Measurement Function: nonlinear_ok_box_h: <a href="#3.2.3">3.2.3: nonlinear_ok_box_h.m</a>
191            Example no Constraint Function: nonlinear_ok_box_nof: <a href="#3.2.4">3.2.4: nonlinear_ok_box_nof.m</a>
192        ckbs_nonlinear Sine Wave Constrained Tracking Example and Test: <a href="#3.3">3.3: nonlinear_ok_sin.m</a>
193            Example Constraint Function: nonlinear_ok_sin_f: <a href="#3.3.1">3.3.1: nonlinear_ok_sin_f.m</a>
194    Constrained Affine Kalman Bucy Smoother: <a href="#4">4: ckbs_affine</a>
195        ckbs_affine Box Constrained Smoothing Spline Example and Test: <a href="#4.1">4.1: affine_ok_box.m</a>
196    ckbs Utility Functions: <a href="#5">5: utility</a>
197        Packed Block Diagonal Matrix Times a Vector: <a href="#5.1">5.1: ckbs_blkdiag_mul</a>
198            blkdiag_mul Example and Test: <a href="#5.1.1">5.1.1: blkdiag_mul_ok.m</a>
199        Transpose of Packed Block Diagonal Matrix Times a Vector: <a href="#5.2">5.2: ckbs_blkdiag_mul_t</a>
200            blkdiag_mul_t Example and Test: <a href="#5.2.1">5.2.1: blkdiag_mul_t_ok.m</a>
201        Affine Residual Sum of Squares Objective: <a href="#5.3">5.3: ckbs_sumsq_obj</a>
202            ckbs_sumsq_obj Example and Test: <a href="#5.3.1">5.3.1: sumsq_obj_ok.m</a>
203        Affine Residual Sum of Squares Gradient: <a href="#5.4">5.4: ckbs_sumsq_grad</a>
204            ckbs_sumsq_grad Example and Test: <a href="#5.4.1">5.4.1: sumsq_grad_ok.m</a>
205        Affine Residual Sum of Squares Hessian: <a href="#5.5">5.5: ckbs_sumsq_hes</a>
206            ckbs_sumsq_hes Example and Test: <a href="#5.5.1">5.5.1: sumsq_hes_ok.m</a>
207        Symmetric Block Tridiagonal Algorithm: <a href="#5.6">5.6: ckbs_tridiag_solve</a>
208            ckbs_tridiag_solve Example and Test: <a href="#5.6.1">5.6.1: tridiag_solve_ok.m</a>
209        Affine Constrained Kalman Bucy Smoother Newton Step: <a href="#5.7">5.7: ckbs_newton_step</a>
210            ckbs_newton_step Example and Test: <a href="#5.7.1">5.7.1: newton_step_ok.m</a>
211        Compute Residual in Kuhn-Tucker Conditions: <a href="#5.8">5.8: ckbs_kuhn_tucker</a>
212            ckbs_kuhn_tucker Example and Test: <a href="#5.8.1">5.8.1: kuhn_tucker_ok.m</a>
213    Run All Correctness Tests: <a href="#6">6: all_ok.m</a>
214        Ensure Path is Set for Testing: <a href="#6.1">6.1: test_path.m</a>
215    Changes and Additions to ckbs: <a href="#7">7: whatsnew</a>
216    Alphabetic Listing of Cross Reference Tags: <a href="#8">8: _reference</a>
217    Keyword Index: <a href="#9">9: _index</a>
218    External Internet References: <a href="#10">10: _external</a>
219</pre>
220<hr>
221<center><b><big><big><a name="2" id="2">2: Your License to use the ckbs Software</a>
222</big></big></b></center>
223<code><span style='white-space: nowrap'><br>
224&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GNU&nbsp;GENERAL&nbsp;PUBLIC&nbsp;LICENSE<br>
225&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Version&nbsp;2,&nbsp;June&nbsp;1991<br>
226<br>
227&nbsp;Copyright&nbsp;(C)&nbsp;1989,&nbsp;1991&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;Inc.,<br>
228&nbsp;51&nbsp;Franklin&nbsp;Street,&nbsp;Fifth&nbsp;Floor,&nbsp;Boston,&nbsp;MA&nbsp;02110-1301&nbsp;USA<br>
229&nbsp;Everyone&nbsp;is&nbsp;permitted&nbsp;to&nbsp;copy&nbsp;and&nbsp;distribute&nbsp;verbatim&nbsp;copies<br>
230&nbsp;of&nbsp;this&nbsp;license&nbsp;document,&nbsp;but&nbsp;changing&nbsp;it&nbsp;is&nbsp;not&nbsp;allowed.<br>
231<br>
232&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Preamble<br>
233<br>
234&nbsp;&nbsp;The&nbsp;licenses&nbsp;for&nbsp;most&nbsp;software&nbsp;are&nbsp;designed&nbsp;to&nbsp;take&nbsp;away&nbsp;your<br>
235freedom&nbsp;to&nbsp;share&nbsp;and&nbsp;change&nbsp;it.&nbsp;&nbsp;By&nbsp;contrast,&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public<br>
236License&nbsp;is&nbsp;intended&nbsp;to&nbsp;guarantee&nbsp;your&nbsp;freedom&nbsp;to&nbsp;share&nbsp;and&nbsp;change&nbsp;free<br>
237software--to&nbsp;make&nbsp;sure&nbsp;the&nbsp;software&nbsp;is&nbsp;free&nbsp;for&nbsp;all&nbsp;its&nbsp;users.&nbsp;&nbsp;This<br>
238General&nbsp;Public&nbsp;License&nbsp;applies&nbsp;to&nbsp;most&nbsp;of&nbsp;the&nbsp;Free&nbsp;Software<br>
239Foundation's&nbsp;software&nbsp;and&nbsp;to&nbsp;any&nbsp;other&nbsp;program&nbsp;whose&nbsp;authors&nbsp;commit&nbsp;to<br>
240using&nbsp;it.&nbsp;&nbsp;(Some&nbsp;other&nbsp;Free&nbsp;Software&nbsp;Foundation&nbsp;software&nbsp;is&nbsp;covered&nbsp;by<br>
241the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;instead.)&nbsp;&nbsp;You&nbsp;can&nbsp;apply&nbsp;it&nbsp;to<br>
242your&nbsp;programs,&nbsp;too.<br>
243<br>
244&nbsp;&nbsp;When&nbsp;we&nbsp;speak&nbsp;of&nbsp;free&nbsp;software,&nbsp;we&nbsp;are&nbsp;referring&nbsp;to&nbsp;freedom,&nbsp;not<br>
245price.&nbsp;&nbsp;Our&nbsp;General&nbsp;Public&nbsp;Licenses&nbsp;are&nbsp;designed&nbsp;to&nbsp;make&nbsp;sure&nbsp;that&nbsp;you<br>
246have&nbsp;the&nbsp;freedom&nbsp;to&nbsp;distribute&nbsp;copies&nbsp;of&nbsp;free&nbsp;software&nbsp;(and&nbsp;charge&nbsp;for<br>
247this&nbsp;service&nbsp;if&nbsp;you&nbsp;wish),&nbsp;that&nbsp;you&nbsp;receive&nbsp;source&nbsp;code&nbsp;or&nbsp;can&nbsp;get&nbsp;it<br>
248if&nbsp;you&nbsp;want&nbsp;it,&nbsp;that&nbsp;you&nbsp;can&nbsp;change&nbsp;the&nbsp;software&nbsp;or&nbsp;use&nbsp;pieces&nbsp;of&nbsp;it<br>
249in&nbsp;new&nbsp;free&nbsp;programs;&nbsp;and&nbsp;that&nbsp;you&nbsp;know&nbsp;you&nbsp;can&nbsp;do&nbsp;these&nbsp;things.<br>
250<br>
251&nbsp;&nbsp;To&nbsp;protect&nbsp;your&nbsp;rights,&nbsp;we&nbsp;need&nbsp;to&nbsp;make&nbsp;restrictions&nbsp;that&nbsp;forbid<br>
252anyone&nbsp;to&nbsp;deny&nbsp;you&nbsp;these&nbsp;rights&nbsp;or&nbsp;to&nbsp;ask&nbsp;you&nbsp;to&nbsp;surrender&nbsp;the&nbsp;rights.<br>
253These&nbsp;restrictions&nbsp;translate&nbsp;to&nbsp;certain&nbsp;responsibilities&nbsp;for&nbsp;you&nbsp;if&nbsp;you<br>
254distribute&nbsp;copies&nbsp;of&nbsp;the&nbsp;software,&nbsp;or&nbsp;if&nbsp;you&nbsp;modify&nbsp;it.<br>
255<br>
256&nbsp;&nbsp;For&nbsp;example,&nbsp;if&nbsp;you&nbsp;distribute&nbsp;copies&nbsp;of&nbsp;such&nbsp;a&nbsp;program,&nbsp;whether<br>
257gratis&nbsp;or&nbsp;for&nbsp;a&nbsp;fee,&nbsp;you&nbsp;must&nbsp;give&nbsp;the&nbsp;recipients&nbsp;all&nbsp;the&nbsp;rights&nbsp;that<br>
258you&nbsp;have.&nbsp;&nbsp;You&nbsp;must&nbsp;make&nbsp;sure&nbsp;that&nbsp;they,&nbsp;too,&nbsp;receive&nbsp;or&nbsp;can&nbsp;get&nbsp;the<br>
259source&nbsp;code.&nbsp;&nbsp;And&nbsp;you&nbsp;must&nbsp;show&nbsp;them&nbsp;these&nbsp;terms&nbsp;so&nbsp;they&nbsp;know&nbsp;their<br>
260rights.<br>
261<br>
262&nbsp;&nbsp;We&nbsp;protect&nbsp;your&nbsp;rights&nbsp;with&nbsp;two&nbsp;steps:&nbsp;(1)&nbsp;copyright&nbsp;the&nbsp;software,&nbsp;and<br>
263(2)&nbsp;offer&nbsp;you&nbsp;this&nbsp;license&nbsp;which&nbsp;gives&nbsp;you&nbsp;legal&nbsp;permission&nbsp;to&nbsp;copy,<br>
264distribute&nbsp;and/or&nbsp;modify&nbsp;the&nbsp;software.<br>
265<br>
266&nbsp;&nbsp;Also,&nbsp;for&nbsp;each&nbsp;author's&nbsp;protection&nbsp;and&nbsp;ours,&nbsp;we&nbsp;want&nbsp;to&nbsp;make&nbsp;certain<br>
267that&nbsp;everyone&nbsp;understands&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;warranty&nbsp;for&nbsp;this&nbsp;free<br>
268software.&nbsp;&nbsp;If&nbsp;the&nbsp;software&nbsp;is&nbsp;modified&nbsp;by&nbsp;someone&nbsp;else&nbsp;and&nbsp;passed&nbsp;on,&nbsp;we<br>
269want&nbsp;its&nbsp;recipients&nbsp;to&nbsp;know&nbsp;that&nbsp;what&nbsp;they&nbsp;have&nbsp;is&nbsp;not&nbsp;the&nbsp;original,&nbsp;so<br>
270that&nbsp;any&nbsp;problems&nbsp;introduced&nbsp;by&nbsp;others&nbsp;will&nbsp;not&nbsp;reflect&nbsp;on&nbsp;the&nbsp;original<br>
271authors'&nbsp;reputations.<br>
272<br>
273&nbsp;&nbsp;Finally,&nbsp;any&nbsp;free&nbsp;program&nbsp;is&nbsp;threatened&nbsp;constantly&nbsp;by&nbsp;software<br>
274patents.&nbsp;&nbsp;We&nbsp;wish&nbsp;to&nbsp;avoid&nbsp;the&nbsp;danger&nbsp;that&nbsp;redistributors&nbsp;of&nbsp;a&nbsp;free<br>
275program&nbsp;will&nbsp;individually&nbsp;obtain&nbsp;patent&nbsp;licenses,&nbsp;in&nbsp;effect&nbsp;making&nbsp;the<br>
276program&nbsp;proprietary.&nbsp;&nbsp;To&nbsp;prevent&nbsp;this,&nbsp;we&nbsp;have&nbsp;made&nbsp;it&nbsp;clear&nbsp;that&nbsp;any<br>
277patent&nbsp;must&nbsp;be&nbsp;licensed&nbsp;for&nbsp;everyone's&nbsp;free&nbsp;use&nbsp;or&nbsp;not&nbsp;licensed&nbsp;at&nbsp;all.<br>
278<br>
279&nbsp;&nbsp;The&nbsp;precise&nbsp;terms&nbsp;and&nbsp;conditions&nbsp;for&nbsp;copying,&nbsp;distribution&nbsp;and<br>
280modification&nbsp;follow.<br>
281<br>
282&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GNU&nbsp;GENERAL&nbsp;PUBLIC&nbsp;LICENSE<br>
283&nbsp;&nbsp;&nbsp;TERMS&nbsp;AND&nbsp;CONDITIONS&nbsp;FOR&nbsp;COPYING,&nbsp;DISTRIBUTION&nbsp;AND&nbsp;MODIFICATION<br>
284<br>
285&nbsp;&nbsp;0.&nbsp;This&nbsp;License&nbsp;applies&nbsp;to&nbsp;any&nbsp;program&nbsp;or&nbsp;other&nbsp;work&nbsp;which&nbsp;contains<br>
286a&nbsp;notice&nbsp;placed&nbsp;by&nbsp;the&nbsp;copyright&nbsp;holder&nbsp;saying&nbsp;it&nbsp;may&nbsp;be&nbsp;distributed<br>
287under&nbsp;the&nbsp;terms&nbsp;of&nbsp;this&nbsp;General&nbsp;Public&nbsp;License.&nbsp;&nbsp;The&nbsp;&quot;Program&quot;,&nbsp;below,<br>
288refers&nbsp;to&nbsp;any&nbsp;such&nbsp;program&nbsp;or&nbsp;work,&nbsp;and&nbsp;a&nbsp;&quot;work&nbsp;based&nbsp;on&nbsp;the&nbsp;Program&quot;<br>
289means&nbsp;either&nbsp;the&nbsp;Program&nbsp;or&nbsp;any&nbsp;derivative&nbsp;work&nbsp;under&nbsp;copyright&nbsp;law:<br>
290that&nbsp;is&nbsp;to&nbsp;say,&nbsp;a&nbsp;work&nbsp;containing&nbsp;the&nbsp;Program&nbsp;or&nbsp;a&nbsp;portion&nbsp;of&nbsp;it,<br>
291either&nbsp;verbatim&nbsp;or&nbsp;with&nbsp;modifications&nbsp;and/or&nbsp;translated&nbsp;into&nbsp;another<br>
292language.&nbsp;&nbsp;(Hereinafter,&nbsp;translation&nbsp;is&nbsp;included&nbsp;without&nbsp;limitation&nbsp;in<br>
293the&nbsp;term&nbsp;&quot;modification&quot;.)&nbsp;&nbsp;Each&nbsp;licensee&nbsp;is&nbsp;addressed&nbsp;as&nbsp;&quot;you&quot;.<br>
294<br>
295Activities&nbsp;other&nbsp;than&nbsp;copying,&nbsp;distribution&nbsp;and&nbsp;modification&nbsp;are&nbsp;not<br>
296covered&nbsp;by&nbsp;this&nbsp;License;&nbsp;they&nbsp;are&nbsp;outside&nbsp;its&nbsp;scope.&nbsp;&nbsp;The&nbsp;act&nbsp;of<br>
297running&nbsp;the&nbsp;Program&nbsp;is&nbsp;not&nbsp;restricted,&nbsp;and&nbsp;the&nbsp;output&nbsp;from&nbsp;the&nbsp;Program<br>
298is&nbsp;covered&nbsp;only&nbsp;if&nbsp;its&nbsp;contents&nbsp;constitute&nbsp;a&nbsp;work&nbsp;based&nbsp;on&nbsp;the<br>
299Program&nbsp;(independent&nbsp;of&nbsp;having&nbsp;been&nbsp;made&nbsp;by&nbsp;running&nbsp;the&nbsp;Program).<br>
300Whether&nbsp;that&nbsp;is&nbsp;true&nbsp;depends&nbsp;on&nbsp;what&nbsp;the&nbsp;Program&nbsp;does.<br>
301<br>
302&nbsp;&nbsp;1.&nbsp;You&nbsp;may&nbsp;copy&nbsp;and&nbsp;distribute&nbsp;verbatim&nbsp;copies&nbsp;of&nbsp;the&nbsp;Program's<br>
303source&nbsp;code&nbsp;as&nbsp;you&nbsp;receive&nbsp;it,&nbsp;in&nbsp;any&nbsp;medium,&nbsp;provided&nbsp;that&nbsp;you<br>
304conspicuously&nbsp;and&nbsp;appropriately&nbsp;publish&nbsp;on&nbsp;each&nbsp;copy&nbsp;an&nbsp;appropriate<br>
305copyright&nbsp;notice&nbsp;and&nbsp;disclaimer&nbsp;of&nbsp;warranty;&nbsp;keep&nbsp;intact&nbsp;all&nbsp;the<br>
306notices&nbsp;that&nbsp;refer&nbsp;to&nbsp;this&nbsp;License&nbsp;and&nbsp;to&nbsp;the&nbsp;absence&nbsp;of&nbsp;any&nbsp;warranty;<br>
307and&nbsp;give&nbsp;any&nbsp;other&nbsp;recipients&nbsp;of&nbsp;the&nbsp;Program&nbsp;a&nbsp;copy&nbsp;of&nbsp;this&nbsp;License<br>
308along&nbsp;with&nbsp;the&nbsp;Program.<br>
309<br>
310You&nbsp;may&nbsp;charge&nbsp;a&nbsp;fee&nbsp;for&nbsp;the&nbsp;physical&nbsp;act&nbsp;of&nbsp;transferring&nbsp;a&nbsp;copy,&nbsp;and<br>
311you&nbsp;may&nbsp;at&nbsp;your&nbsp;option&nbsp;offer&nbsp;warranty&nbsp;protection&nbsp;in&nbsp;exchange&nbsp;for&nbsp;a&nbsp;fee.<br>
312<br>
313&nbsp;&nbsp;2.&nbsp;You&nbsp;may&nbsp;modify&nbsp;your&nbsp;copy&nbsp;or&nbsp;copies&nbsp;of&nbsp;the&nbsp;Program&nbsp;or&nbsp;any&nbsp;portion<br>
314of&nbsp;it,&nbsp;thus&nbsp;forming&nbsp;a&nbsp;work&nbsp;based&nbsp;on&nbsp;the&nbsp;Program,&nbsp;and&nbsp;copy&nbsp;and<br>
315distribute&nbsp;such&nbsp;modifications&nbsp;or&nbsp;work&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;Section&nbsp;1<br>
316above,&nbsp;provided&nbsp;that&nbsp;you&nbsp;also&nbsp;meet&nbsp;all&nbsp;of&nbsp;these&nbsp;conditions:<br>
317<br>
318&nbsp;&nbsp;&nbsp;&nbsp;a)&nbsp;You&nbsp;must&nbsp;cause&nbsp;the&nbsp;modified&nbsp;files&nbsp;to&nbsp;carry&nbsp;prominent&nbsp;notices<br>
319&nbsp;&nbsp;&nbsp;&nbsp;stating&nbsp;that&nbsp;you&nbsp;changed&nbsp;the&nbsp;files&nbsp;and&nbsp;the&nbsp;date&nbsp;of&nbsp;any&nbsp;change.<br>
320<br>
321&nbsp;&nbsp;&nbsp;&nbsp;b)&nbsp;You&nbsp;must&nbsp;cause&nbsp;any&nbsp;work&nbsp;that&nbsp;you&nbsp;distribute&nbsp;or&nbsp;publish,&nbsp;that&nbsp;in<br>
322&nbsp;&nbsp;&nbsp;&nbsp;whole&nbsp;or&nbsp;in&nbsp;part&nbsp;contains&nbsp;or&nbsp;is&nbsp;derived&nbsp;from&nbsp;the&nbsp;Program&nbsp;or&nbsp;any<br>
323&nbsp;&nbsp;&nbsp;&nbsp;part&nbsp;thereof,&nbsp;to&nbsp;be&nbsp;licensed&nbsp;as&nbsp;a&nbsp;whole&nbsp;at&nbsp;no&nbsp;charge&nbsp;to&nbsp;all&nbsp;third<br>
324&nbsp;&nbsp;&nbsp;&nbsp;parties&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;this&nbsp;License.<br>
325<br>
326&nbsp;&nbsp;&nbsp;&nbsp;c)&nbsp;If&nbsp;the&nbsp;modified&nbsp;program&nbsp;normally&nbsp;reads&nbsp;commands&nbsp;interactively<br>
327&nbsp;&nbsp;&nbsp;&nbsp;when&nbsp;run,&nbsp;you&nbsp;must&nbsp;cause&nbsp;it,&nbsp;when&nbsp;started&nbsp;running&nbsp;for&nbsp;such<br>
328&nbsp;&nbsp;&nbsp;&nbsp;interactive&nbsp;use&nbsp;in&nbsp;the&nbsp;most&nbsp;ordinary&nbsp;way,&nbsp;to&nbsp;print&nbsp;or&nbsp;display&nbsp;an<br>
329&nbsp;&nbsp;&nbsp;&nbsp;announcement&nbsp;including&nbsp;an&nbsp;appropriate&nbsp;copyright&nbsp;notice&nbsp;and&nbsp;a<br>
330&nbsp;&nbsp;&nbsp;&nbsp;notice&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;warranty&nbsp;(or&nbsp;else,&nbsp;saying&nbsp;that&nbsp;you&nbsp;provide<br>
331&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;warranty)&nbsp;and&nbsp;that&nbsp;users&nbsp;may&nbsp;redistribute&nbsp;the&nbsp;program&nbsp;under<br>
332&nbsp;&nbsp;&nbsp;&nbsp;these&nbsp;conditions,&nbsp;and&nbsp;telling&nbsp;the&nbsp;user&nbsp;how&nbsp;to&nbsp;view&nbsp;a&nbsp;copy&nbsp;of&nbsp;this<br>
333&nbsp;&nbsp;&nbsp;&nbsp;License.&nbsp;&nbsp;(Exception:&nbsp;if&nbsp;the&nbsp;Program&nbsp;itself&nbsp;is&nbsp;interactive&nbsp;but<br>
334&nbsp;&nbsp;&nbsp;&nbsp;does&nbsp;not&nbsp;normally&nbsp;print&nbsp;such&nbsp;an&nbsp;announcement,&nbsp;your&nbsp;work&nbsp;based&nbsp;on<br>
335&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;Program&nbsp;is&nbsp;not&nbsp;required&nbsp;to&nbsp;print&nbsp;an&nbsp;announcement.)<br>
336<br>
337These&nbsp;requirements&nbsp;apply&nbsp;to&nbsp;the&nbsp;modified&nbsp;work&nbsp;as&nbsp;a&nbsp;whole.&nbsp;&nbsp;If<br>
338identifiable&nbsp;sections&nbsp;of&nbsp;that&nbsp;work&nbsp;are&nbsp;not&nbsp;derived&nbsp;from&nbsp;the&nbsp;Program,<br>
339and&nbsp;can&nbsp;be&nbsp;reasonably&nbsp;considered&nbsp;independent&nbsp;and&nbsp;separate&nbsp;works&nbsp;in<br>
340themselves,&nbsp;then&nbsp;this&nbsp;License,&nbsp;and&nbsp;its&nbsp;terms,&nbsp;do&nbsp;not&nbsp;apply&nbsp;to&nbsp;those<br>
341sections&nbsp;when&nbsp;you&nbsp;distribute&nbsp;them&nbsp;as&nbsp;separate&nbsp;works.&nbsp;&nbsp;But&nbsp;when&nbsp;you<br>
342distribute&nbsp;the&nbsp;same&nbsp;sections&nbsp;as&nbsp;part&nbsp;of&nbsp;a&nbsp;whole&nbsp;which&nbsp;is&nbsp;a&nbsp;work&nbsp;based<br>
343on&nbsp;the&nbsp;Program,&nbsp;the&nbsp;distribution&nbsp;of&nbsp;the&nbsp;whole&nbsp;must&nbsp;be&nbsp;on&nbsp;the&nbsp;terms&nbsp;of<br>
344this&nbsp;License,&nbsp;whose&nbsp;permissions&nbsp;for&nbsp;other&nbsp;licensees&nbsp;extend&nbsp;to&nbsp;the<br>
345entire&nbsp;whole,&nbsp;and&nbsp;thus&nbsp;to&nbsp;each&nbsp;and&nbsp;every&nbsp;part&nbsp;regardless&nbsp;of&nbsp;who&nbsp;wrote&nbsp;it.<br>
346<br>
347Thus,&nbsp;it&nbsp;is&nbsp;not&nbsp;the&nbsp;intent&nbsp;of&nbsp;this&nbsp;section&nbsp;to&nbsp;claim&nbsp;rights&nbsp;or&nbsp;contest<br>
348your&nbsp;rights&nbsp;to&nbsp;work&nbsp;written&nbsp;entirely&nbsp;by&nbsp;you;&nbsp;rather,&nbsp;the&nbsp;intent&nbsp;is&nbsp;to<br>
349exercise&nbsp;the&nbsp;right&nbsp;to&nbsp;control&nbsp;the&nbsp;distribution&nbsp;of&nbsp;derivative&nbsp;or<br>
350collective&nbsp;works&nbsp;based&nbsp;on&nbsp;the&nbsp;Program.<br>
351<br>
352In&nbsp;addition,&nbsp;mere&nbsp;aggregation&nbsp;of&nbsp;another&nbsp;work&nbsp;not&nbsp;based&nbsp;on&nbsp;the&nbsp;Program<br>
353with&nbsp;the&nbsp;Program&nbsp;(or&nbsp;with&nbsp;a&nbsp;work&nbsp;based&nbsp;on&nbsp;the&nbsp;Program)&nbsp;on&nbsp;a&nbsp;volume&nbsp;of<br>
354a&nbsp;storage&nbsp;or&nbsp;distribution&nbsp;medium&nbsp;does&nbsp;not&nbsp;bring&nbsp;the&nbsp;other&nbsp;work&nbsp;under<br>
355the&nbsp;scope&nbsp;of&nbsp;this&nbsp;License.<br>
356<br>
357&nbsp;&nbsp;3.&nbsp;You&nbsp;may&nbsp;copy&nbsp;and&nbsp;distribute&nbsp;the&nbsp;Program&nbsp;(or&nbsp;a&nbsp;work&nbsp;based&nbsp;on&nbsp;it,<br>
358under&nbsp;Section&nbsp;2)&nbsp;in&nbsp;object&nbsp;code&nbsp;or&nbsp;executable&nbsp;form&nbsp;under&nbsp;the&nbsp;terms&nbsp;of<br>
359Sections&nbsp;1&nbsp;and&nbsp;2&nbsp;above&nbsp;provided&nbsp;that&nbsp;you&nbsp;also&nbsp;do&nbsp;one&nbsp;of&nbsp;the&nbsp;following:<br>
360<br>
361&nbsp;&nbsp;&nbsp;&nbsp;a)&nbsp;Accompany&nbsp;it&nbsp;with&nbsp;the&nbsp;complete&nbsp;corresponding&nbsp;machine-readable<br>
362&nbsp;&nbsp;&nbsp;&nbsp;source&nbsp;code,&nbsp;which&nbsp;must&nbsp;be&nbsp;distributed&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;Sections<br>
363&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;and&nbsp;2&nbsp;above&nbsp;on&nbsp;a&nbsp;medium&nbsp;customarily&nbsp;used&nbsp;for&nbsp;software&nbsp;interchange;&nbsp;or,<br>
364<br>
365&nbsp;&nbsp;&nbsp;&nbsp;b)&nbsp;Accompany&nbsp;it&nbsp;with&nbsp;a&nbsp;written&nbsp;offer,&nbsp;valid&nbsp;for&nbsp;at&nbsp;least&nbsp;three<br>
366&nbsp;&nbsp;&nbsp;&nbsp;years,&nbsp;to&nbsp;give&nbsp;any&nbsp;third&nbsp;party,&nbsp;for&nbsp;a&nbsp;charge&nbsp;no&nbsp;more&nbsp;than&nbsp;your<br>
367&nbsp;&nbsp;&nbsp;&nbsp;cost&nbsp;of&nbsp;physically&nbsp;performing&nbsp;source&nbsp;distribution,&nbsp;a&nbsp;complete<br>
368&nbsp;&nbsp;&nbsp;&nbsp;machine-readable&nbsp;copy&nbsp;of&nbsp;the&nbsp;corresponding&nbsp;source&nbsp;code,&nbsp;to&nbsp;be<br>
369&nbsp;&nbsp;&nbsp;&nbsp;distributed&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;Sections&nbsp;1&nbsp;and&nbsp;2&nbsp;above&nbsp;on&nbsp;a&nbsp;medium<br>
370&nbsp;&nbsp;&nbsp;&nbsp;customarily&nbsp;used&nbsp;for&nbsp;software&nbsp;interchange;&nbsp;or,<br>
371<br>
372&nbsp;&nbsp;&nbsp;&nbsp;c)&nbsp;Accompany&nbsp;it&nbsp;with&nbsp;the&nbsp;information&nbsp;you&nbsp;received&nbsp;as&nbsp;to&nbsp;the&nbsp;offer<br>
373&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;distribute&nbsp;corresponding&nbsp;source&nbsp;code.&nbsp;&nbsp;(This&nbsp;alternative&nbsp;is<br>
374&nbsp;&nbsp;&nbsp;&nbsp;allowed&nbsp;only&nbsp;for&nbsp;noncommercial&nbsp;distribution&nbsp;and&nbsp;only&nbsp;if&nbsp;you<br>
375&nbsp;&nbsp;&nbsp;&nbsp;received&nbsp;the&nbsp;program&nbsp;in&nbsp;object&nbsp;code&nbsp;or&nbsp;executable&nbsp;form&nbsp;with&nbsp;such<br>
376&nbsp;&nbsp;&nbsp;&nbsp;an&nbsp;offer,&nbsp;in&nbsp;accord&nbsp;with&nbsp;Subsection&nbsp;b&nbsp;above.)<br>
377<br>
378The&nbsp;source&nbsp;code&nbsp;for&nbsp;a&nbsp;work&nbsp;means&nbsp;the&nbsp;preferred&nbsp;form&nbsp;of&nbsp;the&nbsp;work&nbsp;for<br>
379making&nbsp;modifications&nbsp;to&nbsp;it.&nbsp;&nbsp;For&nbsp;an&nbsp;executable&nbsp;work,&nbsp;complete&nbsp;source<br>
380code&nbsp;means&nbsp;all&nbsp;the&nbsp;source&nbsp;code&nbsp;for&nbsp;all&nbsp;modules&nbsp;it&nbsp;contains,&nbsp;plus&nbsp;any<br>
381associated&nbsp;interface&nbsp;definition&nbsp;files,&nbsp;plus&nbsp;the&nbsp;scripts&nbsp;used&nbsp;to<br>
382control&nbsp;compilation&nbsp;and&nbsp;installation&nbsp;of&nbsp;the&nbsp;executable.&nbsp;&nbsp;However,&nbsp;as&nbsp;a<br>
383special&nbsp;exception,&nbsp;the&nbsp;source&nbsp;code&nbsp;distributed&nbsp;need&nbsp;not&nbsp;include<br>
384anything&nbsp;that&nbsp;is&nbsp;normally&nbsp;distributed&nbsp;(in&nbsp;either&nbsp;source&nbsp;or&nbsp;binary<br>
385form)&nbsp;with&nbsp;the&nbsp;major&nbsp;components&nbsp;(compiler,&nbsp;kernel,&nbsp;and&nbsp;so&nbsp;on)&nbsp;of&nbsp;the<br>
386operating&nbsp;system&nbsp;on&nbsp;which&nbsp;the&nbsp;executable&nbsp;runs,&nbsp;unless&nbsp;that&nbsp;component<br>
387itself&nbsp;accompanies&nbsp;the&nbsp;executable.<br>
388<br>
389If&nbsp;distribution&nbsp;of&nbsp;executable&nbsp;or&nbsp;object&nbsp;code&nbsp;is&nbsp;made&nbsp;by&nbsp;offering<br>
390access&nbsp;to&nbsp;copy&nbsp;from&nbsp;a&nbsp;designated&nbsp;place,&nbsp;then&nbsp;offering&nbsp;equivalent<br>
391access&nbsp;to&nbsp;copy&nbsp;the&nbsp;source&nbsp;code&nbsp;from&nbsp;the&nbsp;same&nbsp;place&nbsp;counts&nbsp;as<br>
392distribution&nbsp;of&nbsp;the&nbsp;source&nbsp;code,&nbsp;even&nbsp;though&nbsp;third&nbsp;parties&nbsp;are&nbsp;not<br>
393compelled&nbsp;to&nbsp;copy&nbsp;the&nbsp;source&nbsp;along&nbsp;with&nbsp;the&nbsp;object&nbsp;code.<br>
394<br>
395&nbsp;&nbsp;4.&nbsp;You&nbsp;may&nbsp;not&nbsp;copy,&nbsp;modify,&nbsp;sublicense,&nbsp;or&nbsp;distribute&nbsp;the&nbsp;Program<br>
396except&nbsp;as&nbsp;expressly&nbsp;provided&nbsp;under&nbsp;this&nbsp;License.&nbsp;&nbsp;Any&nbsp;attempt<br>
397otherwise&nbsp;to&nbsp;copy,&nbsp;modify,&nbsp;sublicense&nbsp;or&nbsp;distribute&nbsp;the&nbsp;Program&nbsp;is<br>
398void,&nbsp;and&nbsp;will&nbsp;automatically&nbsp;terminate&nbsp;your&nbsp;rights&nbsp;under&nbsp;this&nbsp;License.<br>
399However,&nbsp;parties&nbsp;who&nbsp;have&nbsp;received&nbsp;copies,&nbsp;or&nbsp;rights,&nbsp;from&nbsp;you&nbsp;under<br>
400this&nbsp;License&nbsp;will&nbsp;not&nbsp;have&nbsp;their&nbsp;licenses&nbsp;terminated&nbsp;so&nbsp;long&nbsp;as&nbsp;such<br>
401parties&nbsp;remain&nbsp;in&nbsp;full&nbsp;compliance.<br>
402<br>
403&nbsp;&nbsp;5.&nbsp;You&nbsp;are&nbsp;not&nbsp;required&nbsp;to&nbsp;accept&nbsp;this&nbsp;License,&nbsp;since&nbsp;you&nbsp;have&nbsp;not<br>
404signed&nbsp;it.&nbsp;&nbsp;However,&nbsp;nothing&nbsp;else&nbsp;grants&nbsp;you&nbsp;permission&nbsp;to&nbsp;modify&nbsp;or<br>
405distribute&nbsp;the&nbsp;Program&nbsp;or&nbsp;its&nbsp;derivative&nbsp;works.&nbsp;&nbsp;These&nbsp;actions&nbsp;are<br>
406prohibited&nbsp;by&nbsp;law&nbsp;if&nbsp;you&nbsp;do&nbsp;not&nbsp;accept&nbsp;this&nbsp;License.&nbsp;&nbsp;Therefore,&nbsp;by<br>
407modifying&nbsp;or&nbsp;distributing&nbsp;the&nbsp;Program&nbsp;(or&nbsp;any&nbsp;work&nbsp;based&nbsp;on&nbsp;the<br>
408Program),&nbsp;you&nbsp;indicate&nbsp;your&nbsp;acceptance&nbsp;of&nbsp;this&nbsp;License&nbsp;to&nbsp;do&nbsp;so,&nbsp;and<br>
409all&nbsp;its&nbsp;terms&nbsp;and&nbsp;conditions&nbsp;for&nbsp;copying,&nbsp;distributing&nbsp;or&nbsp;modifying<br>
410the&nbsp;Program&nbsp;or&nbsp;works&nbsp;based&nbsp;on&nbsp;it.<br>
411<br>
412&nbsp;&nbsp;6.&nbsp;Each&nbsp;time&nbsp;you&nbsp;redistribute&nbsp;the&nbsp;Program&nbsp;(or&nbsp;any&nbsp;work&nbsp;based&nbsp;on&nbsp;the<br>
413Program),&nbsp;the&nbsp;recipient&nbsp;automatically&nbsp;receives&nbsp;a&nbsp;license&nbsp;from&nbsp;the<br>
414original&nbsp;licensor&nbsp;to&nbsp;copy,&nbsp;distribute&nbsp;or&nbsp;modify&nbsp;the&nbsp;Program&nbsp;subject&nbsp;to<br>
415these&nbsp;terms&nbsp;and&nbsp;conditions.&nbsp;&nbsp;You&nbsp;may&nbsp;not&nbsp;impose&nbsp;any&nbsp;further<br>
416restrictions&nbsp;on&nbsp;the&nbsp;recipients'&nbsp;exercise&nbsp;of&nbsp;the&nbsp;rights&nbsp;granted&nbsp;herein.<br>
417You&nbsp;are&nbsp;not&nbsp;responsible&nbsp;for&nbsp;enforcing&nbsp;compliance&nbsp;by&nbsp;third&nbsp;parties&nbsp;to<br>
418this&nbsp;License.<br>
419<br>
420&nbsp;&nbsp;7.&nbsp;If,&nbsp;as&nbsp;a&nbsp;consequence&nbsp;of&nbsp;a&nbsp;court&nbsp;judgment&nbsp;or&nbsp;allegation&nbsp;of&nbsp;patent<br>
421infringement&nbsp;or&nbsp;for&nbsp;any&nbsp;other&nbsp;reason&nbsp;(not&nbsp;limited&nbsp;to&nbsp;patent&nbsp;issues),<br>
422conditions&nbsp;are&nbsp;imposed&nbsp;on&nbsp;you&nbsp;(whether&nbsp;by&nbsp;court&nbsp;order,&nbsp;agreement&nbsp;or<br>
423otherwise)&nbsp;that&nbsp;contradict&nbsp;the&nbsp;conditions&nbsp;of&nbsp;this&nbsp;License,&nbsp;they&nbsp;do&nbsp;not<br>
424excuse&nbsp;you&nbsp;from&nbsp;the&nbsp;conditions&nbsp;of&nbsp;this&nbsp;License.&nbsp;&nbsp;If&nbsp;you&nbsp;cannot<br>
425distribute&nbsp;so&nbsp;as&nbsp;to&nbsp;satisfy&nbsp;simultaneously&nbsp;your&nbsp;obligations&nbsp;under&nbsp;this<br>
426License&nbsp;and&nbsp;any&nbsp;other&nbsp;pertinent&nbsp;obligations,&nbsp;then&nbsp;as&nbsp;a&nbsp;consequence&nbsp;you<br>
427may&nbsp;not&nbsp;distribute&nbsp;the&nbsp;Program&nbsp;at&nbsp;all.&nbsp;&nbsp;For&nbsp;example,&nbsp;if&nbsp;a&nbsp;patent<br>
428license&nbsp;would&nbsp;not&nbsp;permit&nbsp;royalty-free&nbsp;redistribution&nbsp;of&nbsp;the&nbsp;Program&nbsp;by<br>
429all&nbsp;those&nbsp;who&nbsp;receive&nbsp;copies&nbsp;directly&nbsp;or&nbsp;indirectly&nbsp;through&nbsp;you,&nbsp;then<br>
430the&nbsp;only&nbsp;way&nbsp;you&nbsp;could&nbsp;satisfy&nbsp;both&nbsp;it&nbsp;and&nbsp;this&nbsp;License&nbsp;would&nbsp;be&nbsp;to<br>
431refrain&nbsp;entirely&nbsp;from&nbsp;distribution&nbsp;of&nbsp;the&nbsp;Program.<br>
432<br>
433If&nbsp;any&nbsp;portion&nbsp;of&nbsp;this&nbsp;section&nbsp;is&nbsp;held&nbsp;invalid&nbsp;or&nbsp;unenforceable&nbsp;under<br>
434any&nbsp;particular&nbsp;circumstance,&nbsp;the&nbsp;balance&nbsp;of&nbsp;the&nbsp;section&nbsp;is&nbsp;intended&nbsp;to<br>
435apply&nbsp;and&nbsp;the&nbsp;section&nbsp;as&nbsp;a&nbsp;whole&nbsp;is&nbsp;intended&nbsp;to&nbsp;apply&nbsp;in&nbsp;other<br>
436circumstances.<br>
437<br>
438It&nbsp;is&nbsp;not&nbsp;the&nbsp;purpose&nbsp;of&nbsp;this&nbsp;section&nbsp;to&nbsp;induce&nbsp;you&nbsp;to&nbsp;infringe&nbsp;any<br>
439patents&nbsp;or&nbsp;other&nbsp;property&nbsp;right&nbsp;claims&nbsp;or&nbsp;to&nbsp;contest&nbsp;validity&nbsp;of&nbsp;any<br>
440such&nbsp;claims;&nbsp;this&nbsp;section&nbsp;has&nbsp;the&nbsp;sole&nbsp;purpose&nbsp;of&nbsp;protecting&nbsp;the<br>
441integrity&nbsp;of&nbsp;the&nbsp;free&nbsp;software&nbsp;distribution&nbsp;system,&nbsp;which&nbsp;is<br>
442implemented&nbsp;by&nbsp;public&nbsp;license&nbsp;practices.&nbsp;&nbsp;Many&nbsp;people&nbsp;have&nbsp;made<br>
443generous&nbsp;contributions&nbsp;to&nbsp;the&nbsp;wide&nbsp;range&nbsp;of&nbsp;software&nbsp;distributed<br>
444through&nbsp;that&nbsp;system&nbsp;in&nbsp;reliance&nbsp;on&nbsp;consistent&nbsp;application&nbsp;of&nbsp;that<br>
445system;&nbsp;it&nbsp;is&nbsp;up&nbsp;to&nbsp;the&nbsp;author/donor&nbsp;to&nbsp;decide&nbsp;if&nbsp;he&nbsp;or&nbsp;she&nbsp;is&nbsp;willing<br>
446to&nbsp;distribute&nbsp;software&nbsp;through&nbsp;any&nbsp;other&nbsp;system&nbsp;and&nbsp;a&nbsp;licensee&nbsp;cannot<br>
447impose&nbsp;that&nbsp;choice.<br>
448<br>
449This&nbsp;section&nbsp;is&nbsp;intended&nbsp;to&nbsp;make&nbsp;thoroughly&nbsp;clear&nbsp;what&nbsp;is&nbsp;believed&nbsp;to<br>
450be&nbsp;a&nbsp;consequence&nbsp;of&nbsp;the&nbsp;rest&nbsp;of&nbsp;this&nbsp;License.<br>
451<br>
452&nbsp;&nbsp;8.&nbsp;If&nbsp;the&nbsp;distribution&nbsp;and/or&nbsp;use&nbsp;of&nbsp;the&nbsp;Program&nbsp;is&nbsp;restricted&nbsp;in<br>
453certain&nbsp;countries&nbsp;either&nbsp;by&nbsp;patents&nbsp;or&nbsp;by&nbsp;copyrighted&nbsp;interfaces,&nbsp;the<br>
454original&nbsp;copyright&nbsp;holder&nbsp;who&nbsp;places&nbsp;the&nbsp;Program&nbsp;under&nbsp;this&nbsp;License<br>
455may&nbsp;add&nbsp;an&nbsp;explicit&nbsp;geographical&nbsp;distribution&nbsp;limitation&nbsp;excluding<br>
456those&nbsp;countries,&nbsp;so&nbsp;that&nbsp;distribution&nbsp;is&nbsp;permitted&nbsp;only&nbsp;in&nbsp;or&nbsp;among<br>
457countries&nbsp;not&nbsp;thus&nbsp;excluded.&nbsp;&nbsp;In&nbsp;such&nbsp;case,&nbsp;this&nbsp;License&nbsp;incorporates<br>
458the&nbsp;limitation&nbsp;as&nbsp;if&nbsp;written&nbsp;in&nbsp;the&nbsp;body&nbsp;of&nbsp;this&nbsp;License.<br>
459<br>
460&nbsp;&nbsp;9.&nbsp;The&nbsp;Free&nbsp;Software&nbsp;Foundation&nbsp;may&nbsp;publish&nbsp;revised&nbsp;and/or&nbsp;new&nbsp;versions<br>
461of&nbsp;the&nbsp;General&nbsp;Public&nbsp;License&nbsp;from&nbsp;time&nbsp;to&nbsp;time.&nbsp;&nbsp;Such&nbsp;new&nbsp;versions&nbsp;will<br>
462be&nbsp;similar&nbsp;in&nbsp;spirit&nbsp;to&nbsp;the&nbsp;present&nbsp;version,&nbsp;but&nbsp;may&nbsp;differ&nbsp;in&nbsp;detail&nbsp;to<br>
463address&nbsp;new&nbsp;problems&nbsp;or&nbsp;concerns.<br>
464<br>
465Each&nbsp;version&nbsp;is&nbsp;given&nbsp;a&nbsp;distinguishing&nbsp;version&nbsp;number.&nbsp;&nbsp;If&nbsp;the&nbsp;Program<br>
466specifies&nbsp;a&nbsp;version&nbsp;number&nbsp;of&nbsp;this&nbsp;License&nbsp;which&nbsp;applies&nbsp;to&nbsp;it&nbsp;and&nbsp;&quot;any<br>
467later&nbsp;version&quot;,&nbsp;you&nbsp;have&nbsp;the&nbsp;option&nbsp;of&nbsp;following&nbsp;the&nbsp;terms&nbsp;and&nbsp;conditions<br>
468either&nbsp;of&nbsp;that&nbsp;version&nbsp;or&nbsp;of&nbsp;any&nbsp;later&nbsp;version&nbsp;published&nbsp;by&nbsp;the&nbsp;Free<br>
469Software&nbsp;Foundation.&nbsp;&nbsp;If&nbsp;the&nbsp;Program&nbsp;does&nbsp;not&nbsp;specify&nbsp;a&nbsp;version&nbsp;number&nbsp;of<br>
470this&nbsp;License,&nbsp;you&nbsp;may&nbsp;choose&nbsp;any&nbsp;version&nbsp;ever&nbsp;published&nbsp;by&nbsp;the&nbsp;Free&nbsp;Software<br>
471Foundation.<br>
472<br>
473&nbsp;&nbsp;10.&nbsp;If&nbsp;you&nbsp;wish&nbsp;to&nbsp;incorporate&nbsp;parts&nbsp;of&nbsp;the&nbsp;Program&nbsp;into&nbsp;other&nbsp;free<br>
474programs&nbsp;whose&nbsp;distribution&nbsp;conditions&nbsp;are&nbsp;different,&nbsp;write&nbsp;to&nbsp;the&nbsp;author<br>
475to&nbsp;ask&nbsp;for&nbsp;permission.&nbsp;&nbsp;For&nbsp;software&nbsp;which&nbsp;is&nbsp;copyrighted&nbsp;by&nbsp;the&nbsp;Free<br>
476Software&nbsp;Foundation,&nbsp;write&nbsp;to&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation;&nbsp;we&nbsp;sometimes<br>
477make&nbsp;exceptions&nbsp;for&nbsp;this.&nbsp;&nbsp;Our&nbsp;decision&nbsp;will&nbsp;be&nbsp;guided&nbsp;by&nbsp;the&nbsp;two&nbsp;goals<br>
478of&nbsp;preserving&nbsp;the&nbsp;free&nbsp;status&nbsp;of&nbsp;all&nbsp;derivatives&nbsp;of&nbsp;our&nbsp;free&nbsp;software&nbsp;and<br>
479of&nbsp;promoting&nbsp;the&nbsp;sharing&nbsp;and&nbsp;reuse&nbsp;of&nbsp;software&nbsp;generally.<br>
480<br>
481&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NO&nbsp;WARRANTY<br>
482<br>
483&nbsp;&nbsp;11.&nbsp;BECAUSE&nbsp;THE&nbsp;PROGRAM&nbsp;IS&nbsp;LICENSED&nbsp;FREE&nbsp;OF&nbsp;CHARGE,&nbsp;THERE&nbsp;IS&nbsp;NO&nbsp;WARRANTY<br>
484FOR&nbsp;THE&nbsp;PROGRAM,&nbsp;TO&nbsp;THE&nbsp;EXTENT&nbsp;PERMITTED&nbsp;BY&nbsp;APPLICABLE&nbsp;LAW.&nbsp;&nbsp;EXCEPT&nbsp;WHEN<br>
485OTHERWISE&nbsp;STATED&nbsp;IN&nbsp;WRITING&nbsp;THE&nbsp;COPYRIGHT&nbsp;HOLDERS&nbsp;AND/OR&nbsp;OTHER&nbsp;PARTIES<br>
486PROVIDE&nbsp;THE&nbsp;PROGRAM&nbsp;&quot;AS&nbsp;IS&quot;&nbsp;WITHOUT&nbsp;WARRANTY&nbsp;OF&nbsp;ANY&nbsp;KIND,&nbsp;EITHER&nbsp;EXPRESSED<br>
487OR&nbsp;IMPLIED,&nbsp;INCLUDING,&nbsp;BUT&nbsp;NOT&nbsp;LIMITED&nbsp;TO,&nbsp;THE&nbsp;IMPLIED&nbsp;WARRANTIES&nbsp;OF<br>
488MERCHANTABILITY&nbsp;AND&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;THE&nbsp;ENTIRE&nbsp;RISK&nbsp;AS<br>
489TO&nbsp;THE&nbsp;QUALITY&nbsp;AND&nbsp;PERFORMANCE&nbsp;OF&nbsp;THE&nbsp;PROGRAM&nbsp;IS&nbsp;WITH&nbsp;YOU.&nbsp;&nbsp;SHOULD&nbsp;THE<br>
490PROGRAM&nbsp;PROVE&nbsp;DEFECTIVE,&nbsp;YOU&nbsp;ASSUME&nbsp;THE&nbsp;COST&nbsp;OF&nbsp;ALL&nbsp;NECESSARY&nbsp;SERVICING,<br>
491REPAIR&nbsp;OR&nbsp;CORRECTION.<br>
492<br>
493&nbsp;&nbsp;12.&nbsp;IN&nbsp;NO&nbsp;EVENT&nbsp;UNLESS&nbsp;REQUIRED&nbsp;BY&nbsp;APPLICABLE&nbsp;LAW&nbsp;OR&nbsp;AGREED&nbsp;TO&nbsp;IN&nbsp;WRITING<br>
494WILL&nbsp;ANY&nbsp;COPYRIGHT&nbsp;HOLDER,&nbsp;OR&nbsp;ANY&nbsp;OTHER&nbsp;PARTY&nbsp;WHO&nbsp;MAY&nbsp;MODIFY&nbsp;AND/OR<br>
495REDISTRIBUTE&nbsp;THE&nbsp;PROGRAM&nbsp;AS&nbsp;PERMITTED&nbsp;ABOVE,&nbsp;BE&nbsp;LIABLE&nbsp;TO&nbsp;YOU&nbsp;FOR&nbsp;DAMAGES,<br>
496INCLUDING&nbsp;ANY&nbsp;GENERAL,&nbsp;SPECIAL,&nbsp;INCIDENTAL&nbsp;OR&nbsp;CONSEQUENTIAL&nbsp;DAMAGES&nbsp;ARISING<br>
497OUT&nbsp;OF&nbsp;THE&nbsp;USE&nbsp;OR&nbsp;INABILITY&nbsp;TO&nbsp;USE&nbsp;THE&nbsp;PROGRAM&nbsp;(INCLUDING&nbsp;BUT&nbsp;NOT&nbsp;LIMITED<br>
498TO&nbsp;LOSS&nbsp;OF&nbsp;DATA&nbsp;OR&nbsp;DATA&nbsp;BEING&nbsp;RENDERED&nbsp;INACCURATE&nbsp;OR&nbsp;LOSSES&nbsp;SUSTAINED&nbsp;BY<br>
499YOU&nbsp;OR&nbsp;THIRD&nbsp;PARTIES&nbsp;OR&nbsp;A&nbsp;FAILURE&nbsp;OF&nbsp;THE&nbsp;PROGRAM&nbsp;TO&nbsp;OPERATE&nbsp;WITH&nbsp;ANY&nbsp;OTHER<br>
500PROGRAMS),&nbsp;EVEN&nbsp;IF&nbsp;SUCH&nbsp;HOLDER&nbsp;OR&nbsp;OTHER&nbsp;PARTY&nbsp;HAS&nbsp;BEEN&nbsp;ADVISED&nbsp;OF&nbsp;THE<br>
501POSSIBILITY&nbsp;OF&nbsp;SUCH&nbsp;DAMAGES.<br>
502<br>
503&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END&nbsp;OF&nbsp;TERMS&nbsp;AND&nbsp;CONDITIONS<br>
504<br>
505&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;How&nbsp;to&nbsp;Apply&nbsp;These&nbsp;Terms&nbsp;to&nbsp;Your&nbsp;New&nbsp;Programs<br>
506<br>
507&nbsp;&nbsp;If&nbsp;you&nbsp;develop&nbsp;a&nbsp;new&nbsp;program,&nbsp;and&nbsp;you&nbsp;want&nbsp;it&nbsp;to&nbsp;be&nbsp;of&nbsp;the&nbsp;greatest<br>
508possible&nbsp;use&nbsp;to&nbsp;the&nbsp;public,&nbsp;the&nbsp;best&nbsp;way&nbsp;to&nbsp;achieve&nbsp;this&nbsp;is&nbsp;to&nbsp;make&nbsp;it<br>
509free&nbsp;software&nbsp;which&nbsp;everyone&nbsp;can&nbsp;redistribute&nbsp;and&nbsp;change&nbsp;under&nbsp;these&nbsp;terms.<br>
510<br>
511&nbsp;&nbsp;To&nbsp;do&nbsp;so,&nbsp;attach&nbsp;the&nbsp;following&nbsp;notices&nbsp;to&nbsp;the&nbsp;program.&nbsp;&nbsp;It&nbsp;is&nbsp;safest<br>
512to&nbsp;attach&nbsp;them&nbsp;to&nbsp;the&nbsp;start&nbsp;of&nbsp;each&nbsp;source&nbsp;file&nbsp;to&nbsp;most&nbsp;effectively<br>
513convey&nbsp;the&nbsp;exclusion&nbsp;of&nbsp;warranty;&nbsp;and&nbsp;each&nbsp;file&nbsp;should&nbsp;have&nbsp;at&nbsp;least<br>
514the&nbsp;&quot;copyright&quot;&nbsp;line&nbsp;and&nbsp;a&nbsp;pointer&nbsp;to&nbsp;where&nbsp;the&nbsp;full&nbsp;notice&nbsp;is&nbsp;found.<br>
515<br>
516&nbsp;&nbsp;&nbsp;&nbsp;&lt;one&nbsp;line&nbsp;to&nbsp;give&nbsp;the&nbsp;program's&nbsp;name&nbsp;and&nbsp;a&nbsp;brief&nbsp;idea&nbsp;of&nbsp;what&nbsp;it&nbsp;does.&gt;<br>
517&nbsp;&nbsp;&nbsp;&nbsp;Copyright&nbsp;(C)&nbsp;&lt;year&gt;&nbsp;&nbsp;&lt;name&nbsp;of&nbsp;author&gt;<br>
518<br>
519&nbsp;&nbsp;&nbsp;&nbsp;This&nbsp;program&nbsp;is&nbsp;free&nbsp;software;&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify<br>
520&nbsp;&nbsp;&nbsp;&nbsp;it&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published&nbsp;by<br>
521&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation;&nbsp;either&nbsp;version&nbsp;2&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
522&nbsp;&nbsp;&nbsp;&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
523<br>
524&nbsp;&nbsp;&nbsp;&nbsp;This&nbsp;program&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
525&nbsp;&nbsp;&nbsp;&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
526&nbsp;&nbsp;&nbsp;&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
527&nbsp;&nbsp;&nbsp;&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
528<br>
529&nbsp;&nbsp;&nbsp;&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;along<br>
530&nbsp;&nbsp;&nbsp;&nbsp;with&nbsp;this&nbsp;program;&nbsp;if&nbsp;not,&nbsp;write&nbsp;to&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;Inc.,<br>
531&nbsp;&nbsp;&nbsp;&nbsp;51&nbsp;Franklin&nbsp;Street,&nbsp;Fifth&nbsp;Floor,&nbsp;Boston,&nbsp;MA&nbsp;02110-1301&nbsp;USA.<br>
532<br>
533Also&nbsp;add&nbsp;information&nbsp;on&nbsp;how&nbsp;to&nbsp;contact&nbsp;you&nbsp;by&nbsp;electronic&nbsp;and&nbsp;paper&nbsp;mail.<br>
534<br>
535If&nbsp;the&nbsp;program&nbsp;is&nbsp;interactive,&nbsp;make&nbsp;it&nbsp;output&nbsp;a&nbsp;short&nbsp;notice&nbsp;like&nbsp;this<br>
536when&nbsp;it&nbsp;starts&nbsp;in&nbsp;an&nbsp;interactive&nbsp;mode:<br>
537<br>
538&nbsp;&nbsp;&nbsp;&nbsp;Gnomovision&nbsp;version&nbsp;69,&nbsp;Copyright&nbsp;(C)&nbsp;year&nbsp;name&nbsp;of&nbsp;author<br>
539&nbsp;&nbsp;&nbsp;&nbsp;Gnomovision&nbsp;comes&nbsp;with&nbsp;ABSOLUTELY&nbsp;NO&nbsp;WARRANTY;&nbsp;for&nbsp;details&nbsp;type&nbsp;`show&nbsp;w'.<br>
540&nbsp;&nbsp;&nbsp;&nbsp;This&nbsp;is&nbsp;free&nbsp;software,&nbsp;and&nbsp;you&nbsp;are&nbsp;welcome&nbsp;to&nbsp;redistribute&nbsp;it<br>
541&nbsp;&nbsp;&nbsp;&nbsp;under&nbsp;certain&nbsp;conditions;&nbsp;type&nbsp;`show&nbsp;c'&nbsp;for&nbsp;details.<br>
542<br>
543The&nbsp;hypothetical&nbsp;commands&nbsp;`show&nbsp;w'&nbsp;and&nbsp;`show&nbsp;c'&nbsp;should&nbsp;show&nbsp;the&nbsp;appropriate<br>
544parts&nbsp;of&nbsp;the&nbsp;General&nbsp;Public&nbsp;License.&nbsp;&nbsp;Of&nbsp;course,&nbsp;the&nbsp;commands&nbsp;you&nbsp;use&nbsp;may<br>
545be&nbsp;called&nbsp;something&nbsp;other&nbsp;than&nbsp;`show&nbsp;w'&nbsp;and&nbsp;`show&nbsp;c';&nbsp;they&nbsp;could&nbsp;even&nbsp;be<br>
546mouse-clicks&nbsp;or&nbsp;menu&nbsp;items--whatever&nbsp;suits&nbsp;your&nbsp;program.<br>
547<br>
548You&nbsp;should&nbsp;also&nbsp;get&nbsp;your&nbsp;employer&nbsp;(if&nbsp;you&nbsp;work&nbsp;as&nbsp;a&nbsp;programmer)&nbsp;or&nbsp;your<br>
549school,&nbsp;if&nbsp;any,&nbsp;to&nbsp;sign&nbsp;a&nbsp;&quot;copyright&nbsp;disclaimer&quot;&nbsp;for&nbsp;the&nbsp;program,&nbsp;if<br>
550necessary.&nbsp;&nbsp;Here&nbsp;is&nbsp;a&nbsp;sample;&nbsp;alter&nbsp;the&nbsp;names:<br>
551<br>
552&nbsp;&nbsp;Yoyodyne,&nbsp;Inc.,&nbsp;hereby&nbsp;disclaims&nbsp;all&nbsp;copyright&nbsp;interest&nbsp;in&nbsp;the&nbsp;program<br>
553&nbsp;&nbsp;`Gnomovision'&nbsp;(which&nbsp;makes&nbsp;passes&nbsp;at&nbsp;compilers)&nbsp;written&nbsp;by&nbsp;James&nbsp;Hacker.<br>
554<br>
555&nbsp;&nbsp;&lt;signature&nbsp;of&nbsp;Ty&nbsp;Coon&gt;,&nbsp;1&nbsp;April&nbsp;1989<br>
556&nbsp;&nbsp;Ty&nbsp;Coon,&nbsp;President&nbsp;of&nbsp;Vice<br>
557<br>
558This&nbsp;General&nbsp;Public&nbsp;License&nbsp;does&nbsp;not&nbsp;permit&nbsp;incorporating&nbsp;your&nbsp;program&nbsp;into<br>
559proprietary&nbsp;programs.&nbsp;&nbsp;If&nbsp;your&nbsp;program&nbsp;is&nbsp;a&nbsp;subroutine&nbsp;library,&nbsp;you&nbsp;may<br>
560consider&nbsp;it&nbsp;more&nbsp;useful&nbsp;to&nbsp;permit&nbsp;linking&nbsp;proprietary&nbsp;applications&nbsp;with&nbsp;the<br>
561library.&nbsp;&nbsp;If&nbsp;this&nbsp;is&nbsp;what&nbsp;you&nbsp;want&nbsp;to&nbsp;do,&nbsp;use&nbsp;the&nbsp;GNU&nbsp;Lesser&nbsp;General<br>
562Public&nbsp;License&nbsp;instead&nbsp;of&nbsp;this&nbsp;License.<br>
563</span></code>
564<hr>Input File: omh/license.omh
565
566<hr>
567<center><b><big><big><a name="3" id="3">3: The Nonlinear Constrained Kalman-Bucy Smoother</a>
568</big></big></b></center>
569<br>
570<b><big><a name="3.a" id="3.a">3.a: Syntax</a></big></b>
571
572<br>
573<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>x_out</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>u_out</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_nonlinear(</span></font></code><i><span style='white-space: nowrap'>f_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>g_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>h_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;...<br>
574&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></code><i><span style='white-space: nowrap'>max_itr</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>x_in</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>z</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>qinv</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>rinv</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>level</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
575
576<br>
577<br>
578<b><big><a name="3.b" id="3.b">3.b: Purpose</a></big></b>
579<br>
580This routine minimizes the
581Kalman-Bucy smoother residual sum of squares objective
582for a general nonlinear model functions
583(in the case where the model functions are affine, the routine
584<a href="#4">4: <span style='white-space: nowrap'>ckbs_affine</span></a>
585 is more efficient).
586
587<br>
588<br>
589<b><big><a name="3.c" id="3.c">3.c: Notation</a></big></b>
590<br>
591The Kalman-Bucy smoother residual sum of squares is defined by
592<code>
593<span style='white-space: nowrap'>&nbsp;\[<br>
594\begin{array}{rcl}<br>
595S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;\sum_{k=1}^N&nbsp;S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;\\<br>
596S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
597\frac{1}{2}&nbsp;<br>
598[&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;]^\T&nbsp;*&nbsp;R_k^{-1}&nbsp;*&nbsp;[&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;]<br>
599\\<br>
600&amp;&nbsp;+&nbsp;&amp;<br>
601\frac{1}{2}&nbsp;<br>
602[&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;(&nbsp;x_{k-1}&nbsp;)&nbsp;]^\T&nbsp;*&nbsp;Q_k^{-1}&nbsp;*&nbsp;[&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;(&nbsp;x_{k-1}&nbsp;)&nbsp;]<br>
603\\<br>
604\end{array}<br>
605\]&nbsp;</span></code>
606
607where the matrices <code>
608<span style='white-space: nowrap'>&nbsp;R_k</span></code>
609 and <code>
610<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
611 are
612symmetric positive definite and
613<code>
614<span style='white-space: nowrap'>&nbsp;x_0</span></code>
615 is the constant zero.
616Note that <code>
617<span style='white-space: nowrap'>&nbsp;g_1&nbsp;(&nbsp;x_0&nbsp;)</span></code>
618 is the initial state estimate
619and <code>
620<span style='white-space: nowrap'>&nbsp;Q_1</span></code>
621 is the corresponding covariance.
622
623<br>
624<br>
625<b><big><a name="3.d" id="3.d">3.d: Problem</a></big></b>
626<br>
627Our constrained Kalman-Bucy smoother problem is
628<code>
629<span style='white-space: nowrap'>&nbsp;\[<br>
630\begin{array}{rll}<br>
631{\rm&nbsp;minimize}&nbsp;<br>
632&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;S(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;<br>
633&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;{\rm&nbsp;w.r.t.}&nbsp;\;&nbsp;x_1&nbsp;\in&nbsp;\R^n&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;\in&nbsp;\R^n<br>
634\\<br>
635{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;<br>
636&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;f_k(x_k)&nbsp;\leq&nbsp;0&nbsp;<br>
637&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;{\rm&nbsp;for}&nbsp;\;&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N<br>
638\end{array}<br>
639\]&nbsp;</span></code>
640
641
642<br>
643<br>
644<b><big><a name="3.e" id="3.e">3.e: First Order Conditions</a></big></b>
645<br>
646A state sequence <code>
647<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
648 is considered a solution
649if there is a Lagrange multiplier sequence <code>
650<span style='white-space: nowrap'>&nbsp;(&nbsp;u_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;u_N&nbsp;)</span></code>
651 
652such that the following conditions are satisfied for
653<code>
654<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
655 and <code>
656<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
657:
658<code>
659<span style='white-space: nowrap'>&nbsp;\[<br>
660\begin{array}{rcl}<br>
661f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;\varepsilon&nbsp;&nbsp;\\<br>
6620&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;u_k&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
663|&nbsp;u_k^\T&nbsp;*&nbsp;\partial_k&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;+&nbsp;\partial_k&nbsp;&nbsp;S(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;|<br>
664&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;\varepsilon&nbsp;\\&nbsp;&nbsp;<br>
665|&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)_i&nbsp;|&nbsp;*&nbsp;(&nbsp;u_k&nbsp;)_i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;\varepsilon<br>
666\end{array}<br>
667\]&nbsp;</span></code>
668
669Here the notation
670<code>
671<span style='white-space: nowrap'>&nbsp;\partial_k</span></code>
672 is used for the partial derivative of
673with respect to <code>
674<span style='white-space: nowrap'>&nbsp;x_k</span></code>
675 and the notation
676<code>
677<span style='white-space: nowrap'>&nbsp;(u_k)_i</span></code>
678 denotes the <i>i</i>-th component of <code>
679<span style='white-space: nowrap'>&nbsp;u_k</span></code>
680.
681
682<br>
683<br>
684<b><big><a name="3.f" id="3.f">3.f: f_fun</a></big></b>
685<br>
686The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>f_fun</i> 
687is a function that supports both of the
688following syntaxes
689<code><font color="blue"><span style='white-space: nowrap'><br>
690&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span></font></code><i><span style='white-space: nowrap'>fk</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;feval(</span></font></code><i><span style='white-space: nowrap'>f_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>k</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>xk</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br>
691&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span></font></code><i><span style='white-space: nowrap'>fk</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Fk</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;feval(</span></font></code><i><span style='white-space: nowrap'>f_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>k</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>xk</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br>
692</span></font></code>In the case where there are no constraints,
693one can use the following function for <i>f_fun</i>:
694<code><font color='blue'><pre style='display:inline'> 
695        [fk, Fk] = f_fun(k, xk)
696        n  = size(xk, 1);
697        fk = -1;
698        Fk =  zeros(1, n);
699        return
700        end
701</pre></font></code>
702
703
704<br>
705<br>
706<b><a name="3.f.a" id="3.f.a">3.f.a: k</a></b>
707<br>
708The <i>f_fun</i> argument <i>k</i> is an integer with
709<code>
710<span style='white-space: nowrap'>&nbsp;1&nbsp;\leq&nbsp;k&nbsp;\leq&nbsp;N</span></code>
711.
712
713<br>
714<br>
715<b><a name="3.f.b" id="3.f.b">3.f.b: xk</a></b>
716<br>
717The <i>f_fun</i> argument <i>xk</i> is an column vector with
718length <code>
719<span style='white-space: nowrap'>&nbsp;n</span></code>
720. It specifies the state vector at time index <i>k</i>
721<code>
722<span style='white-space: nowrap'>&nbsp;\[<br>
723&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xk&nbsp;=&nbsp;x_k<br>
724\]&nbsp;</span></code>
725.
726
727<br>
728<br>
729<b><a name="3.f.c" id="3.f.c">3.f.c: fk</a></b>
730<br>
731The <i>f_fun</i> result <i>fk</i> is an column vector with
732length <code>
733<span style='white-space: nowrap'>&nbsp;\ell</span></code>
734 and
735<code>
736<span style='white-space: nowrap'>&nbsp;\[<br>
737&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fk&nbsp;=&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
738\]&nbsp;</span></code>
739
740
741<br>
742<br>
743<b><a name="3.f.d" id="3.f.d">3.f.d: Fk</a></b>
744<br>
745If the <i>f_fun</i> result <i>Fk</i> is present in the syntax,
746it is the <code>
747<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;n</span></code>
748 matrix given by
749and
750<code>
751<span style='white-space: nowrap'>&nbsp;\[<br>
752&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fk&nbsp;=&nbsp;\partial_k&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
753\]&nbsp;</span></code>
754
755
756<br>
757<br>
758<b><big><a name="3.g" id="3.g">3.g: g_fun</a></big></b>
759<br>
760The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>g_fun</i> 
761is a function that supports both of
762the following syntaxes
763<code><font color="blue"><span style='white-space: nowrap'><br>
764&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span></font></code><i><span style='white-space: nowrap'>gk</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;feval(</span></font></code><i><span style='white-space: nowrap'>g_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>k</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>xk1</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br>
765&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span></font></code><i><span style='white-space: nowrap'>gk</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Gk</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;feval(</span></font></code><i><span style='white-space: nowrap'>g_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>k</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>xk1</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br>
766</span></font></code><br>
767<b><a name="3.g.a" id="3.g.a">3.g.a: k</a></b>
768<br>
769The <i>g_fun</i> argument <i>k</i> is an integer with
770<code>
771<span style='white-space: nowrap'>&nbsp;1&nbsp;\leq&nbsp;k&nbsp;\leq&nbsp;N</span></code>
772.
773The case <code>
774<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
775 serves to specify the initial state estimate.
776
777<br>
778<br>
779<b><a name="3.g.b" id="3.g.b">3.g.b: xk1</a></b>
780<br>
781The <i>g_fun</i> argument <i>xk1</i> is an column vector with
782length <code>
783<span style='white-space: nowrap'>&nbsp;n</span></code>
784. It specifies the state vector at time index <i>k</i>
785<code>
786<span style='white-space: nowrap'>&nbsp;\[<br>
787&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xk1&nbsp;=&nbsp;x_{k-1}<br>
788\]&nbsp;</span></code>
789.
790In the case <code>
791<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
792, the value of <i>xk1</i> does not matter.
793
794<br>
795<br>
796<b><a name="3.g.c" id="3.g.c">3.g.c: gk</a></b>
797<br>
798The <i>g_fun</i> result <i>gk</i> is an column vector with
799length <code>
800<span style='white-space: nowrap'>&nbsp;n</span></code>
801 and
802<code>
803<span style='white-space: nowrap'>&nbsp;\[<br>
804&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gk&nbsp;=&nbsp;g_k&nbsp;(&nbsp;x_{k-1}&nbsp;)&nbsp;<br>
805\]&nbsp;</span></code>
806
807In the case <code>
808<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
809, the value of <i>gk</i> is the initial state
810estimate at time index <i>k</i>.
811
812<br>
813<br>
814<b><a name="3.g.d" id="3.g.d">3.g.d: Gk</a></b>
815<br>
816If the <i>g_fun</i> result <i>Gk</i> is present in the syntax,
817it is the <code>
818<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
819 matrix given by
820and
821<code>
822<span style='white-space: nowrap'>&nbsp;\[<br>
823&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gk&nbsp;=&nbsp;\partial_{k-1}&nbsp;g_k&nbsp;(&nbsp;x_{k-1}&nbsp;)&nbsp;<br>
824\]&nbsp;</span></code>
825
826In the case <code>
827<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
828, the value of <i>Gk</i> is the zero matrix;
829i.e., <code>
830<span style='white-space: nowrap'>&nbsp;g_k</span></code>
831 does not depend on the value of <code>
832<span style='white-space: nowrap'>&nbsp;x_{k-1}</span></code>
833.
834
835<br>
836<br>
837<b><big><a name="3.h" id="3.h">3.h: h_fun</a></big></b>
838<br>
839The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>h_fun</i> 
840is a function that supports both of the
841following syntaxes
842<code><font color="blue"><span style='white-space: nowrap'><br>
843&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span></font></code><i><span style='white-space: nowrap'>hk</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;feval(</span></font></code><i><span style='white-space: nowrap'>h_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>k</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>xk</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br>
844&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[</span></font></code><i><span style='white-space: nowrap'>hk</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Hk</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;feval(</span></font></code><i><span style='white-space: nowrap'>h_fun</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>k</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>xk</span></i><code><font color="blue"><span style='white-space: nowrap'>)<br>
845</span></font></code><br>
846<b><a name="3.h.a" id="3.h.a">3.h.a: k</a></b>
847<br>
848The <i>h_fun</i> argument <i>k</i> is an integer with
849<code>
850<span style='white-space: nowrap'>&nbsp;1&nbsp;\leq&nbsp;k&nbsp;\leq&nbsp;N</span></code>
851.
852
853<br>
854<br>
855<b><a name="3.h.b" id="3.h.b">3.h.b: xk</a></b>
856<br>
857The <i>h_fun</i> argument <i>xk</i> is an column vector with
858length <code>
859<span style='white-space: nowrap'>&nbsp;n</span></code>
860. It specifies the state vector at time index <i>k</i>
861<code>
862<span style='white-space: nowrap'>&nbsp;\[<br>
863&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xk&nbsp;=&nbsp;x_k<br>
864\]&nbsp;</span></code>
865.
866
867<br>
868<br>
869<b><a name="3.h.c" id="3.h.c">3.h.c: hk</a></b>
870<br>
871The <i>h_fun</i> result <i>hk</i> is an column vector with
872length <code>
873<span style='white-space: nowrap'>&nbsp;m</span></code>
874 and
875<code>
876<span style='white-space: nowrap'>&nbsp;\[<br>
877&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hk&nbsp;=&nbsp;h_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
878\]&nbsp;</span></code>
879
880
881<br>
882<br>
883<b><a name="3.h.d" id="3.h.d">3.h.d: Hk</a></b>
884<br>
885If the <i>h_fun</i> result <i>Hk</i> is present in the syntax,
886it is the <code>
887<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n</span></code>
888 matrix given by
889and
890<code>
891<span style='white-space: nowrap'>&nbsp;\[<br>
892&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hk&nbsp;=&nbsp;\partial_k&nbsp;h_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
893\]&nbsp;</span></code>
894
895
896<br>
897<br>
898<b><big><a name="3.i" id="3.i">3.i: max_itr</a></big></b>
899<br>
900The integer scalar <i>max_itr</i> specifies the maximum number of
901iterations of the algorithm to execute. It must be greater than or
902equal to zero. Note that if it is zero, the first row of the
903<a href="#3.r">3.r: <span style='white-space: nowrap'>info</span></a>
904 return value will still be computed.
905This can be useful for deciding what is a good value for the argument
906<a href="#3.j">3.j: <span style='white-space: nowrap'>epsilon</span></a>
907.
908
909<br>
910<br>
911<b><big><a name="3.j" id="3.j">3.j: epsilon</a></big></b>
912<br>
913The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>epsilon</i> is a positive scalar.
914It specifies the convergence
915criteria value; i.e.,
916<code>
917<span style='white-space: nowrap'>&nbsp;\[<br>
918&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\varepsilon&nbsp;=&nbsp;epsilon<br>
919\]&nbsp;</span></code>
920
921In some instances, <code><font color="blue">ckbs_nonlinear</font></code> will return after printing
922a warning without convergence; see <a href="#3.r">3.r: <span style='white-space: nowrap'>info</span></a>
923.
924
925<br>
926<br>
927<b><big><a name="3.k" id="3.k">3.k: x_in</a></big></b>
928<br>
929The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>x_in</i> 
930is a two dimensional array with size <code>
931<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
932.
933It specifies a sequence of state values; i.e.,
934for <code>
935<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
936
937<code>
938<span style='white-space: nowrap'>&nbsp;\[<br>
939&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x\_in&nbsp;(:,&nbsp;k)&nbsp;=&nbsp;x_k<br>
940\]&nbsp;</span></code>
941
942The closer the initial state sequence is to the solution
943the faster, and more likely, the <code><font color="blue">ckbs_nonlinear</font></code> will converge.
944The initial state sequence need not be feasible; i.e.
945it is not necessary that
946<code>
947<span style='white-space: nowrap'>&nbsp;\[<br>
948&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;\leq&nbsp;0<br>
949\]&nbsp;</span></code>
950
951for all <code>
952<span style='white-space: nowrap'>&nbsp;k</span></code>
953.
954
955<br>
956<br>
957<b><big><a name="3.l" id="3.l">3.l: z</a></big></b>
958<br>
959The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>z</i> is a two dimensional array
960with size <code>
961<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
962.
963It specifies the sequence of measurement vectors; i.e.,
964for <code>
965<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
966
967<code>
968<span style='white-space: nowrap'>&nbsp;\[<br>
969&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z(:,&nbsp;k)&nbsp;=&nbsp;z_k<br>
970\]</span></code>
971
972
973<br>
974<br>
975<b><big><a name="3.m" id="3.m">3.m: qinv</a></big></b>
976<br>
977The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>qinv</i> 
978is a three dimensional array
979with size <code>
980<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
981.
982It specifies the inverse of the variance of the measurement noise; i.e.,
983for <code>
984<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
985
986<code>
987<span style='white-space: nowrap'>&nbsp;\[<br>
988&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qinv(:,:,&nbsp;k)&nbsp;=&nbsp;Q_k^{-1}<br>
989\]</span></code>
990
991In the case <code>
992<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
993, the value of <code>
994<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
995 is the variance
996of the initial state estimate (see <a href="#3.g">3.g: <span style='white-space: nowrap'>g_fun</span></a>
997.
998
999<br>
1000<br>
1001<b><big><a name="3.n" id="3.n">3.n: rinv</a></big></b>
1002<br>
1003The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>rinv</i> 
1004is a three dimensional array,
1005with size <code>
1006<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
1007.
1008it specifies the inverse of the variance of the transition noise; i.e.,
1009for <code>
1010<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1011
1012<code>
1013<span style='white-space: nowrap'>&nbsp;\[<br>
1014&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rinv(:,:,&nbsp;k)&nbsp;=&nbsp;R_k^{-1}<br>
1015\]</span></code>
1016
1017It is ok to signify a missing data value by setting the corresponding
1018row and column of <i>rinv</i> to zero. This also enables use
1019to interpolate the state vector <code>
1020<span style='white-space: nowrap'>&nbsp;x_k</span></code>
1021 to points where
1022there are no measurements.
1023
1024<br>
1025<br>
1026<b><big><a name="3.o" id="3.o">3.o: level</a></big></b>
1027<br>
1028The integer scalar <i>level</i> specifies the level of tracing to do.
1029If <code><font color="blue"></font></code><i><span style='white-space: nowrap'>level</span></i><code><font color="blue"><span style='white-space: nowrap'>&nbsp;==&nbsp;0</span></font></code>, no tracing is done.
1030If <code><font color="blue"></font></code><i><span style='white-space: nowrap'>level</span></i><code><font color="blue"><span style='white-space: nowrap'>&nbsp;&gt;=&nbsp;1</span></font></code>, the row index <i>q</i>
1031and the correspond row of <i>info</i> 
1032are printed as soon as soon as they are computed.
1033If <code><font color="blue"></font></code><i><span style='white-space: nowrap'>level</span></i><code><font color="blue"><span style='white-space: nowrap'>&nbsp;&gt;=&nbsp;2</span></font></code>, a check of the derivative calculations
1034is printed before the calculations start. In this case, control will
1035return to the keyboard so that you can print values, continue,
1036or abort the calculation.
1037
1038<br>
1039<br>
1040<b><big><a name="3.p" id="3.p">3.p: x_out</a></big></b>
1041<br>
1042The result <i>x_out</i> 
1043is a two dimensional array with size <code>
1044<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
1045.
1046<code>
1047<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
1048.
1049It contains an approximation for the optimal sequence; i.e.,
1050for <code>
1051<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1052
1053<code>
1054<span style='white-space: nowrap'>&nbsp;\[<br>
1055&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x\_out(:,&nbsp;k)&nbsp;=&nbsp;x_k<br>
1056\]</span></code>
1057
1058
1059<br>
1060<br>
1061<b><big><a name="3.q" id="3.q">3.q: u_out</a></big></b>
1062<br>
1063The result <i>u_out</i> 
1064is a two dimensional array with size % <code>
1065<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;N</span></code>
1066.
1067It contains the Lagrange multiplier sequence
1068corresponding to <i>x_out</i>; i.e.,
1069for <code>
1070<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1071
1072<code>
1073<span style='white-space: nowrap'>&nbsp;\[<br>
1074&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u\_out(:,&nbsp;k)&nbsp;=&nbsp;u_k<br>
1075\]</span></code>
1076
1077The pair <i>x_out</i>, <i>u_out</i> satisfy the
1078<a href="#3.e">3.e: <span style='white-space: nowrap'>first&nbsp;order&nbsp;conditions</span></a>
1079.
1080
1081<br>
1082<br>
1083<b><big><a name="3.r" id="3.r">3.r: info</a></big></b>
1084<br>
1085The result <i>info</i> is a matrix with each row corresponding
1086to an iteration of the algorithm.
1087Note that <code><font color="blue">ckbs_nonlinear</font></code> has satisfied the convergence condition if
1088and only if
1089<code><font color="blue"><span style='white-space: nowrap'><br>
1090&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all(&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(end,&nbsp;1:3)&nbsp;&lt;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>&nbsp;)<br>
1091</span></font></code><code><span style='white-space: nowrap'><br>
1092<br>
1093</span></code>We use <code>
1094<span style='white-space: nowrap'>&nbsp;\{&nbsp;x_k^q&nbsp;\}</span></code>
1095 to denote the state vector sequence at the
1096at the end of iteration <code>
1097<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1098 and
1099<code>
1100<span style='white-space: nowrap'>&nbsp;\{&nbsp;u_k^q&nbsp;\}</span></code>
1101 for the dual vector sequence (<code>
1102<span style='white-space: nowrap'>&nbsp;u_k^q&nbsp;\geq&nbsp;0</span></code>
1103).
1104
1105<br>
1106<br>
1107<b><a name="3.r.a" id="3.r.a">3.r.a: max_f</a></b>
1108<br>
1109The value
1110<code><font color="blue"><span style='white-space: nowrap'><br>
1111&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></code><i><span style='white-space: nowrap'>max_f</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>)&nbsp;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;1)<br>
1112</span></font></code>is a bound on the constraint functions
1113at the end of iteration <i>q-1</i>. To be specific
1114<code>
1115<span style='white-space: nowrap'>&nbsp;\[<br>
1116&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max\_f(q)&nbsp;=&nbsp;\max_{i,&nbsp;k}&nbsp;[&nbsp;f_k&nbsp;(&nbsp;x_k^q&nbsp;)_i&nbsp;]<br>
1117\]&nbsp;</span></code>
1118
1119where the maximum is with respect to
1120<code>
1121<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
1122 and
1123<code>
1124<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1125.
1126Convergence requires this value to be less than or equal <i>epsilon</i>.
1127
1128<br>
1129<br>
1130<b><a name="3.r.b" id="3.r.b">3.r.b: max_grad</a></b>
1131<br>
1132The value
1133<code><font color="blue"><span style='white-space: nowrap'><br>
1134&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></code><i><span style='white-space: nowrap'>max_grad</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q)</span></i><code><font color="blue"><span style='white-space: nowrap'>&nbsp;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;2)<br>
1135</span></font></code>is a bound on the partial of the
1136Lagrangian with respect to <code>
1137<span style='white-space: nowrap'>&nbsp;x</span></code>
1138
1139at the end of iteration <i>q-1</i>. To be specific
1140<code>
1141<span style='white-space: nowrap'>&nbsp;\[<br>
1142max\_grad(q)&nbsp;=&nbsp;\max_{j,&nbsp;k}&nbsp;\left[&nbsp;\left|<br>
1143(u_k^q)^\T&nbsp;*&nbsp;\partial_k&nbsp;f_k(x_k^q)&nbsp;+&nbsp;\partial_k&nbsp;&nbsp;S(x_1^q,&nbsp;\ldots&nbsp;,x_N^q)&nbsp;<br>
1144\right|&nbsp;\right]_j<br>
1145\]&nbsp;</span></code>
1146
1147where the maximum is with respect to
1148<code>
1149<span style='white-space: nowrap'>&nbsp;j&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;n</span></code>
1150 and
1151<code>
1152<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1153.
1154This value should converge to zero.
1155
1156<br>
1157<br>
1158<b><a name="3.r.c" id="3.r.c">3.r.c: max_fu</a></b>
1159<br>
1160The value
1161<code><font color="blue"><span style='white-space: nowrap'><br>
1162&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></code><i><span style='white-space: nowrap'>max_fu</span></i><code><font color="blue"><span style='white-space: nowrap'>&nbsp;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;3)<br>
1163</span></font></code>is a bound on
1164the complementarity conditions
1165at the end of iteration <i>q-1</i>. To be specific
1166<code>
1167<span style='white-space: nowrap'>&nbsp;\[<br>
1168max\_fu(q)&nbsp;=&nbsp;\max_{i,&nbsp;k}&nbsp;[&nbsp;|&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)_i&nbsp;|&nbsp;*&nbsp;(&nbsp;u_k&nbsp;)_i&nbsp;]<br>
1169\]&nbsp;</span></code>
1170
1171where the maximum is with respect to
1172<code>
1173<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
1174 and
1175<code>
1176<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1177.
1178This value should converge to be less than or equal zero.
1179
1180<br>
1181<br>
1182<b><a name="3.r.d" id="3.r.d">3.r.d: obj_cur</a></b>
1183<br>
1184The value
1185<code><font color="blue"><span style='white-space: nowrap'><br>
1186&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></code><i><span style='white-space: nowrap'>obj_cur</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>)&nbsp;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;4)<br>
1187</span></font></code>is the value of the objective function
1188at the end of <code>
1189<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1190; i.e.,
1191<code>
1192<span style='white-space: nowrap'>&nbsp;\[<br>
1193&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj\_cur(q)&nbsp;=&nbsp;S(&nbsp;x_1^q&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_k^q&nbsp;)<br>
1194\]&nbsp;</span></code>
1195
1196(Note that <code>
1197<span style='white-space: nowrap'>&nbsp;info(1,&nbsp;4)%</span></code>
1198 is the value of the objective
1199corresponding to <i>x_in</i>.
1200
1201<br>
1202<br>
1203<b><a name="3.r.e" id="3.r.e">3.r.e: lambda</a></b>
1204<br>
1205The value
1206<code><font color="blue"><span style='white-space: nowrap'><br>
1207&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></code><i><span style='white-space: nowrap'>lambda</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>)&nbsp;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;5)<br>
1208</span></font></code>is the line search step size used during
1209iteration <code>
1210<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1211 of <code><font color="blue">ckbs_nonlinear</font></code>.
1212If the problem is nearly affine (if the affine approximate is accurate)
1213this will be one.
1214Much small step sizes indicate highly non-affine problems
1215(with the exception that <code><font color="blue"></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(1,&nbsp;5)</span></font></code> is always zero).
1216
1217<br>
1218<br>
1219<b><a name="3.r.f" id="3.r.f">3.r.f: lam_aff</a></b>
1220<br>
1221The value
1222<code><font color="blue"><span style='white-space: nowrap'><br>
1223&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></font></code><i><span style='white-space: nowrap'>lam_aff</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>)&nbsp;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;6)<br>
1224</span></font></code>is the minimum line search step size
1225while solving the affine sub-problem that corresponds to
1226iteration <code>
1227<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1228 of <code><font color="blue">ckbs_nonlinear</font></code>.
1229If the sub-problem solution is working well,
1230this will be one.
1231Much small step sizes indicate the sub-problem solution is not working well.
1232
1233
1234
1235<br>
1236<br>
1237<b><a name="3.r.g" id="3.r.g">3.r.g: Penalty Parameter</a></b>
1238<br>
1239The exact penalty function
1240<code>
1241<span style='white-space: nowrap'>&nbsp;\[<br>
1242&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_k&nbsp;)&nbsp;<br>
1243&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;\alpha&nbsp;\sum_{k=1}^N&nbsp;\sum_{i=1}^\ell&nbsp;\max&nbsp;[&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)_i&nbsp;,&nbsp;0&nbsp;]<br>
1244\]&nbsp;</span></code>
1245
1246is used to determine the line search step size.
1247The value <code><font color="blue"></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>a</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;7)</span></font></code> is the penalty parameter
1248<code>
1249<span style='white-space: nowrap'>&nbsp;\alpha</span></code>
1250 during iteration <code>
1251<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1252 of <code><font color="blue">ckbs_nonlinear</font></code>.
1253
1254<br>
1255<br>
1256<b><big><a name="3.s" id="3.s">3.s: Example</a></big></b>
1257
1258
1259<br>
1260<br>
1261<b><a name="3.s.a" id="3.s.a">3.s.a: Simple</a></b>
1262<br>
1263The file <a href="#3.1">3.1: <span style='white-space: nowrap'>nonlinear_ok_simple.m</span></a>
1264 contains a simple example
1265and test of <code><font color="blue">ckbs_nonlinear</font></code>.
1266It returns true if <code><font color="blue">ckbs_nonlinear</font></code> passes the tests
1267and false otherwise.
1268
1269<br>
1270<br>
1271<b><a name="3.s.b" id="3.s.b">3.s.b: Box Constraints</a></b>
1272<br>
1273The file <a href="#3.2">3.2: <span style='white-space: nowrap'>nonlinear_ok_box.m</span></a>
1274 contains an example
1275and test of <code><font color="blue">ckbs_nonlinear</font></code> with box constraints
1276and a nonlinear measurement function.
1277It returns true if <code><font color="blue">ckbs_nonlinear</font></code> passes the tests
1278and false otherwise.
1279
1280<br>
1281<br>
1282<b><a name="3.s.c" id="3.s.c">3.s.c: Nonlinear Constraints</a></b>
1283<br>
1284The file <a href="#3.3">3.3: <span style='white-space: nowrap'>nonlinear_ok_sin.m</span></a>
1285 contains an example
1286and test of <code><font color="blue">ckbs_nonlinear</font></code> with a sine wave constraint
1287and a nonlinear measurement function.
1288It returns true if <code><font color="blue">ckbs_nonlinear</font></code> passes the tests
1289and false otherwise.
1290
1291
1292
1293<hr>Input File: src/ckbs_nonlinear.m
1294
1295<hr>
1296 
1297
1298
1299<center><b><big><big><a name="3.1" id="3.1">3.1: Simple ckbs_nonlinear Example and Test</a>
1300</big></big></b></center>
1301<br>
1302<b><big><a name="3.1.a" id="3.1.a">3.1.a: Call Back Functions</a></big></b>
1303
1304<table><tr><td align='left'  valign='top'>
1305
1306<a href="#3.1.1">3.1.1: nonlinear_ok_simple_f.m</a></td><td>
1307Example Constraint Function: nonlinear_ok_simple_f</td></tr>
1308<tr><td>
1309
1310<a href="#3.1.2">3.1.2: nonlinear_ok_simple_g.m</a></td><td>
1311Example Transition Function: nonlinear_ok_simple_g</td></tr>
1312<tr><td>
1313
1314<a href="#3.1.3">3.1.3: nonlinear_ok_simple_h.m</a></td><td>
1315Example Measurement Function: nonlinear_ok_simple_h</td></tr>
1316<tr><td>
1317
1318</td></tr>
1319</table>
1320<br>
1321<b><big><a name="3.1.b" id="3.1.b">3.1.b: Source Code</a></big></b>
1322
1323 <code><font color='blue'><pre style='display:inline'> 
1324function [ok] = nonlinear_ok_simple()
1325% --------------------------------------------------------------------
1326max_itr = 20;      % maximum number of iterations
1327epsilon = 1e-5;    % convergence criteria
1328N       = 3;       % number of time points
1329ell     = 2;       % number of constraints
1330m       = 1;       % number of measurements per time point
1331n       = 3;       % number of state vector components per time point
1332sigma   = 1;       % variance of measurement noise
1333level   = 0;       % level of tracing in ckbs_nonlinear
1334%
1335% simulated true trajectory
1336x_true  = ones(n, 1) * (1 : N);
1337%
1338% simulate measurement noise
1339e_true  = zeros(m, N);
1340%
1341% initial x vector
1342x_in = zeros(n, N);
1343%
1344% --------------------------------------------------------------------
1345if m &gt; n
1346        error('nonlinear_ok_simple: m &gt; n');
1347end
1348if ell &gt; n
1349        error('nonlinear_ok_simple: ell &gt; n');
1350end
1351%
1352global nonlinear_ok_simple_m
1353global nonlinear_ok_simple_ell
1354global nonlinear_ok_simple_N
1355%
1356nonlinear_ok_simple_m   = m;
1357nonlinear_ok_simple_ell = ell;
1358nonlinear_ok_simple_N   = N;
1359%
1360% measurement variances
1361rinv    = zeros(m, m, N);
1362qinv    = zeros(n, n, N);
1363qinvk   = eye(n) / (sigma * sigma);
1364rinvk   = eye(m) / (sigma * sigma);
1365z       = zeros(m, N);
1366for k = 1 : N
1367        xk           = x_true(:, k);
1368        ek           = e_true(:, k);
1369        hk           = nonlinear_ok_simple_h(k, xk);
1370        z(:, k)      = hk + ek;
1371        qinv(:,:, k) = qinvk;
1372        rinv(:,:, k) = rinvk;
1373end
1374%
1375% pass the maximum state value to f
1376global nonlinear_ok_simple_f_max
1377nonlinear_ok_simple_f_max = (N - .5) * ones(m, 1);
1378%
1379% ----------------------------------------------------------------------
1380f_fun = 'nonlinear_ok_simple_f';
1381g_fun = 'nonlinear_ok_simple_g';
1382h_fun = 'nonlinear_ok_simple_h';
1383[x_out, u_out, info] = ckbs_nonlinear( ...
1384        f_fun,    ...
1385        g_fun,    ...
1386        h_fun,    ...
1387        max_itr,  ...
1388        epsilon,  ...
1389        x_in,     ...
1390        z,        ...
1391        qinv,     ...
1392        rinv,     ...
1393        level     ...
1394);
1395% ----------------------------------------------------------------------
1396ok     = size(info, 1) &lt;= max_itr;
1397f_out  = zeros(ell, N);
1398g_out  = zeros(n,   N);
1399h_out  = zeros(m,   N);
1400df_out = zeros(ell, n, N);
1401dg_out = zeros(n, n,   N);
1402dh_out = zeros(m, n,   N);
1403xk1    = zeros(n, 1);
1404for k = 1 : N
1405        xk       = x_out(:, k);
1406        uk       = u_out(:, k);
1407        [fk, Fk] = feval(f_fun, k, xk);
1408        [gk, Gk] = feval(g_fun, k, xk1);
1409        [hk, Hk] = feval(h_fun, k, xk);
1410        %
1411        ok       = ok &amp; all( fk &lt;= epsilon);
1412        ok       = ok &amp; all( abs(fk) .* uk &lt;= epsilon );
1413        %
1414        f_out(:, k) = fk - Fk * xk;
1415        g_out(:, k) = gk - Gk * xk1;
1416        h_out(:, k) = hk - Hk * xk;
1417        df_out(:,:, k) = Fk;
1418        dg_out(:,:, k) = Gk;
1419        dh_out(:,:, k) = Hk;
1420        xk1 = xk;
1421end
1422ok   = ok &amp; all( all( u_out &gt;= 0 ) );
1423grad  = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
1424for k = 1 : N
1425        uk  = u_out(:, k);
1426        Fk  = df_out(:,:, k);
1427        dk  = grad(:, k);
1428        %
1429        ok  = ok &amp; all( abs(Fk' * uk + dk) &lt;= epsilon );
1430end
1431return
1432end
1433</pre></font></code>
1434 
1435
1436<hr>Input File: test/nonlinear_ok_simple.m
1437
1438<hr>
1439 
1440
1441
1442
1443<center><b><big><big><a name="3.1.1" id="3.1.1">3.1.1: Example Constraint Function: nonlinear_ok_simple_f</a>
1444</big></big></b></center>
1445<br>
1446<b><big><a name="3.1.1.a" id="3.1.1.a">3.1.1.a: Source Code</a></big></b>
1447
1448 <code><font color='blue'><pre style='display:inline'> 
1449function [fk, Fk] = nonlinear_ok_simple_f(k, xk)
1450        global nonlinear_ok_simple_N
1451        global nonlinear_ok_simple_ell
1452        %
1453        N   = nonlinear_ok_simple_N;
1454        ell = nonlinear_ok_simple_ell;
1455        n   = size(xk, 1);
1456        % xk(1:ell)^2 &lt;= N - .5
1457        fk = xk(1:ell).^2 - (N - .5);
1458        Fk = zeros(ell, n);
1459        for i = 1 : ell
1460                Fk(i, i) = 2 * xk(i);
1461        end
1462        return
1463end
1464</pre></font></code>
1465 
1466
1467<hr>Input File: test/nonlinear_ok_simple_f.m
1468
1469<hr>
1470 
1471
1472
1473
1474<center><b><big><big><a name="3.1.2" id="3.1.2">3.1.2: Example Transition Function: nonlinear_ok_simple_g</a>
1475</big></big></b></center>
1476<br>
1477<b><big><a name="3.1.2.a" id="3.1.2.a">3.1.2.a: Source Code</a></big></b>
1478
1479 <code><font color='blue'><pre style='display:inline'> 
1480function [gk, Gk] = nonlinear_ok_simple_g(k, xk1)
1481        n  = size(xk1, 1);
1482        if k == 1
1483                Gk = zeros(n, n);
1484                gk = Gk * xk1 + 1;
1485        else
1486                Gk = eye(n);
1487                gk = Gk * xk1 + 1;
1488        end
1489        return
1490end
1491</pre></font></code>
1492 
1493
1494<hr>Input File: test/nonlinear_ok_simple_g.m
1495
1496<hr>
1497 
1498
1499
1500
1501<center><b><big><big><a name="3.1.3" id="3.1.3">3.1.3: Example Measurement Function: nonlinear_ok_simple_h</a>
1502</big></big></b></center>
1503<br>
1504<b><big><a name="3.1.3.a" id="3.1.3.a">3.1.3.a: Source Code</a></big></b>
1505
1506 <code><font color='blue'><pre style='display:inline'> 
1507function [hk, Hk] = nonlinear_ok_simple_h(k, xk)
1508        global nonlinear_ok_simple_m
1509        %
1510        n        = size(xk, 1);
1511        m        = nonlinear_ok_simple_m;
1512        hk       = xk(1:m);
1513        Hk       = [ eye(m) , zeros(m, n-m) ];
1514        return
1515end
1516</pre></font></code>
1517 
1518
1519<hr>Input File: test/nonlinear_ok_simple_h.m
1520
1521<hr>
1522 
1523
1524
1525<center><b><big><big><a name="3.2" id="3.2">3.2: ckbs_nonlinear Box Constrained Tracking Example and Test</a>
1526</big></big></b></center>
1527<br>
1528<b><big><a name="3.2.a" id="3.2.a">3.2.a: Syntax</a></big></b>
1529
1530<br>
1531<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>ok</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;nonlinear_ok_box(</span></font></code><i><span style='white-space: nowrap'>draw_plot</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
1532
1533<br>
1534<br>
1535<b><big><a name="3.2.b" id="3.2.b">3.2.b: draw_plot</a></big></b>
1536<br>
1537If this argument is true, a plot is drawn showing the results
1538and the <code><font color="blue">nonlinear_ok_box.out</font></code> file is written for use with
1539the program <code><font color="blue">nonlinear_ok_box.r</font></code>.
1540
1541<br>
1542<br>
1543<b><big><a name="3.2.c" id="3.2.c">3.2.c: ok</a></big></b>
1544<br>
1545If the return value <i>ok</i> is true, the test passed,
1546otherwise the test failed.
1547
1548<br>
1549<br>
1550<b><big><a name="3.2.d" id="3.2.d">3.2.d: State Vector</a></big></b>
1551
1552<table><tr><td align='left'  valign='top'>
1553
1554<code>
1555<span style='white-space: nowrap'>&nbsp;x1&nbsp;(t)</span></code>
1556  </td><td align='left'  valign='top'>
1557 first component of velocity  </td></tr><tr><td align='left'  valign='top'>
1558
1559<code>
1560<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
1561  </td><td align='left'  valign='top'>
1562 first component of position  </td></tr><tr><td align='left'  valign='top'>
1563
1564<code>
1565<span style='white-space: nowrap'>&nbsp;x3&nbsp;(t)</span></code>
1566  </td><td align='left'  valign='top'>
1567 second component of velocity  </td></tr><tr><td align='left'  valign='top'>
1568
1569<code>
1570<span style='white-space: nowrap'>&nbsp;x4&nbsp;(t)</span></code>
1571  </td><td align='left'  valign='top'>
1572 second component of position 
1573</td></tr>
1574</table>
1575<br>
1576<b><big><a name="3.2.e" id="3.2.e">3.2.e: Measurement Vector</a></big></b>
1577
1578<table><tr><td align='left'  valign='top'>
1579
1580<code>
1581<span style='white-space: nowrap'>&nbsp;z1&nbsp;(t)</span></code>
1582  </td><td align='left'  valign='top'>
1583 range to the station s1  plus noise </td></tr><tr><td align='left'  valign='top'>
1584
1585<code>
1586<span style='white-space: nowrap'>&nbsp;z2&nbsp;(t)</span></code>
1587  </td><td align='left'  valign='top'>
1588 range to the station s2  plus noise
1589</td></tr>
1590</table>
1591<br>
1592<b><big><a name="3.2.f" id="3.2.f">3.2.f: Constraint</a></big></b>
1593
1594<br>
1595<code>
1596<span style='white-space: nowrap'>&nbsp;2&nbsp;+&nbsp;x4\_min&nbsp;\geq&nbsp;x_4&nbsp;(t)&nbsp;\geq&nbsp;x4\_min&nbsp;</span></code>
1597.
1598
1599
1600<br>
1601<br>
1602<b><big><a name="3.2.g" id="3.2.g">3.2.g: Call Back Functions</a></big></b>
1603
1604<table><tr><td align='left'  valign='top'>
1605
1606<a href="#3.2.1">3.2.1: nonlinear_ok_box_f.m</a></td><td>
1607Example Constraint Function: nonlinear_ok_box_f</td></tr>
1608<tr><td>
1609
1610<a href="#3.2.2">3.2.2: nonlinear_ok_box_g.m</a></td><td>
1611Example Transition Function: nonlinear_ok_box_g</td></tr>
1612<tr><td>
1613
1614<a href="#3.2.3">3.2.3: nonlinear_ok_box_h.m</a></td><td>
1615Example Measurement Function: nonlinear_ok_box_h</td></tr>
1616<tr><td>
1617
1618<a href="#3.2.4">3.2.4: nonlinear_ok_box_nof.m</a></td><td>
1619Example no Constraint Function: nonlinear_ok_box_nof</td></tr>
1620<tr><td>
1621
1622</td></tr>
1623</table>
1624<br>
1625<b><big><a name="3.2.h" id="3.2.h">3.2.h: Source Code</a></big></b>
1626
1627 <code><font color='blue'><pre style='display:inline'> 
1628function [ok] = nonlinear_ok_box(draw_plot)
1629if nargin &lt; 1
1630        draw_plot = false;
1631end
1632% --------------------------------------------------------
1633% You can change these parameters
1634N       = 50;            % number of measurement time points
1635dt      = 2 * pi / N;    % time between measurement points
1636sigma   = .25;           % standard deviation of measurement noise
1637gamma   = 1;             % multiplier for transition variance
1638max_itr = 50;            % maximum number of iterations
1639epsilon = 1e-4;          % convergence criteria
1640x4_min  = .25;           % minimum value for x4_true
1641h_min   = 0;             % minimum horizontal value in plots
1642h_max   = 7;             % maximum horizontal value in plots
1643v_min   = 0;             % minimum vertical value in plots
1644v_max   = 2.5;           % maximum vertical value in plots
1645s1      = [ 0 , 0 ];     % station one
1646s2      = [ 2*pi , 0 ];  % station two
1647%
1648% level of tracing during the optimization
1649if draw_plot
1650        level   = 1;
1651else
1652        level   = 0;
1653end
1654% ---------------------------------------------------------
1655%
1656% global variables used by nonlinear_ok_box_h
1657global nonlinear_ok_box_s1
1658global nonlinear_ok_box_s2
1659nonlinear_ok_box_s1 = s1;
1660nonlinear_ok_box_s2 = s2;
1661%
1662ok = true;
1663%
1664%  Define the problem
1665rand('seed', 1234);
1666%
1667% number of constraints per time point
1668ell   = 2;
1669%
1670% number of measurements per time point
1671m     = 2;
1672%
1673% number of state vector components per time point
1674n     = 4;
1675%
1676% simulate the true trajectory and measurement noise
1677t        =  (1 : N) * dt;
1678x2_true  = t;
1679x4_max   = x4_min + 2;
1680x4_true  = x4_min + 1 - sin(t);
1681x1_true  = ones(1, N);
1682x3_true  = - cos(t);
1683x_true   = [ x1_true ; x2_true ; x3_true ; x4_true ];
1684v1_true  = sigma * randn(1, N);
1685v2_true  = sigma * randn(1, N);
1686%
1687% corresponding measurement values
1688rinv    = zeros(m, m, N);
1689z       = zeros(m, N);
1690rinvk   = eye(m) / (sigma * sigma);
1691for k = 1 : N
1692        x_k          = x_true(:, k);
1693        h_k          = nonlinear_ok_box_h(k, x_k);
1694        z(:, k)      = h_k + [ v1_true(k) ; v2_true(k) ];
1695        rinv(:,:, k) = rinvk;
1696end
1697%
1698% covariance for the transition noise
1699qk       = diag( [ dt, dt^3 / 3 , dt, dt^3 / 3 ] );
1700qk(1, 2) = dt^2 / 2;
1701qk(2, 1) = dt^2 / 2;
1702qk(3, 4) = dt^2 / 2;
1703qk(4, 3) = dt^2 / 2;
1704qk       = qk * gamma;
1705qinvk    = inv(qk);
1706qinv     = zeros(n, n, N);
1707for k = 2 : N
1708        qinv(:,:, k) = qinvk;
1709end
1710%
1711% covariance for the initial estimate
1712qinv(:,:,1) = eye(n) * 100 * gamma;
1713%
1714% initial x vector
1715x_in = zeros(n, N);
1716for k = 1 : N
1717        x_in(:, k) = [ 0 ; 1 ; 0 ; 1 ];
1718end
1719%
1720% global variables used by nonlinear_ok_box_f
1721global nonlinear_ok_box_x4_min
1722global nonlinear_ok_box_x4_max
1723nonlinear_ok_box_x4_min = x4_min;
1724nonlinear_ok_box_x4_max = x4_max;
1725%
1726% global variables used by nonlinear_ok_box_g
1727global nonlinear_ok_box_x1
1728global nonlinear_ok_box_dt
1729nonlinear_ok_box_x1 = x_true(:, 1);
1730nonlinear_ok_box_dt = dt;
1731%
1732% ----------------------------------------------------------------------
1733f_fun = 'nonlinear_ok_box_f';
1734g_fun = 'nonlinear_ok_box_g';
1735h_fun = 'nonlinear_ok_box_h';
1736[x_out, u_out, info] = ckbs_nonlinear( ...
1737        f_fun,    ...
1738        g_fun,    ...
1739        h_fun,    ...
1740        max_itr,  ...
1741        epsilon,  ...
1742        x_in,     ...
1743        z,        ...
1744        qinv,     ...
1745        rinv,     ...
1746        level     ...
1747);
1748% ----------------------------------------------------------------------
1749ok         = ok &amp; (size(info,1) &lt;= max_itr);
1750f_out      = zeros(ell, N);
1751g_out      = zeros(n, N);
1752h_out      = zeros(m, N);
1753df_out     = zeros(ell, n, N);
1754dg_out     = zeros(n, n, N);
1755dh_out     = zeros(m, n, N);
1756xk1        = zeros(n, 1);
1757for k = 1 : N
1758        xk    = x_out(:, k);
1759        uk    = u_out(:, k);
1760        [fk, Fk]   = nonlinear_ok_box_f(k, xk);
1761        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
1762        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
1763        %
1764        ok   = ok &amp; all( fk &lt;= epsilon );
1765        ok   = ok &amp; all( abs(fk) .* uk &lt;= epsilon );
1766        %
1767        df_out(:,:, k) = Fk;
1768        dg_out(:,:, k) = Gk;
1769        dh_out(:,:, k) = Hk;
1770        f_out(:, k)    = fk - Fk * xk;
1771        g_out(:, k)    = gk - Gk * xk1;
1772        h_out(:, k)    = hk - Hk * xk;
1773        xk1 = xk;
1774end
1775ok   = ok &amp; all( all( u_out &gt;= 0 ) );
1776%
1777d_out = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
1778for k = 1 : N
1779        uk = u_out(:, k);
1780        Fk = df_out(:,:, k);
1781        dk = d_out(:, k);
1782        %
1783        ok = ok &amp; (max ( abs( Fk' * uk + dk ) ) &lt;= epsilon);
1784end
1785if ~ ok
1786        keyboard
1787end
1788if draw_plot
1789        figure(1);
1790        clf
1791        hold on
1792        plot(x_true(2,:)', x_true(4,:)', 'b-' );
1793        plot(x_out(2,:)', x_out(4,:)', 'g-' );
1794        plot(x_true(2,:)', x4_min * ones(N,1), 'r-');
1795        plot(x_true(2,:)', x4_max * ones(N,1), 'r-');
1796        axis([h_min, h_max, v_min, v_max]);
1797        title('Constrained: blue=truth, green=estimate, red=constraint');
1798        hold off
1799        %
1800        % constrained estimate
1801        x_con = x_out;
1802end
1803% ----------------------------------------------------------------------
1804% Unconstrained case
1805f_fun = 'nonlinear_ok_box_nof';
1806[x_out, u_out, info] = ckbs_nonlinear( ...
1807        f_fun,    ...
1808        g_fun,    ...
1809        h_fun,    ...
1810        max_itr,  ...
1811        epsilon,  ...
1812        x_in,     ...
1813        z,        ...
1814        qinv,     ...
1815        rinv,     ...
1816        level     ...
1817);
1818% ----------------------------------------------------------------------
1819ok   = ok &amp; (size(info,1) &lt;= max_itr);
1820xk1  = zeros(n, 1);
1821for k = 1 : N
1822        xk    = x_out(:, k);
1823        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
1824        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
1825        %
1826        dg_out(:,:, k) = Gk;
1827        dh_out(:,:, k) = Hk;
1828        g_out(:, k)    = gk - Gk * xk1;
1829        h_out(:, k)    = hk - Hk * xk;
1830        xk1 = xk;
1831end
1832d_out  = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
1833ok     = ok &amp; (max( max( abs(d_out) ) ) &lt;= epsilon);
1834if draw_plot
1835        figure(2);
1836        clf
1837        hold on
1838        plot(x_true(2,:)', x_true(4,:)', 'b-' );
1839        plot(x_out(2,:)', x_out(4,:)', 'g-' );
1840        plot(x_true(2,:)', x4_min * ones(1,N), 'r-');
1841        plot(x_true(2,:)', x4_max * ones(1,N), 'r-');
1842        axis([h_min, h_max, v_min, v_max]);
1843        title('Unconstrained: blue=truth, green=estimate, red=constraint');
1844        hold off
1845        %
1846        % unconstrained estimate
1847        x_free = x_out;
1848        %
1849        % write out constrained and unconstrained results
1850        [fid, msg] = fopen('nonlinear_ok_box.out', 'wt');
1851        if size(msg, 2) &gt; 0
1852                disp(['nonlinear_ok: ', msg]);
1853        end
1854        %                      123456789012345678901234'
1855        heading =             ' x2_true  x2_con x2_free'  ;
1856        heading = [ heading , ' x4_true  x4_con x4_free' ];
1857        heading = [ heading , '      z1      z2\n'       ];
1858        fprintf(fid, heading);
1859        for k = 1 : N
1860                fprintf(fid,'%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f\n', ...
1861                        x_true(2,k), x_con(2,k), x_free(2,k), ...
1862                        x_true(4,k), x_con(4,k), x_free(4,k), ...
1863                        z(1,k), z(2,k) ...
1864                );
1865        end
1866        fclose(fid);
1867end
1868return
1869end
1870</pre></font></code>
1871 
1872
1873<hr>Input File: test/nonlinear_ok_box.m
1874
1875<hr>
1876 
1877
1878
1879
1880<center><b><big><big><a name="3.2.1" id="3.2.1">3.2.1: Example Constraint Function: nonlinear_ok_box_f</a>
1881</big></big></b></center>
1882<br>
1883<b><big><a name="3.2.1.a" id="3.2.1.a">3.2.1.a: Source Code</a></big></b>
1884
1885 <code><font color='blue'><pre style='display:inline'> 
1886function [fk, Fk] = nonlinear_ok_box_f(k, xk)
1887        global nonlinear_ok_box_x4_min
1888        global nonlinear_ok_box_x4_max
1889        %
1890        % constrained so that x4_min &lt;= x4(t) &lt;= x4_max
1891        x4_min = nonlinear_ok_box_x4_min;
1892        x4_max = nonlinear_ok_box_x4_max;
1893        ell    = 2;
1894        n      = size(xk, 1);
1895        %
1896        fk = [ ...
1897                xk(4) - x4_max;
1898                x4_min - xk(4) ...
1899        ];
1900        Fk = zeros(ell, n);
1901        Fk(1, 4) = 1;
1902        Fk(2, 4) = -1;
1903        return
1904end
1905</pre></font></code>
1906 
1907
1908<hr>Input File: test/nonlinear_ok_box_f.m
1909
1910<hr>
1911 
1912
1913
1914
1915<center><b><big><big><a name="3.2.2" id="3.2.2">3.2.2: Example Transition Function: nonlinear_ok_box_g</a>
1916</big></big></b></center>
1917<br>
1918<b><big><a name="3.2.2.a" id="3.2.2.a">3.2.2.a: Source Code</a></big></b>
1919
1920 <code><font color='blue'><pre style='display:inline'> 
1921function [gk, Gk] = nonlinear_ok_box_g(k, xk1)
1922        global nonlinear_ok_box_x1
1923        global nonlinear_ok_box_dt
1924        if k == 1
1925                Gk = zeros(4, 4);
1926                gk = nonlinear_ok_box_x1;
1927                return;
1928        end
1929        dt = nonlinear_ok_box_dt;
1930        Gk = [ ...
1931                1  0  0  0
1932                dt 1  0  0
1933                0  0  1  0
1934                0  0  dt 1 ...
1935        ];
1936        gk = Gk * xk1;
1937        return
1938end
1939</pre></font></code>
1940 
1941
1942<hr>Input File: test/nonlinear_ok_box_g.m
1943
1944<hr>
1945 
1946
1947
1948
1949<center><b><big><big><a name="3.2.3" id="3.2.3">3.2.3: Example Measurement Function: nonlinear_ok_box_h</a>
1950</big></big></b></center>
1951<br>
1952<b><big><a name="3.2.3.a" id="3.2.3.a">3.2.3.a: Source Code</a></big></b>
1953
1954 <code><font color='blue'><pre style='display:inline'> 
1955function [hk, Hk] = nonlinear_ok_box_h(k, xk)
1956        global nonlinear_ok_box_s1
1957        global nonlinear_ok_box_s2
1958        s1  = nonlinear_ok_box_s1;
1959        s2  = nonlinear_ok_box_s2;
1960        r1  = sqrt( (xk(2) - s1(1))^2 + (xk(4) - s1(2))^2 );
1961        r2  = sqrt( (xk(2) - s2(1))^2 + (xk(4) - s2(2))^2 );
1962        hk = [ r1 ; r2 ];
1963        dr1 = [ 0, xk(2) - s1(1), 0, xk(4) - s1(2) ] / r1;
1964        dr2 = [ 0, xk(2) - s2(1), 0, xk(4) - s2(2) ] / r2;
1965        Hk = [ dr1 ; dr2 ];
1966        return
1967end
1968</pre></font></code>
1969 
1970
1971<hr>Input File: test/nonlinear_ok_box_h.m
1972
1973<hr>
1974 
1975
1976
1977
1978<center><b><big><big><a name="3.2.4" id="3.2.4">3.2.4: Example no Constraint Function: nonlinear_ok_box_nof</a>
1979</big></big></b></center>
1980<br>
1981<b><big><a name="3.2.4.a" id="3.2.4.a">3.2.4.a: Source Code</a></big></b>
1982
1983 <code><font color='blue'><pre style='display:inline'> 
1984function [fk, Fk] = nonlinear_ok_box_nof(k, xk)
1985        % no constraint case
1986        n  = size(xk, 1);
1987        fk = -1;
1988        Fk = zeros(1, n);
1989        return
1990end
1991</pre></font></code>
1992 
1993
1994<hr>Input File: test/nonlinear_ok_box_nof.m
1995
1996<hr>
1997 
1998
1999
2000<center><b><big><big><a name="3.3" id="3.3">3.3: ckbs_nonlinear Sine Wave Constrained Tracking Example and Test</a>
2001</big></big></b></center>
2002<br>
2003<b><big><a name="3.3.a" id="3.3.a">3.3.a: Syntax</a></big></b>
2004
2005<br>
2006<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>ok</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;nonlinear_ok_sin(</span></font></code><i><span style='white-space: nowrap'>draw_plot</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
2007
2008<br>
2009<br>
2010<b><big><a name="3.3.b" id="3.3.b">3.3.b: draw_plot</a></big></b>
2011<br>
2012If this argument is true, a plot is drawn showing the results
2013and the <code><font color="blue">nonlinear_ok_sin.out</font></code> file is written for use with the
2014program <code><font color="blue">test/nonlinear_ok_sin.r</font></code>.
2015
2016<br>
2017<br>
2018<b><big><a name="3.3.c" id="3.3.c">3.3.c: ok</a></big></b>
2019<br>
2020If the return value <i>ok</i> is true, the test passed,
2021otherwise the test failed.
2022
2023<br>
2024<br>
2025<b><big><a name="3.3.d" id="3.3.d">3.3.d: State Vector</a></big></b>
2026
2027<table><tr><td align='left'  valign='top'>
2028
2029<code>
2030<span style='white-space: nowrap'>&nbsp;x1&nbsp;(t)</span></code>
2031  </td><td align='left'  valign='top'>
2032 first component of velocity   </td></tr><tr><td align='left'  valign='top'>
2033
2034<code>
2035<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
2036  </td><td align='left'  valign='top'>
2037 first component of position  </td></tr><tr><td align='left'  valign='top'>
2038
2039<code>
2040<span style='white-space: nowrap'>&nbsp;x3&nbsp;(t)</span></code>
2041  </td><td align='left'  valign='top'>
2042 second component of velocity   </td></tr><tr><td align='left'  valign='top'>
2043
2044<code>
2045<span style='white-space: nowrap'>&nbsp;x4&nbsp;(t)</span></code>
2046  </td><td align='left'  valign='top'>
2047 second component of position 
2048</td></tr>
2049</table>
2050<br>
2051<b><big><a name="3.3.e" id="3.3.e">3.3.e: Measurement Vector</a></big></b>
2052
2053<table><tr><td align='left'  valign='top'>
2054
2055<code>
2056<span style='white-space: nowrap'>&nbsp;z1&nbsp;(t)</span></code>
2057  </td><td align='left'  valign='top'>
2058 range to station s1 plus noise </td></tr><tr><td align='left'  valign='top'>
2059
2060<code>
2061<span style='white-space: nowrap'>&nbsp;z2&nbsp;(t)</span></code>
2062  </td><td align='left'  valign='top'>
2063 range to station s2  plus noise
2064</td></tr>
2065</table>
2066<br>
2067<b><big><a name="3.3.f" id="3.3.f">3.3.f: Constraint</a></big></b>
2068
2069<br>
2070<code>
2071<span style='white-space: nowrap'>&nbsp;&nbsp;x4(t)&nbsp;\geq&nbsp;1&nbsp;-&nbsp;sin(&nbsp;x2(t)&nbsp;)</span></code>
2072 
2073
2074
2075<br>
2076<br>
2077<b><big><a name="3.3.g" id="3.3.g">3.3.g: Call Back Functions</a></big></b>
2078
2079<table><tr><td align='left'  valign='top'>
2080
2081<a href="#3.3.1">3.3.1: nonlinear_ok_sin_f.m</a></td><td>
2082Example Constraint Function: nonlinear_ok_sin_f</td></tr>
2083<tr><td>
2084
2085<a href="#3.2.2">3.2.2: nonlinear_ok_box_g.m</a></td><td>
2086Example Transition Function: nonlinear_ok_box_g</td></tr>
2087<tr><td>
2088
2089<a href="#3.2.3">3.2.3: nonlinear_ok_box_h.m</a></td><td>
2090Example Measurement Function: nonlinear_ok_box_h</td></tr>
2091<tr><td>
2092
2093<a href="#3.2.4">3.2.4: nonlinear_ok_box_nof.m</a></td><td>
2094Example no Constraint Function: nonlinear_ok_box_nof</td></tr>
2095<tr><td>
2096
2097</td></tr>
2098</table>
2099<br>
2100<b><big><a name="3.3.h" id="3.3.h">3.3.h: Source Code</a></big></b>
2101
2102 <code><font color='blue'><pre style='display:inline'> 
2103function [ok] = nonlinear_ok_sin(draw_plot)
2104if nargin &lt; 1
2105        draw_plot = false;
2106end
2107% --------------------------------------------------------
2108% You can change these parameters
2109N       = 50;            % number of measurement time points
2110dt      = 2 * pi / N;    % time between measurement points
2111sigma   = .25;           % standard deviation of measurement noise
2112gamma   = 1.;            % multiplier for transition variance
2113max_itr = 50;            % maximum number of iterations
2114epsilon = 1e-4;          % convergence criteria
2115x4_min  = .25;           % minimum value for x4 constraint
2116h_min   = 0;             % minimum horizontal value in plots
2117h_max   = 7;             % maximum horizontal value in plots
2118v_min   = 0;             % minimum vertical value in plots
2119v_max   = 2.5;           % maximum vertical value in plots
2120x4_dist = .05;           % distance true path is from the constraint
2121s1      = [ 0 , 0 ];     % station one
2122s2      = [ 2*pi , 0 ];  % station two
2123%
2124% level of tracing during the optimization
2125if draw_plot
2126        level   = 1;
2127else
2128        level   = 0;
2129end
2130% ---------------------------------------------------------
2131% global variables used by nonlinear_ok_box_h
2132global nonlinear_ok_box_s1
2133global nonlinear_ok_box_s2
2134nonlinear_ok_box_s1 = s1;
2135nonlinear_ok_box_s2 = s2;
2136%
2137% global variable used by nonlinear_ok_sin_f
2138global nonlinear_ok_sin_x4_min
2139nonlinear_ok_sin_x4_min = x4_min;
2140%
2141ok = true;
2142%
2143%  Define the problem
2144rand('seed', 234);
2145%
2146% number of constraints per time point
2147ell   = 1;
2148%
2149% number of measurements per time point
2150m     = 2;
2151%
2152% number of state vector components per time point
2153n     = 4;
2154%
2155% simulate the true trajectory and measurement noise
2156t        =  (1 : N) * dt;
2157x1_true  = ones(1, N);
2158x2_true  = t;
2159x3_true  = - cos(t);
2160x4_true  = x4_dist + 1 - sin(t) + x4_min;
2161x_true   = [ x1_true ; x2_true ; x3_true ; x4_true ];
2162v1_true  = sigma * randn(1, N);
2163v2_true  = sigma * randn(1, N);
2164%
2165% corresponding measurement values
2166rinv    = zeros(m, m, N);
2167z       = zeros(m, N);
2168rinvk   = eye(m) / (sigma * sigma);
2169for k = 1 : N
2170        x_k          = x_true(:, k);
2171        h_k          = nonlinear_ok_box_h(k, x_k);
2172        z(:, k)      = h_k + [ v1_true(k) ; v2_true(k) ];
2173        rinv(:,:, k) = rinvk;
2174end
2175%
2176% covariance for the transition noise
2177qk       = diag( [ dt, dt^3 / 3 , dt, dt^3 / 3 ] );
2178qk(1, 2) = dt^2 / 2;
2179qk(2, 1) = dt^2 / 2;
2180qk(3, 4) = dt^2 / 2;
2181qk(4, 3) = dt^2 / 2;
2182qk       = qk * gamma;
2183qinvk    = inv(qk);
2184qinv     = zeros(n, n, N);
2185for k = 2 : N
2186        qinv(:,:, k) = qinvk;
2187end
2188%
2189% covariance for the initial estimate
2190qinv(:,:,1) = eye(n) * 100 * gamma;
2191%
2192% initial x vector
2193x_in       = zeros(n, N);
2194x_in(4, :) = 1;
2195%
2196% nonlinear_ok_sin use same g function as nonlinear_box_ok
2197% global variables used by nonlinear_ok_box_g
2198global nonlinear_ok_box_x1
2199global nonlinear_ok_box_dt
2200nonlinear_ok_box_x1 = x_true(:, 1);
2201nonlinear_ok_box_dt = dt;
2202%
2203% ----------------------------------------------------------------------
2204f_fun = 'nonlinear_ok_sin_f';  % special nonlinear_ok_sin constraints
2205g_fun = 'nonlinear_ok_box_g';  % same transition function as nonlinear_ok_box
2206h_fun = 'nonlinear_ok_box_h';  % same measurement function as nonlinear_ok_box
2207[x_out, u_out, info] = ckbs_nonlinear( ...
2208        f_fun,    ...
2209        g_fun,    ...
2210        h_fun,    ...
2211        max_itr,  ...
2212        epsilon,  ...
2213        x_in,     ...
2214        z,        ...
2215        qinv,     ...
2216        rinv,     ...
2217        level     ...
2218);
2219% ----------------------------------------------------------------------
2220ok         = ok &amp; (size(info,1) &lt;= max_itr);
2221f_out      = zeros(ell, N);
2222g_out      = zeros(n, N);
2223h_out      = zeros(m, N);
2224df_out     = zeros(ell, n, N);
2225dg_out     = zeros(n, n, N);
2226dh_out     = zeros(m, n, N);
2227xk1        = zeros(n, 1);
2228for k = 1 : N
2229        xk    = x_out(:, k);
2230        uk    = u_out(:, k);
2231        [fk, Fk]   = nonlinear_ok_sin_f(k, xk);
2232        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
2233        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
2234        %
2235        ok   = ok &amp; all( fk &lt;= epsilon );
2236        ok   = ok &amp; all( abs(fk) .* uk &lt;= epsilon );
2237        %
2238        df_out(:,:, k) = Fk;
2239        dg_out(:,:, k) = Gk;
2240        dh_out(:,:, k) = Hk;
2241        f_out(:, k)    = fk - Fk * xk;
2242        g_out(:, k)    = gk - Gk * xk1;
2243        h_out(:, k)    = hk - Hk * xk;
2244        xk1 = xk;
2245end
2246ok   = ok &amp; all( all( u_out &gt;= 0 ) );
2247%
2248d_out = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
2249for k = 1 : N
2250        uk = u_out(:, k);
2251        Fk = df_out(:,:, k);
2252        dk = d_out(:, k);
2253        %
2254        ok = ok &amp; (max ( abs( Fk' * uk + dk ) ) &lt;= epsilon);
2255end
2256if ~ ok
2257        keyboard
2258end
2259if draw_plot
2260        figure(1);
2261        clf
2262        hold on
2263        plot(x_true(2,:)', x_true(4,:)', 'b-' );
2264        plot(x_out(2,:)', x_out(4,:)', 'g-' );
2265        plot(x_true(2,:)', 1 - sin(x_true(2,:))' + x4_min, 'r-');
2266        axis([h_min, h_max, v_min, v_max]);
2267        title('Constrained: blue=truth, green=estimate, red=constraint');
2268        hold off
2269        %
2270        % constrained estimate
2271        x_con = x_out;
2272end
2273% ----------------------------------------------------------------------
2274% Unconstrained case
2275f_fun = 'nonlinear_ok_box_nof';  % same function as used by nonlinear_ok_box
2276[x_out, u_out, info] = ckbs_nonlinear( ...
2277        f_fun,    ...
2278        g_fun,    ...
2279        h_fun,    ...
2280        max_itr,  ...
2281        epsilon,  ...
2282        x_in,     ...
2283        z,        ...
2284        qinv,     ...
2285        rinv,     ...
2286        level     ...
2287);
2288% ----------------------------------------------------------------------
2289ok   = ok &amp; (size(info,1) &lt;= max_itr);
2290xk1  = zeros(n, 1);
2291for k = 1 : N
2292        xk    = x_out(:, k);
2293        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
2294        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
2295        %
2296        dg_out(:,:, k) = Gk;
2297        dh_out(:,:, k) = Hk;
2298        g_out(:, k)    = gk - Gk * xk1;
2299        h_out(:, k)    = hk - Hk * xk;
2300        xk1 = xk;
2301end
2302d_out  = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
2303ok     = ok &amp; (max( max( abs(d_out) ) ) &lt;= epsilon);
2304if draw_plot
2305        figure(2);
2306        clf
2307        hold on
2308        plot(x_true(2,:)', x_true(4,:)', 'b-' );
2309        plot(x_out(2,:)', x_out(4,:)', 'g-' );
2310        plot(x_true(2,:)', 1 - sin(x_true(2,:))' + x4_min, 'r-');
2311        axis([h_min, h_max, v_min, v_max]);
2312        title('Unconstrained: blue=truth, green=estimate, red=constraint');
2313        hold off
2314        %
2315        % unconstrained estimate
2316        x_free = x_out;
2317        %
2318        % write out constrained and unconstrained results
2319        [fid, msg] = fopen('nonlinear_ok_sin.out', 'wt');
2320        if size(msg, 2) &gt; 0
2321                disp(['nonlinear_ok: ', msg]);
2322        end
2323        %                      123456789012345678901234'
2324        heading =             ' x2_true  x2_con x2_free'  ;
2325        heading = [ heading , ' x4_true  x4_con x4_free' ];
2326        heading = [ heading , '      z1      z2\n'       ];
2327        fprintf(fid, heading);
2328        for k = 1 : N
2329                fprintf(fid,'%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f\n', ...
2330                        x_true(2,k), x_con(2,k), x_free(2,k), ...
2331                        x_true(4,k), x_con(4,k), x_free(4,k), ...
2332                        z(1,k), z(2,k) ...
2333                );
2334        end
2335        fclose(fid);
2336end
2337return
2338end
2339</pre></font></code>
2340 
2341
2342<hr>Input File: test/nonlinear_ok_sin.m
2343
2344<hr>
2345 
2346
2347
2348
2349<center><b><big><big><a name="3.3.1" id="3.3.1">3.3.1: Example Constraint Function: nonlinear_ok_sin_f</a>
2350</big></big></b></center>
2351<br>
2352<b><big><a name="3.3.1.a" id="3.3.1.a">3.3.1.a: Source Code</a></big></b>
2353
2354 <code><font color='blue'><pre style='display:inline'> 
2355function [fk, Fk] = nonlinear_ok_sin_f(k, xk)
2356        global nonlinear_ok_sin_x4_min
2357        x4_min = nonlinear_ok_sin_x4_min;
2358        %
2359        % constrained so that x(4) &gt;= 1 - sin( x(1) ) + x4_min
2360        ell      = 1;
2361        n        = size(xk, 1);
2362        %
2363        fk       = 1 - sin( xk(2) ) + x4_min - xk(4);
2364        Fk       = zeros(ell, n);
2365        Fk(1, 2) = - cos( xk(2) );
2366        Fk(1, 4) = -1;
2367        return
2368end
2369</pre></font></code>
2370 
2371
2372<hr>Input File: test/nonlinear_ok_sin_f.m
2373
2374<hr>
2375 
2376
2377
2378
2379
2380
2381
2382
2383
2384<center><b><big><big><a name="4" id="4">4: Constrained Affine Kalman Bucy Smoother</a>
2385</big></big></b></center>
2386<br>
2387<b><big><a name="4.a" id="4.a">4.a: Syntax</a></big></b>
2388
2389<br>
2390<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>xOut</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>uOut</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_affine(</span></font></code><i><span style='white-space: nowrap'>max_itr</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>z</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>b</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>g</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>h</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>db</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dg</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dh</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>qinv</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>rinv</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
2391
2392<br>
2393<br>
2394<b><big><a name="4.b" id="4.b">4.b: Purpose</a></big></b>
2395<br>
2396This routine minimizes the
2397affine Kalman-Bucy smoother residual sum of squares objective
2398subject to an affine inequality constraint.
2399
2400<br>
2401<br>
2402<b><big><a name="4.c" id="4.c">4.c: Notation</a></big></b>
2403<br>
2404The affine Kalman-Bucy smoother residual sum of squares is defined by
2405<code>
2406<span style='white-space: nowrap'>&nbsp;\[<br>
2407\begin{array}{rcl}<br>
2408S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;\sum_{k=1}^N&nbsp;S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;\\<br>
2409S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
2410\frac{1}{2}&nbsp;<br>
2411(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)^\T&nbsp;*&nbsp;R_k^{-1}&nbsp;*&nbsp;(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)<br>
2412\\<br>
2413&amp;&nbsp;+&nbsp;&amp;<br>
2414\frac{1}{2}&nbsp;<br>
2415(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)^\T&nbsp;*&nbsp;Q_k^{-1}&nbsp;*&nbsp;(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)<br>
2416\\<br>
2417\end{array}<br>
2418\]&nbsp;</span></code>
2419
2420where the matrices <code>
2421<span style='white-space: nowrap'>&nbsp;R_k</span></code>
2422 and <code>
2423<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
2424 are
2425symmetric positive definite and
2426<code>
2427<span style='white-space: nowrap'>&nbsp;x_0</span></code>
2428 is the constant zero.
2429Note that <code>
2430<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2431 is the initial state estimate
2432and <code>
2433<span style='white-space: nowrap'>&nbsp;Q_1</span></code>
2434 is the corresponding covariance.
2435
2436<br>
2437<br>
2438<b><big><a name="4.d" id="4.d">4.d: Problem</a></big></b>
2439<br>
2440The affine constrained Kalman-Bucy smoother problem is
2441<code>
2442<span style='white-space: nowrap'>&nbsp;\[<br>
2443\begin{array}{rll}<br>
2444{\rm&nbsp;minimize}&nbsp;<br>
2445&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;S(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;<br>
2446&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;{\rm&nbsp;w.r.t.}&nbsp;\;&nbsp;x_1&nbsp;\in&nbsp;\R^n&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;\in&nbsp;\R^n<br>
2447\\<br>
2448{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;<br>
2449&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;b_k&nbsp;+&nbsp;B_k&nbsp;*&nbsp;x_k&nbsp;&nbsp;\leq&nbsp;0&nbsp;<br>
2450&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;{\rm&nbsp;for}&nbsp;\;&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N<br>
2451\end{array}<br>
2452\]&nbsp;</span></code>
2453
2454
2455<br>
2456<br>
2457<b><big><a name="4.e" id="4.e">4.e: First Order Conditions</a></big></b>
2458<br>
2459A state sequence <code>
2460<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
2461 is considered a solution
2462if there is a Lagrange multiplier sequence <code>
2463<span style='white-space: nowrap'>&nbsp;(&nbsp;u_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;u_N&nbsp;)</span></code>
2464 
2465such that the following conditions are satisfied.
2466<code>
2467<span style='white-space: nowrap'>&nbsp;\[<br>
2468\begin{array}{rcl}<br>
2469&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b_k&nbsp;+&nbsp;B_k&nbsp;*&nbsp;x_k&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;\varepsilon&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
2470&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;u_k&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
2471&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;(&nbsp;B_k^T&nbsp;*&nbsp;u_k&nbsp;+&nbsp;d_k&nbsp;)_j&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;\varepsilon&nbsp;\\&nbsp;&nbsp;<br>
2472&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;(u_k)_i&nbsp;*&nbsp;(&nbsp;b_k&nbsp;+&nbsp;B_k&nbsp;*&nbsp;x_k)_i&nbsp;|&nbsp;&amp;&nbsp;\leq&nbsp;&amp;&nbsp;\varepsilon<br>
2473\end{array}<br>
2474\]&nbsp;</span></code>
2475
2476for <code>
2477<span style='white-space: nowrap'>&nbsp;j&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;n</span></code>
2478,
2479<code>
2480<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
2481, and
2482<code>
2483<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2484.
2485Here
2486<code>
2487<span style='white-space: nowrap'>&nbsp;d_k</span></code>
2488 is the partial derivative of <code>
2489<span style='white-space: nowrap'>&nbsp;S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
2490
2491with respect to <code>
2492<span style='white-space: nowrap'>&nbsp;x_k</span></code>
2493
2494and <code>
2495<span style='white-space: nowrap'>&nbsp;(u_k)_i</span></code>
2496 denotes the <i>i</i>-th component of <code>
2497<span style='white-space: nowrap'>&nbsp;u_k</span></code>
2498.
2499
2500<br>
2501<br>
2502<b><big><a name="4.f" id="4.f">4.f: max_itr</a></big></b>
2503<br>
2504The integer scalar <i>max_itr</i> specifies the maximum number of
2505iterations of the algorithm to execute. It must be greater than or
2506equal to zero. Note that if it is zero, the first row of the
2507<a href="#4.s">4.s: <span style='white-space: nowrap'>info</span></a>
2508 return value will still be computed.
2509This can be useful for deciding what is a good value for the argument
2510<a href="#4.g">4.g: <span style='white-space: nowrap'>epsilon</span></a>
2511.
2512
2513<br>
2514<br>
2515<b><big><a name="4.g" id="4.g">4.g: epsilon</a></big></b>
2516<br>
2517The positive scalar <i>epsilon</i> specifies the convergence
2518criteria value; i.e.,
2519<code>
2520<span style='white-space: nowrap'>&nbsp;\[<br>
2521&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\varepsilon&nbsp;=&nbsp;epsilon<br>
2522\]&nbsp;</span></code>
2523
2524
2525<br>
2526<br>
2527<b><big><a name="4.h" id="4.h">4.h: z</a></big></b>
2528<br>
2529The argument <i>z</i> is a two dimensional array,
2530for <code>
2531<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2532
2533<code>
2534<span style='white-space: nowrap'>&nbsp;\[<br>
2535&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z_k&nbsp;=&nbsp;z(:,&nbsp;k)<br>
2536\]</span></code>
2537
2538and <i>z</i> has size <code>
2539<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
2540.
2541
2542<br>
2543<br>
2544<b><big><a name="4.i" id="4.i">4.i: b</a></big></b>
2545<br>
2546The argument <i>b</i> is a two dimensional array,
2547for <code>
2548<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2549
2550<code>
2551<span style='white-space: nowrap'>&nbsp;\[<br>
2552&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b_k&nbsp;=&nbsp;b(:,&nbsp;k)<br>
2553\]</span></code>
2554
2555and <i>b</i> has size <code>
2556<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;N</span></code>
2557.
2558If <code>
2559<span style='white-space: nowrap'>&nbsp;\ell&nbsp;=&nbsp;0</span></code>
2560, the problem is not constrained; i.e.,
2561it is the affine Kalman-Bucy smoother problem.
2562
2563<br>
2564<br>
2565<b><big><a name="4.j" id="4.j">4.j: g</a></big></b>
2566<br>
2567The argument <i>g</i> is a two dimensional array,
2568for <code>
2569<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2570
2571<code>
2572<span style='white-space: nowrap'>&nbsp;\[<br>
2573&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_k&nbsp;=&nbsp;g(:,&nbsp;k)<br>
2574\]</span></code>
2575
2576and <i>g</i> has size <code>
2577<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
2578.
2579The value <code>
2580<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2581 serves as the initial state estimate.
2582
2583<br>
2584<br>
2585<b><big><a name="4.k" id="4.k">4.k: h</a></big></b>
2586<br>
2587The argument <i>h</i> is a two dimensional array,
2588for <code>
2589<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2590
2591<code>
2592<span style='white-space: nowrap'>&nbsp;\[<br>
2593&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h_k&nbsp;=&nbsp;h(:,&nbsp;k)<br>
2594\]</span></code>
2595
2596and <i>h</i> has size <code>
2597<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
2598.
2599
2600<br>
2601<br>
2602<b><big><a name="4.l" id="4.l">4.l: db</a></big></b>
2603<br>
2604The argument <i>db</i> is a three dimensional array,
2605for <code>
2606<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2607
2608<code>
2609<span style='white-space: nowrap'>&nbsp;\[<br>
2610&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;db(:,:,k)<br>
2611\]</span></code>
2612
2613and <i>db</i> has size <code>
2614<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2615.
2616
2617
2618<br>
2619<br>
2620<b><big><a name="4.m" id="4.m">4.m: dg</a></big></b>
2621<br>
2622The argument <i>dg</i> is a three dimensional array,
2623for <code>
2624<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2625
2626<code>
2627<span style='white-space: nowrap'>&nbsp;\[<br>
2628&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
2629\]</span></code>
2630
2631and <i>dg</i> has size <code>
2632<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2633.
2634The initial state estimate <code>
2635<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2636 does not depend on the value of
2637<code>
2638<span style='white-space: nowrap'>&nbsp;x_0</span></code>
2639, hence <code>
2640<span style='white-space: nowrap'>&nbsp;G_1</span></code>
2641 should be zero.
2642
2643<br>
2644<br>
2645<b><big><a name="4.n" id="4.n">4.n: dh</a></big></b>
2646<br>
2647The argument <i>dh</i> is a three dimensional array,
2648for <code>
2649<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2650
2651<code>
2652<span style='white-space: nowrap'>&nbsp;\[<br>
2653&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
2654\]</span></code>
2655
2656and <i>dh</i> has size <code>
2657<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2658.
2659
2660<br>
2661<br>
2662<b><big><a name="4.o" id="4.o">4.o: qinv</a></big></b>
2663<br>
2664The argument <i>qinv</i> is a three dimensional array,
2665for <code>
2666<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2667
2668<code>
2669<span style='white-space: nowrap'>&nbsp;\[<br>
2670&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,&nbsp;k)<br>
2671\]</span></code>
2672
2673and <i>qinv</i> has size <code>
2674<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2675.
2676The value of <code>
2677<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
2678 is the variance of the initial state
2679estimate <code>
2680<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2681.
2682
2683<br>
2684<br>
2685<b><big><a name="4.p" id="4.p">4.p: rinv</a></big></b>
2686<br>
2687The argument <i>rinv</i> is a three dimensional array,
2688for <code>
2689<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2690
2691<code>
2692<span style='white-space: nowrap'>&nbsp;\[<br>
2693&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,&nbsp;k)<br>
2694\]</span></code>
2695
2696and <i>rinv</i> has size <code>
2697<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
2698.
2699It is ok to signify a missing data value by setting the corresponding
2700row and column of <i>rinv</i> to zero. This also enables use
2701to interpolate the state vector <code>
2702<span style='white-space: nowrap'>&nbsp;x_k</span></code>
2703 to points where
2704there are no measurements.
2705
2706<br>
2707<br>
2708<b><big><a name="4.q" id="4.q">4.q: xOut</a></big></b>
2709<br>
2710The result <i>xOut</i> contains the optimal sequence
2711<code>
2712<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
2713.
2714For <code>
2715<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2716
2717<code>
2718<span style='white-space: nowrap'>&nbsp;\[<br>
2719&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x_k&nbsp;=&nbsp;xOut(:,&nbsp;k)<br>
2720\]</span></code>
2721
2722and <i>xOut</i> is a two dimensional array with size <code>
2723<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
2724.
2725
2726<br>
2727<br>
2728<b><big><a name="4.r" id="4.r">4.r: uOut</a></big></b>
2729<br>
2730The result <i>uOut</i> contains the Lagrange multiplier sequence
2731corresponding to <i>xOut</i>.
2732For <code>
2733<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2734
2735<code>
2736<span style='white-space: nowrap'>&nbsp;\[<br>
2737&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u_k&nbsp;=&nbsp;uOut(:,&nbsp;k)<br>
2738\]</span></code>
2739
2740and <i>uOut</i> is a two dimensional array with size
2741<code>
2742<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;N</span></code>
2743.
2744The pair <i>xOut</i>, <i>uOut</i> satisfy the
2745<a href="#4.e">4.e: <span style='white-space: nowrap'>first&nbsp;order&nbsp;conditions</span></a>
2746.
2747
2748<br>
2749<br>
2750<b><big><a name="4.s" id="4.s">4.s: info</a></big></b>
2751<br>
2752The result <i>info</i> is a matrix with each row corresponding
2753to an iteration of the algorithm.
2754Note that <code><font color="blue">ckbs_affine</font></code> has satisfied the convergence condition if
2755and only if
2756<code><font color="blue"><span style='white-space: nowrap'><br>
2757&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all(&nbsp;</span></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(end,&nbsp;1:3)&nbsp;&lt;=&nbsp;</span></font></code><i><span style='white-space: nowrap'>epsilon</span></i><code><font color="blue"><span style='white-space: nowrap'>&nbsp;)<br>
2758</span></font></code><code><span style='white-space: nowrap'><br>
2759<br>
2760</span></code>We use <code>
2761<span style='white-space: nowrap'>&nbsp;x_k^q</span></code>
2762 (<code>
2763<span style='white-space: nowrap'>&nbsp;u_k^q</span></code>
2764)
2765to denote the state vector (dual vector)
2766for time point <code>
2767<span style='white-space: nowrap'>&nbsp;k</span></code>
2768 and at the end of iteration <code>
2769<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2770
2771We use <code>
2772<span style='white-space: nowrap'>&nbsp;d_k^q</span></code>
2773 for the partial derivative of
2774<code>
2775<span style='white-space: nowrap'>&nbsp;S&nbsp;(&nbsp;x_1^q&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N^q&nbsp;)</span></code>
2776 with respect to <code>
2777<span style='white-space: nowrap'>&nbsp;x_k</span></code>
2778.
2779
2780<br>
2781<br>
2782<b><a name="4.s.a" id="4.s.a">4.s.a: Constraint Bound</a></b>
2783<br>
2784The value <code><font color="blue"></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;1)</span></font></code> is
2785a bound on the constraint functions
2786at the end of iteration <code>
2787<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2788. To be specific
2789<code>
2790<span style='white-space: nowrap'>&nbsp;\[<br>
2791info(q,&nbsp;1)&nbsp;=&nbsp;\max_{i,k}&nbsp;(&nbsp;b_k&nbsp;+&nbsp;B_k&nbsp;*&nbsp;x_k&nbsp;)_i<br>
2792\]&nbsp;</span></code>
2793
2794
2795<br>
2796<br>
2797<b><a name="4.s.b" id="4.s.b">4.s.b: First Order Conditions</a></b>
2798<br>
2799The value <code><font color="blue"></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;2)</span></font></code> is
2800a bound on the partial derivative of the Lagrangian with respect to
2801the state vector sequence
2802at the end of iteration <code>
2803<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2804:
2805<code>
2806<span style='white-space: nowrap'>&nbsp;\[<br>
2807info(q,&nbsp;2)&nbsp;=&nbsp;\max&nbsp;\left[&nbsp;|&nbsp;(&nbsp;B_k^T&nbsp;*&nbsp;u_k&nbsp;+&nbsp;d_k&nbsp;)_j&nbsp;|&nbsp;\right]<br>
2808\]&nbsp;</span></code>
2809
2810where the maximum is with respect to <code>
2811<span style='white-space: nowrap'>&nbsp;j&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;n</span></code>
2812
2813and <code>
2814<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2815.
2816
2817<br>
2818<br>
2819<b><a name="4.s.c" id="4.s.c">4.s.c: Complementarity Conditions</a></b>
2820<br>
2821The value <code><font color="blue"></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;3)</span></font></code> is
2822a bound on the complementarity conditions
2823at the end of iteration <code>
2824<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2825:
2826<code>
2827<span style='white-space: nowrap'>&nbsp;\[<br>
2828info(q,&nbsp;3)&nbsp;=&nbsp;\max&nbsp;\left[&nbsp;|&nbsp;(u_k)_i&nbsp;*&nbsp;(&nbsp;b_k&nbsp;+&nbsp;B_k&nbsp;*&nbsp;x_k)_i&nbsp;|&nbsp;\right]<br>
2829\]&nbsp;</span></code>
2830
2831where the maximum is with respect to
2832<code>
2833<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
2834 and
2835<code>
2836<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2837.
2838
2839
2840<br>
2841<br>
2842<b><a name="4.s.d" id="4.s.d">4.s.d: Step Size</a></b>
2843<br>
2844The value <code><font color="blue"></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(</span></font></code><i><span style='white-space: nowrap'>q</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;4)</span></font></code> is the line search step size used during
2845iteration <code>
2846<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2847.
2848Small step sizes indicate problems with the interior point method
2849used to solve the affine problem
2850(with the exception that <code><font color="blue"></font></code><i><span style='white-space: nowrap'>info</span></i><code><font color="blue"><span style='white-space: nowrap'>(1,&nbsp;4)</span></font></code> is always zero).
2851
2852
2853
2854
2855<br>
2856<br>
2857<b><big><a name="4.t" id="4.t">4.t: Example</a></big></b>
2858<br>
2859The file <a href="#4.1">4.1: <span style='white-space: nowrap'>affine_ok_box.m</span></a>
2860 contains an example and test of
2861<code><font color="blue">ckbs_affine</font></code>.
2862It returns true if <code><font color="blue">ckbs_affine</font></code> passes the test
2863and false otherwise.
2864
2865
2866<hr>Input File: src/ckbs_affine.m
2867
2868<hr>
2869 
2870
2871
2872<center><b><big><big><a name="4.1" id="4.1">4.1: ckbs_affine Box Constrained Smoothing Spline Example and Test</a>
2873</big></big></b></center>
2874<br>
2875<b><big><a name="4.1.a" id="4.1.a">4.1.a: Syntax</a></big></b>
2876
2877<br>
2878<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>ok</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;affine_ok_box(</span></font></code><i><span style='white-space: nowrap'>draw_plot</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
2879
2880<br>
2881<br>
2882<b><big><a name="4.1.b" id="4.1.b">4.1.b: draw_plot</a></big></b>
2883<br>
2884If this argument is true, a plot is drawn showing the results
2885and the <code><font color="blue">nonlinear_ok_box.out</font></code> file is written for use with
2886the program <code><font color="blue">nonlinear_ok_box.r</font></code>.
2887
2888<br>
2889<br>
2890<b><big><a name="4.1.c" id="4.1.c">4.1.c: ok</a></big></b>
2891<br>
2892If the return value <i>ok</i> is true, the test passed,
2893otherwise the test failed.
2894
2895<br>
2896<br>
2897<b><big><a name="4.1.d" id="4.1.d">4.1.d: State Vector</a></big></b>
2898
2899<table><tr><td align='left'  valign='top'>
2900
2901<code>
2902<span style='white-space: nowrap'>&nbsp;x1&nbsp;(t)</span></code>
2903 </td><td align='left'  valign='top'>
2904 derivative of function we are estimating </td></tr><tr><td align='left'  valign='top'>
2905
2906<code>
2907<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
2908 </td><td align='left'  valign='top'>
2909 value of function we are estimating
2910</td></tr>
2911</table>
2912<br>
2913<b><big><a name="4.1.e" id="4.1.e">4.1.e: Measurement</a></big></b>
2914
2915<br>
2916<code>
2917<span style='white-space: nowrap'>&nbsp;z1&nbsp;(t)</span></code>
2918 value of <code>
2919<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
2920 plus noise
2921
2922<br>
2923<br>
2924<b><big><a name="4.1.f" id="4.1.f">4.1.f: Constraint</a></big></b>
2925
2926<br>
2927<code>
2928<span style='white-space: nowrap'>&nbsp;\[<br>
2929&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\begin{array}{c}<br>
2930&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-1&nbsp;\leq&nbsp;x1&nbsp;(t)&nbsp;\leq&nbsp;+1<br>
2931&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
2932&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-1&nbsp;\leq&nbsp;x2&nbsp;(t)&nbsp;\leq&nbsp;+1<br>
2933&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\end{array}<br>
2934\]</span></code>
2935.
2936
2937<br>
2938<br>
2939<b><big><a name="4.1.g" id="4.1.g">4.1.g: Source Code</a></big></b>
2940
2941
2942 <code><font color='blue'><pre style='display:inline'> 
2943function [ok] = affine_ok_box(draw_plot)
2944% --------------------------------------------------------
2945% You can change these parameters
2946N     = 50;        % number of measurement time points
2947dt    = 2*pi / N;  % time between measurement points
2948gamma =  1;        % transition covariance multiplier
2949sigma =  .5;       % standard deviation of measurement noise
2950max_itr = 30;      % maximum number of iterations
2951epsilon = 1e-5;    % convergence criteria
2952h_min   = 0;       % minimum horizontal value in plots
2953h_max   = 7;       % maximum horizontal value in plots
2954v_min   = -2.0;    % minimum vertical value in plots
2955v_max   = +2.0;    % maximum vertical value in plots
2956% ---------------------------------------------------------
2957ok = true;
2958if nargin &lt; 1
2959        draw_plot = false;
2960end
2961%  Define the problem
2962rand('seed', 1234);
2963%
2964% number of constraints per time point
2965ell   = 4;
2966%
2967% number of measurements per time point
2968m     = 1;
2969%
2970% number of state vector components per time point
2971n     = 2;
2972%
2973% simulate the true trajectory and measurement noise
2974t       =  (1 : N) * dt;
2975x1_true = - cos(t);
2976x2_true = - sin(t);
2977x_true  = [ x1_true ; x2_true ];
2978v_true  = sigma * rand(1, N);
2979%
2980% measurement values and model
2981v_true  = sigma * randn(1, N);
2982z       = x2_true + v_true;
2983rk      = sigma * sigma;
2984rinvk   = 1 / rk;
2985rinv    = zeros(m, m, N);
2986h       = zeros(m, N);
2987dh      = zeros(m, n, N);
2988for k = 1 : N
2989        rinv(:, :, k) = rinvk;
2990        h(:, k)       = 0;
2991        dh(:,:, k)    = [ 0 , 1 ];
2992end
2993%
2994% transition model
2995g       = zeros(n, N);
2996dg      = zeros(n, n, N);
2997qinv    = zeros(n, n, N);
2998qk      = gamma * [ dt , dt^2/2 ; dt^2/2 , dt^3/3 ];
2999qinvk   = inv(qk);
3000for k = 2 : N
3001        g(:, k)       = 0;
3002        dg(:,:, k)    = [ 1 , 0 ; dt , 1 ];
3003        qinv(:,:, k)  = qinvk;
3004end
3005%
3006% initial state estimate
3007g(:, 1)      = x_true(:, 1);
3008qinv(:,:, 1) = 100 * eye(2);
3009%
3010% constraints
3011b       = zeros(ell, N);
3012db      = zeros(ell, n, N);
3013for k = 1 : N
3014        %
3015        % b(:, k) + db(:,:, k) * x(:, k) &lt;= 0
3016        b(:, k)    = [ -1 ; -1 ; -1 ; -1 ];
3017        db(:,:, k) = [ -1 , 0 ; 1 , 0 ; 0 , -1 ; 0 , 1 ];
3018end
3019%
3020% -------------------------------------------------------------------------
3021[xOut, uOut, info] = ...
3022        ckbs_affine(max_itr, epsilon, z, b, g, h, db, dg, dh, qinv, rinv);
3023% --------------------------------------------------------------------------
3024ok   = ok &amp; all( info(end, 1:3) &lt;= epsilon);
3025d    = ckbs_sumsq_grad(xOut, z, g, h, dg, dh, qinv, rinv);
3026for k = 1 : N
3027        xk = xOut(:, k);
3028        uk = uOut(:, k);
3029        bk = b(:, k);
3030        Bk = db(:,:, k);
3031        dk = d(:, k);
3032        sk = - bk - Bk * xk;
3033        %
3034        ok = ok &amp; (min(uk) &gt;= 0.);
3035        ok = ok &amp; (max (bk + Bk * xk) &lt;= epsilon);
3036        ok = ok &amp; (max ( abs( Bk' * uk + dk ) ) &lt;= epsilon);
3037        ok = ok &amp; (max ( uk .* sk ) &lt;= epsilon );
3038end
3039if draw_plot
3040        figure(1);
3041        clf
3042        hold on
3043        plot(t', x_true(2,:)', 'r-' );
3044        plot(t', z(1,:)', 'ko' );
3045        plot(t', xOut(2,:)', 'b-' );
3046        plot(t', - ones(N,1), 'b-');
3047        plot(t', ones(N,1), 'b-');
3048        axis([h_min, h_max, v_min, v_max]);
3049        title('Constrained');
3050        hold off
3051        %
3052        % constrained estimate
3053        x_con = xOut;
3054end
3055%
3056% Unconstrained Case
3057b           = zeros(0, N);
3058db          = zeros(0, n, N);
3059% -------------------------------------------------------------------------
3060[xOut, uOut, info] = ...
3061        ckbs_affine(max_itr, epsilon, z, b, g, h, db, dg, dh, qinv, rinv);
3062% --------------------------------------------------------------------------
3063ok   = ok &amp; all( info(end, 1:3) &lt;= epsilon);
3064d    = ckbs_sumsq_grad(xOut, z, g, h, dg, dh, qinv, rinv);
3065for k = 1 : N
3066        xk = xOut(:, k);
3067        dk = d(:, k);
3068        %
3069        ok = ok &amp; (min(dk) &lt;= epsilon);
3070end
3071if draw_plot
3072        figure(2);
3073        clf
3074        hold on
3075        plot(t', x_true(2,:)', 'r-' );
3076        plot(t', z(1,:)', 'ko' );
3077        plot(t', xOut(2,:)', 'b-' );
3078        plot(t', - ones(N,1), 'b-');
3079        plot(t', ones(N,1), 'b-');
3080        axis([h_min, h_max, v_min, v_max]);
3081        title('Unconstrained');
3082        hold off
3083        %
3084        % unconstrained estimate
3085        x_free = xOut;
3086        %
3087        % write out constrained and unconstrained results
3088        [fid, msg] = fopen('affine_ok_box.out', 'wt');
3089        if size(msg, 2) &gt; 0
3090                disp(['affine_ok: ', msg]);
3091        end
3092        %                      123456789012345678901234'
3093        heading =             '       t';
3094        heading = [ heading , ' x2_true  x2_con x2_free' ];
3095        heading = [ heading , '      z1\n'               ];
3096        fprintf(fid, heading);
3097        for k = 1 : N
3098                fprintf(fid,'%8.3f%8.3f%8.3f%8.3f%8.3f\n', ...
3099                        t(k), ...
3100                        x_true(2,k), x_con(2,k), x_free(2,k), ...
3101                        z(1,k) ...
3102                );
3103        end
3104        fclose(fid);
3105end
3106return
3107end
3108</pre></font></code>
3109 
3110
3111<hr>Input File: test/affine_ok_box.m
3112
3113<hr>
3114
3115
3116
3117<center><b><big><big><a name="5" id="5">5: ckbs Utility Functions</a>
3118</big></big></b></center>
3119<br>
3120<b><big><a name="5.a" id="5.a">5.a: Contents</a></big></b>
3121<br>
3122<table>
3123<tr><td><a href="#5.1" target="_top">ckbs_blkdiag_mul:&nbsp;5.1</a></td><td>Packed&nbsp;Block&nbsp;Diagonal&nbsp;Matrix&nbsp;Times&nbsp;a&nbsp;Vector</td></tr><tr><td><a href="#5.2" target="_top">ckbs_blkdiag_mul_t:&nbsp;5.2</a></td><td>Transpose&nbsp;of&nbsp;Packed&nbsp;Block&nbsp;Diagonal&nbsp;Matrix&nbsp;Times&nbsp;a&nbsp;Vector</td></tr><tr><td><a href="#5.3" target="_top">ckbs_sumsq_obj:&nbsp;5.3</a></td><td>Affine&nbsp;Residual&nbsp;Sum&nbsp;of&nbsp;Squares&nbsp;Objective</td></tr><tr><td><a href="#5.4" target="_top">ckbs_sumsq_grad:&nbsp;5.4</a></td><td>Affine&nbsp;Residual&nbsp;Sum&nbsp;of&nbsp;Squares&nbsp;Gradient</td></tr><tr><td><a href="#5.5" target="_top">ckbs_sumsq_hes:&nbsp;5.5</a></td><td>Affine&nbsp;Residual&nbsp;Sum&nbsp;of&nbsp;Squares&nbsp;Hessian</td></tr><tr><td><a href="#5.6" target="_top">ckbs_tridiag_solve:&nbsp;5.6</a></td><td>Symmetric&nbsp;Block&nbsp;Tridiagonal&nbsp;Algorithm</td></tr><tr><td><a href="#5.7" target="_top">ckbs_newton_step:&nbsp;5.7</a></td><td>Affine&nbsp;Constrained&nbsp;Kalman&nbsp;Bucy&nbsp;Smoother&nbsp;Newton&nbsp;Step</td></tr><tr><td><a href="#5.8" target="_top">ckbs_kuhn_tucker:&nbsp;5.8</a></td><td>Compute&nbsp;Residual&nbsp;in&nbsp;Kuhn-Tucker&nbsp;Conditions</td></tr></table>
3124<hr>Input File: omh/utility.omh
3125
3126<hr>
3127<center><b><big><big><a name="5.1" id="5.1">5.1: Packed Block Diagonal Matrix Times a Vector</a>
3128</big></big></b></center>
3129<br>
3130<b><big><a name="5.1.a" id="5.1.a">5.1.a: Syntax</a></big></b>
3131
3132<br>
3133<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>w</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_blkdiag_mul(</span></font></code><i><span style='white-space: nowrap'>Bdia</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>v</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
3134
3135<br>
3136<br>
3137<b><big><a name="5.1.b" id="5.1.b">5.1.b: Purpose</a></big></b>
3138<br>
3139This routine enables one to used the packed form of a block diagonal matrix
3140and returns the matrix times a vector; i.e.,
3141<code>
3142<span style='white-space: nowrap'>&nbsp;\[<br>
3143&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;=&nbsp;B&nbsp;*&nbsp;v<br>
3144\]&nbsp;</span></code>
3145
3146
3147<br>
3148<br>
3149<b><big><a name="5.1.c" id="5.1.c">5.1.c: Bdia</a></big></b>
3150<br>
3151The argument <i>Bdia</i> is an <code>
3152<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3153 array.
3154For <code>
3155<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3156 we define <code>
3157<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
3158 by
3159<code>
3160<span style='white-space: nowrap'>&nbsp;\[<br>
3161&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
3162\]&nbsp;</span></code>
3163
3164
3165<br>
3166<br>
3167<b><big><a name="5.1.d" id="5.1.d">5.1.d: B</a></big></b>
3168<br>
3169The matrix <code>
3170<span style='white-space: nowrap'>&nbsp;B</span></code>
3171 is defined by
3172<code>
3173<span style='white-space: nowrap'>&nbsp;\[<br>
3174B&nbsp;<br>
3175=<br>
3176\left(&nbsp;\begin{array}{cccc}<br>
3177&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_1&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
3178&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
3179&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
3180&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_N&nbsp;<br>
3181\end{array}&nbsp;\right)<br>
3182\]&nbsp;</span></code>
3183
3184
3185<br>
3186<br>
3187<b><big><a name="5.1.e" id="5.1.e">5.1.e: v</a></big></b>
3188<br>
3189The argument <i>v</i> is a column vector of length <code>
3190<span style='white-space: nowrap'>&nbsp;n&nbsp;*&nbsp;N</span></code>
3191.
3192
3193<br>
3194<br>
3195<b><big><a name="5.1.f" id="5.1.f">5.1.f: w</a></big></b>
3196<br>
3197The result <i>w</i> is a column vector of length <code>
3198<span style='white-space: nowrap'>&nbsp;m&nbsp;*&nbsp;N</span></code>
3199.
3200
3201
3202
3203
3204<br>
3205<br>
3206<b><big><a name="5.1.g" id="5.1.g">5.1.g: Example</a></big></b>
3207<br>
3208The file <a href="#5.1.1">5.1.1: <span style='white-space: nowrap'>blkdiag_mul_ok.m</span></a>
3209 contains an example and test of
3210<code><font color="blue">ckbs_blkdiag_mul</font></code>.
3211It returns true if <code><font color="blue">ckbs_blkdiag_mul</font></code> passes the test
3212and false otherwise.
3213
3214
3215<hr>Input File: src/ckbs_blkdiag_mul.m
3216
3217<hr>
3218 
3219
3220
3221<center><b><big><big><a name="5.1.1" id="5.1.1">5.1.1: blkdiag_mul Example and Test</a>
3222</big></big></b></center>
3223<br>
3224<b><big><a name="5.1.1.a" id="5.1.1.a">5.1.1.a: Source Code</a></big></b>
3225
3226 <code><font color='blue'><pre style='display:inline'> 
3227function [ok] = blkdiag_mul_ok()
3228ok = true;
3229% -------------------------------------------------------------
3230% You can change these parameters
3231m    = 2;
3232n    = 3;
3233N    = 2;
3234% -------------------------------------------------------------
3235% Define the problem
3236rand('seed', 123);
3237v     = rand(n * N, 1);
3238Bdiag = zeros(m, n, N);
3239B     = zeros(m * N , n * N);
3240blk_m = 1 : m;
3241blk_n = 1 : n;
3242for k = 1 : N
3243        Bdiag(:, :, k)  = rand(m, n);
3244        B(blk_m, blk_n) = Bdiag(:, :, k);
3245        blk_m           = blk_m + m;
3246        blk_n           = blk_n + n;
3247end
3248% -------------------------------------
3249w     = ckbs_blkdiag_mul(Bdiag, v);
3250% -------------------------------------
3251check = B * v;
3252ok    = ok &amp; ( max(abs(w - check)) &lt; 1e-10 );
3253return
3254end
3255</pre></font></code>
3256 
3257
3258<hr>Input File: test/blkdiag_mul_ok.m
3259
3260<hr>
3261 
3262
3263
3264<center><b><big><big><a name="5.2" id="5.2">5.2: Transpose of Packed Block Diagonal Matrix Times a Vector</a>
3265</big></big></b></center>
3266<br>
3267<b><big><a name="5.2.a" id="5.2.a">5.2.a: Syntax</a></big></b>
3268
3269<br>
3270<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>w</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_blkdiag_mul_t(</span></font></code><i><span style='white-space: nowrap'>Bdia</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>v</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
3271
3272<br>
3273<br>
3274<b><big><a name="5.2.b" id="5.2.b">5.2.b: Purpose</a></big></b>
3275<br>
3276This routine enables one to used the packed form of a block diagonal matrix
3277and returns the transpose of the matrix times a vector; i.e.,
3278<code>
3279<span style='white-space: nowrap'>&nbsp;\[<br>
3280&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;=&nbsp;B^\T&nbsp;*&nbsp;v<br>
3281\]&nbsp;</span></code>
3282
3283
3284<br>
3285<br>
3286<b><big><a name="5.2.c" id="5.2.c">5.2.c: Bdia</a></big></b>
3287<br>
3288The argument <i>Bdia</i> is an <code>
3289<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3290 array.
3291For <code>
3292<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3293 we define <code>
3294<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
3295 by
3296<code>
3297<span style='white-space: nowrap'>&nbsp;\[<br>
3298&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
3299\]&nbsp;</span></code>
3300
3301
3302<br>
3303<br>
3304<b><big><a name="5.2.d" id="5.2.d">5.2.d: B</a></big></b>
3305<br>
3306The matrix <code>
3307<span style='white-space: nowrap'>&nbsp;B</span></code>
3308 is defined by
3309<code>
3310<span style='white-space: nowrap'>&nbsp;\[<br>
3311B&nbsp;<br>
3312=<br>
3313\left(&nbsp;\begin{array}{cccc}<br>
3314&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_1&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
3315&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
3316&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
3317&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_N&nbsp;<br>
3318\end{array}&nbsp;\right)<br>
3319\]&nbsp;</span></code>
3320
3321
3322<br>
3323<br>
3324<b><big><a name="5.2.e" id="5.2.e">5.2.e: v</a></big></b>
3325<br>
3326The argument <i>v</i> is a column vector of length <code>
3327<span style='white-space: nowrap'>&nbsp;m&nbsp;*&nbsp;N</span></code>
3328.
3329
3330<br>
3331<br>
3332<b><big><a name="5.2.f" id="5.2.f">5.2.f: w</a></big></b>
3333<br>
3334The result <i>w</i> is a column vector of length <code>
3335<span style='white-space: nowrap'>&nbsp;n&nbsp;*&nbsp;N</span></code>
3336.
3337
3338
3339
3340<br>
3341<br>
3342<b><big><a name="5.2.g" id="5.2.g">5.2.g: Example</a></big></b>
3343<br>
3344The file <a href="#5.2.1">5.2.1: <span style='white-space: nowrap'>blkdiag_mul_t_ok.m</span></a>
3345 contains an example and test of
3346<code><font color="blue">ckbs_blkdiag_mul_t</font></code>.
3347It returns true if <code><font color="blue">ckbs_blkdiag_mul_t</font></code> passes the test
3348and false otherwise.
3349
3350
3351<hr>Input File: src/ckbs_blkdiag_mul_t.m
3352
3353<hr>
3354 
3355
3356
3357<center><b><big><big><a name="5.2.1" id="5.2.1">5.2.1: blkdiag_mul_t Example and Test</a>
3358</big></big></b></center>
3359<br>
3360<b><big><a name="5.2.1.a" id="5.2.1.a">5.2.1.a: Source Code</a></big></b>
3361
3362 <code><font color='blue'><pre style='display:inline'> 
3363function [ok] = blkdiag_mul_t_ok()
3364ok = true;
3365% -------------------------------------------------------------
3366% You can change these parameters
3367m    = 2;
3368n    = 3;
3369N    = 2;
3370% -------------------------------------------------------------
3371% Define the problem
3372rand('seed', 123);
3373v     = rand(m * N, 1);
3374Bdiag = zeros(m, n, N);
3375B     = zeros(m * N , n * N);
3376blk_m = 1 : m;
3377blk_n = 1 : n;
3378for k = 1 : N
3379        Bdiag(:, :, k)  = rand(m, n);
3380        B(blk_m, blk_n) = Bdiag(:, :, k);
3381        blk_m           = blk_m + m;
3382        blk_n           = blk_n + n;
3383end
3384% -------------------------------------
3385w     = ckbs_blkdiag_mul_t(Bdiag, v);
3386% -------------------------------------
3387check = B' * v;
3388ok    = ok &amp; ( max(abs(w - check)) &lt; 1e-10 );
3389return
3390end
3391</pre></font></code>
3392 
3393
3394<hr>Input File: test/blkdiag_mul_t_ok.m
3395
3396<hr>
3397 
3398
3399
3400<center><b><big><big><a name="5.3" id="5.3">5.3: Affine Residual Sum of Squares Objective</a>
3401</big></big></b></center>
3402<br>
3403<b><big><a name="5.3.a" id="5.3.a">5.3.a: Syntax</a></big></b>
3404
3405<br>
3406<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>obj</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_sumsq_obj(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>z</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>g</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>h</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dg</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dh</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>qinv</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>rinv</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
3407
3408<br>
3409<br>
3410<b><big><a name="5.3.b" id="5.3.b">5.3.b: Purpose</a></big></b>
3411<br>
3412This routine computes the value of the
3413affine Kalman-Bucy smoother residual sum of squares objective function.
3414
3415<br>
3416<br>
3417<b><big><a name="5.3.c" id="5.3.c">5.3.c: Notation</a></big></b>
3418<br>
3419The affine Kalman-Bucy smoother residual sum of squares is defined by
3420<code>
3421<span style='white-space: nowrap'>&nbsp;\[<br>
3422\begin{array}{rcl}<br>
3423S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;\sum_{k=1}^N&nbsp;S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;\\<br>
3424S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
3425\frac{1}{2}&nbsp;<br>
3426(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)^\T&nbsp;*&nbsp;R_k^{-1}&nbsp;*&nbsp;(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)<br>
3427\\<br>
3428&amp;&nbsp;+&nbsp;&amp;<br>
3429\frac{1}{2}&nbsp;<br>
3430(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)^\T&nbsp;*&nbsp;Q_k^{-1}&nbsp;*&nbsp;(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)<br>
3431\\<br>
3432\end{array}<br>
3433\]&nbsp;</span></code>
3434
3435where the matrices <code>
3436<span style='white-space: nowrap'>&nbsp;R_k</span></code>
3437 and <code>
3438<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
3439 are
3440symmetric positive definite and
3441<code>
3442<span style='white-space: nowrap'>&nbsp;x_0</span></code>
3443 is the constant zero.
3444
3445<br>
3446<br>
3447<b><big><a name="5.3.d" id="5.3.d">5.3.d: x</a></big></b>
3448<br>
3449The argument <i>x</i> is a two dimensional array,
3450for <code>
3451<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3452
3453<code>
3454<span style='white-space: nowrap'>&nbsp;\[<br>
3455&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x_k&nbsp;=&nbsp;x(:,&nbsp;k)<br>
3456\]</span></code>
3457
3458and <i>x</i> has size <code>
3459<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3460.
3461
3462<br>
3463<br>
3464<b><big><a name="5.3.e" id="5.3.e">5.3.e: z</a></big></b>
3465<br>
3466The argument <i>z</i> is a two dimensional array,
3467for <code>
3468<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3469
3470<code>
3471<span style='white-space: nowrap'>&nbsp;\[<br>
3472&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z_k&nbsp;=&nbsp;z(:,&nbsp;k)<br>
3473\]</span></code>
3474
3475and <i>z</i> has size <code>
3476<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3477.
3478
3479<br>
3480<br>
3481<b><big><a name="5.3.f" id="5.3.f">5.3.f: g</a></big></b>
3482<br>
3483The argument <i>g</i> is a two dimensional array,
3484for <code>
3485<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3486
3487<code>
3488<span style='white-space: nowrap'>&nbsp;\[<br>
3489&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_k&nbsp;=&nbsp;g(:,&nbsp;k)<br>
3490\]</span></code>
3491
3492and <i>g</i> has size <code>
3493<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3494.
3495
3496<br>
3497<br>
3498<b><big><a name="5.3.g" id="5.3.g">5.3.g: h</a></big></b>
3499<br>
3500The argument <i>h</i> is a two dimensional array,
3501for <code>
3502<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3503
3504<code>
3505<span style='white-space: nowrap'>&nbsp;\[<br>
3506&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h_k&nbsp;=&nbsp;h(:,&nbsp;k)<br>
3507\]</span></code>
3508
3509and <i>h</i> has size <code>
3510<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3511.
3512
3513<br>
3514<br>
3515<b><big><a name="5.3.h" id="5.3.h">5.3.h: dg</a></big></b>
3516<br>
3517The argument <i>dg</i> is a three dimensional array,
3518for <code>
3519<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3520
3521<code>
3522<span style='white-space: nowrap'>&nbsp;\[<br>
3523&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
3524\]</span></code>
3525
3526and <i>dg</i> has size <code>
3527<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3528.
3529
3530<br>
3531<br>
3532<b><big><a name="5.3.i" id="5.3.i">5.3.i: dh</a></big></b>
3533<br>
3534The argument <i>dh</i> is a three dimensional array,
3535for <code>
3536<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3537
3538<code>
3539<span style='white-space: nowrap'>&nbsp;\[<br>
3540&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
3541\]</span></code>
3542
3543and <i>dh</i> has size <code>
3544<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3545.
3546
3547<br>
3548<br>
3549<b><big><a name="5.3.j" id="5.3.j">5.3.j: qinv</a></big></b>
3550<br>
3551The argument <i>qinv</i> is a three dimensional array,
3552for <code>
3553<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3554
3555<code>
3556<span style='white-space: nowrap'>&nbsp;\[<br>
3557&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,&nbsp;k)<br>
3558\]</span></code>
3559
3560and <i>qinv</i> has size <code>
3561<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3562.
3563
3564<br>
3565<br>
3566<b><big><a name="5.3.k" id="5.3.k">5.3.k: rinv</a></big></b>
3567<br>
3568The argument <i>rinv</i> is a three dimensional array,
3569for <code>
3570<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3571
3572<code>
3573<span style='white-space: nowrap'>&nbsp;\[<br>
3574&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,&nbsp;k)<br>
3575\]</span></code>
3576
3577and <i>rinv</i> has size <code>
3578<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
3579.
3580
3581<br>
3582<br>
3583<b><big><a name="5.3.l" id="5.3.l">5.3.l: obj</a></big></b>
3584<br>
3585The result <i>obj</i> is a scalar given by
3586<code>
3587<span style='white-space: nowrap'>&nbsp;\[<br>
3588&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj&nbsp;=&nbsp;S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)<br>
3589\]&nbsp;</span></code>
3590
3591
3592
3593
3594<br>
3595<br>
3596<b><big><a name="5.3.m" id="5.3.m">5.3.m: Example</a></big></b>
3597<br>
3598The file <a href="#5.3.1">5.3.1: <span style='white-space: nowrap'>sumsq_obj_ok.m</span></a>
3599 contains an example and test of
3600<code><font color="blue">ckbs_sumsq_obj</font></code>.
3601It returns true if <code><font color="blue">ckbs_sumsq_obj</font></code> passes the test
3602and false otherwise.
3603
3604
3605<hr>Input File: src/ckbs_sumsq_obj.m
3606
3607<hr>
3608 
3609
3610
3611<center><b><big><big><a name="5.3.1" id="5.3.1">5.3.1: ckbs_sumsq_obj Example and Test</a>
3612</big></big></b></center>
3613<br>
3614<b><big><a name="5.3.1.a" id="5.3.1.a">5.3.1.a: Source Code</a></big></b>
3615
3616 <code><font color='blue'><pre style='display:inline'> 
3617function [ok] = sumsq_obj_ok()
3618ok = true;
3619% --------------------------------------------------------
3620% You can change these parameters
3621m    = 1;   % number of measurements per time point
3622n    = 2;   % number of state vector components per time point
3623N    = 3;   % number of time points
3624% ---------------------------------------------------------
3625%  Define the problem
3626rand('seed', 123);
3627x    = rand(n, N);
3628z    = rand(m, N);
3629h    = rand(m, N);
3630g    = rand(n, N);
3631dh   = zeros(m, n, N);
3632dg   = zeros(n, n, N);
3633qinv = zeros(n, n, N);
3634rinv = zeros(m, m, N);
3635for k = 1 : N
3636        dh(:, :, k)   = rand(m, n);
3637        dg(:, :, k)   = rand(n, n);
3638        tmp           = rand(m, m);
3639        rinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(m);
3640        tmp           = rand(n, n);
3641        qinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(n);
3642end
3643% ---------------------------------------------------------
3644% Compute the Objective using ckbs_sumsq_obj
3645obj  = ckbs_sumsq_obj(x, z, g, h, dg, dh, qinv, rinv);
3646% ---------------------------------------------------------
3647sumsq = 0;
3648xk    = zeros(n, 1);
3649for k = 1 : N
3650        xkm   = xk;
3651        xk    = x(:, k);
3652        xres  = xk      - g(:, k) - dg(:,:, k) * xkm;
3653        zres  = z(:, k) - h(:, k) - dh(:,:, k) * xk;
3654        sumsq = sumsq + xres' * qinv(:,:, k) * xres;
3655        sumsq = sumsq + zres' * rinv(:,:, k) * zres;
3656end
3657ok = ok &amp; ( abs(obj - sumsq/2) &lt; 1e-10 );
3658return
3659end
3660</pre></font></code>
3661 
3662
3663<hr>Input File: test/sumsq_obj_ok.m
3664
3665<hr>
3666 
3667
3668
3669<center><b><big><big><a name="5.4" id="5.4">5.4: Affine Residual Sum of Squares Gradient</a>
3670</big></big></b></center>
3671<br>
3672<b><big><a name="5.4.a" id="5.4.a">5.4.a: Syntax</a></big></b>
3673
3674<br>
3675<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>grad</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_sumsq_grad(</span></font></code><i><span style='white-space: nowrap'>x</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>z</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>g</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>h</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dg</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dh</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>qinv</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>rinv</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
3676
3677<br>
3678<br>
3679<b><big><a name="5.4.b" id="5.4.b">5.4.b: Purpose</a></big></b>
3680<br>
3681This computes the gradient of the
3682of the affine Kalman-Bucy smoother residual sum of squares.
3683
3684<br>
3685<br>
3686<b><big><a name="5.4.c" id="5.4.c">5.4.c: Notation</a></big></b>
3687<br>
3688The affine Kalman-Bucy smoother residual sum of squares is defined by
3689<code>
3690<span style='white-space: nowrap'>&nbsp;\[<br>
3691\begin{array}{rcl}<br>
3692S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;\sum_{k=1}^N&nbsp;S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;\\<br>
3693S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
3694\frac{1}{2}&nbsp;<br>
3695(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)^\T&nbsp;*&nbsp;R_k^{-1}&nbsp;*&nbsp;(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)<br>
3696\\<br>
3697&amp;&nbsp;+&nbsp;&amp;<br>
3698\frac{1}{2}&nbsp;<br>
3699(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)^\T&nbsp;*&nbsp;Q_k^{-1}&nbsp;*&nbsp;(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)<br>
3700\end{array}<br>
3701\]&nbsp;</span></code>
3702
3703where the matrices <code>
3704<span style='white-space: nowrap'>&nbsp;R_k</span></code>
3705 and <code>
3706<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
3707 are
3708symmetric positive definite and
3709<code>
3710<span style='white-space: nowrap'>&nbsp;x_0</span></code>
3711 is the constant zero.
3712
3713<br>
3714<br>
3715<b><big><a name="5.4.d" id="5.4.d">5.4.d: Gradient</a></big></b>
3716<br>
3717We define <code>
3718<span style='white-space: nowrap'>&nbsp;Q_{N+1}</span></code>
3719 to be the <code>
3720<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
3721 identity
3722matrix and <code>
3723<span style='white-space: nowrap'>&nbsp;G_{N+1}</span></code>
3724 to be zero,
3725<code>
3726<span style='white-space: nowrap'>&nbsp;\[<br>
3727\begin{array}{rcl}<br>
3728\nabla_k&nbsp;S_k^{(1)}&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;<br>
3729&amp;&nbsp;=&nbsp;&amp;&nbsp;&nbsp;H_k^\T&nbsp;*&nbsp;R_k^{-1}&nbsp;*&nbsp;(&nbsp;h_k&nbsp;+&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;-&nbsp;z_k&nbsp;)&nbsp;<br>
3730&nbsp;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;*&nbsp;(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)<br>
3731\\<br>
3732\nabla_k&nbsp;S_{k+1}^{(1)}&nbsp;(&nbsp;x_{k+1}&nbsp;,&nbsp;x_k&nbsp;)&nbsp;<br>
3733&amp;&nbsp;=&nbsp;&amp;&nbsp;G_{k+1}^\T&nbsp;*&nbsp;Q_{k+1}^{-1}&nbsp;*&nbsp;(&nbsp;g_{k+1}&nbsp;+&nbsp;G_{k+1}&nbsp;*&nbsp;x_k&nbsp;&nbsp;-&nbsp;x_{k+1}&nbsp;)<br>
3734\end{array}<br>
3735\]&nbsp;</span></code>
3736
3737It follows that the gradient of the
3738affine Kalman-Bucy smoother residual sum of squares is
3739<code>
3740<span style='white-space: nowrap'>&nbsp;\[<br>
3741\begin{array}{rcl}<br>
3742\nabla&nbsp;S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;<br>
3743&amp;&nbsp;=&nbsp;&amp;<br>
3744\left(&nbsp;\begin{array}{c}<br>
3745&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d_1&nbsp;\\&nbsp;\vdots&nbsp;\\&nbsp;d_N<br>
3746\end{array}&nbsp;\right)<br>
3747\\<br>
3748d_k&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;\nabla_k&nbsp;S_k^{(1)}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;<br>
3749&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;&nbsp;\nabla_k&nbsp;S_{k+1}^{(1)}&nbsp;(&nbsp;x_{k+1}&nbsp;,&nbsp;x_k&nbsp;)<br>
3750\end{array}<br>
3751\]&nbsp;</span></code>
3752
3753where <code>
3754<span style='white-space: nowrap'>&nbsp;S_{N+1}&nbsp;(&nbsp;x_{N+1}&nbsp;,&nbsp;x_N&nbsp;)</span></code>
3755 is defined as
3756identically zero.
3757
3758<br>
3759<br>
3760<b><big><a name="5.4.e" id="5.4.e">5.4.e: x</a></big></b>
3761<br>
3762The argument <i>x</i> is a two dimensional array,
3763for <code>
3764<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3765
3766<code>
3767<span style='white-space: nowrap'>&nbsp;\[<br>
3768&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x_k&nbsp;=&nbsp;x(:,&nbsp;k)<br>
3769\]</span></code>
3770
3771and <i>x</i> has size <code>
3772<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3773.
3774
3775<br>
3776<br>
3777<b><big><a name="5.4.f" id="5.4.f">5.4.f: z</a></big></b>
3778<br>
3779The argument <i>z</i> is a two dimensional array,
3780for <code>
3781<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3782
3783<code>
3784<span style='white-space: nowrap'>&nbsp;\[<br>
3785&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z_k&nbsp;=&nbsp;z(:,&nbsp;k)<br>
3786\]</span></code>
3787
3788and <i>z</i> has size <code>
3789<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3790.
3791
3792<br>
3793<br>
3794<b><big><a name="5.4.g" id="5.4.g">5.4.g: g</a></big></b>
3795<br>
3796The argument <i>g</i> is a two dimensional array,
3797for <code>
3798<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3799
3800<code>
3801<span style='white-space: nowrap'>&nbsp;\[<br>
3802&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_k&nbsp;=&nbsp;g(:,&nbsp;k)<br>
3803\]</span></code>
3804
3805and <i>g</i> has size <code>
3806<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3807.
3808
3809<br>
3810<br>
3811<b><big><a name="5.4.h" id="5.4.h">5.4.h: h</a></big></b>
3812<br>
3813The argument <i>h</i> is a two dimensional array,
3814for <code>
3815<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3816
3817<code>
3818<span style='white-space: nowrap'>&nbsp;\[<br>
3819&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h_k&nbsp;=&nbsp;h(:,&nbsp;k)<br>
3820\]</span></code>
3821
3822and <i>h</i> has size <code>
3823<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3824.
3825
3826<br>
3827<br>
3828<b><big><a name="5.4.i" id="5.4.i">5.4.i: dg</a></big></b>
3829<br>
3830The argument <i>dg</i> is a three dimensional array,
3831for <code>
3832<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3833
3834<code>
3835<span style='white-space: nowrap'>&nbsp;\[<br>
3836&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
3837\]</span></code>
3838
3839and <i>dg</i> has size <code>
3840<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3841.
3842
3843<br>
3844<br>
3845<b><big><a name="5.4.j" id="5.4.j">5.4.j: dh</a></big></b>
3846<br>
3847The argument <i>dh</i> is a three dimensional array,
3848for <code>
3849<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3850
3851<code>
3852<span style='white-space: nowrap'>&nbsp;\[<br>
3853&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
3854\]</span></code>
3855
3856and <i>dh</i> has size <code>
3857<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3858.
3859
3860<br>
3861<br>
3862<b><big><a name="5.4.k" id="5.4.k">5.4.k: qinv</a></big></b>
3863<br>
3864The argument <i>qinv</i> is a three dimensional array,
3865for <code>
3866<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3867
3868<code>
3869<span style='white-space: nowrap'>&nbsp;\[<br>
3870&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,k)<br>
3871\]</span></code>
3872
3873and <i>qinv</i> has size <code>
3874<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3875.
3876
3877<br>
3878<br>
3879<b><big><a name="5.4.l" id="5.4.l">5.4.l: rinv</a></big></b>
3880<br>
3881The argument <i>rinv</i> is a three dimensional array,
3882for <code>
3883<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3884
3885<code>
3886<span style='white-space: nowrap'>&nbsp;\[<br>
3887&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,k)<br>
3888\]</span></code>
3889
3890and <i>rinv</i> has size <code>
3891<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
3892.
3893
3894<br>
3895<br>
3896<b><big><a name="5.4.m" id="5.4.m">5.4.m: grad</a></big></b>
3897<br>
3898The result <i>grad</i> is a two dimensional array,
3899for <code>
3900<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3901
3902<code>
3903<span style='white-space: nowrap'>&nbsp;\[<br>
3904&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d_k&nbsp;=&nbsp;grad(:,&nbsp;k)<br>
3905\]</span></code>
3906
3907and <i>grad</i> has size <code>
3908<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3909.
3910
3911
3912
3913<br>
3914<br>
3915<b><big><a name="5.4.n" id="5.4.n">5.4.n: Example</a></big></b>
3916<br>
3917The file <a href="#5.4.1">5.4.1: <span style='white-space: nowrap'>sumsq_grad_ok.m</span></a>
3918 contains an example and test of
3919<code><font color="blue">ckbs_sumsq_grad</font></code>.
3920It returns true if <code><font color="blue">ckbs_sumsq_grad</font></code> passes the test
3921and false otherwise.
3922
3923
3924<hr>Input File: src/ckbs_sumsq_grad.m
3925
3926<hr>
3927 
3928
3929
3930<center><b><big><big><a name="5.4.1" id="5.4.1">5.4.1: ckbs_sumsq_grad Example and Test</a>
3931</big></big></b></center>
3932<br>
3933<b><big><a name="5.4.1.a" id="5.4.1.a">5.4.1.a: Source Code</a></big></b>
3934
3935 <code><font color='blue'><pre style='display:inline'> 
3936function [ok] = sumsq_grad_ok()
3937ok = true;
3938% --------------------------------------------------------
3939% You can change these parameters
3940m    = 1;   % number of measurements per time point
3941n    = 2;   % number of state vector components per time point
3942N    = 3;   % number of time points
3943% ---------------------------------------------------------
3944%  Define the problem
3945rand('seed', 123);
3946x    = rand(n, N);
3947z    = rand(m, N);
3948h    = rand(m, N);
3949g    = rand(n, N);
3950dg   = zeros(n, n, N);
3951dh   = zeros(m, n, N);
3952qinv = zeros(n, n, N);
3953rinv = zeros(m, m, N);
3954for k = 1 : N
3955        dh(:, :, k)   = rand(m, n);
3956        dg(:, :, k)   = rand(n, n);
3957        tmp           = rand(m, m);
3958        rinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(m);
3959        tmp           = rand(n, n);
3960        qinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(n);
3961end
3962% ---------------------------------------------------------
3963% Compute the gradient using ckbs_sumsq_grad
3964grad = ckbs_sumsq_grad(x, z, g, h, dg, dh, qinv, rinv);
3965% ---------------------------------------------------------
3966% Use finite differences to check gradient
3967step   = 1;
3968for k  = 1 : N
3969for i  = 1 : n
3970        % Check second partial w.r.t x(i,k)
3971        xm        = x;
3972        xm(i, k)  = xm(i, k) - step;
3973        Sm        = ckbs_sumsq_obj(xm, z, g, h, dg, dh, qinv, rinv);
3974        %
3975        xp        = x;
3976        xp(i, k)  = xp(i, k) + step;
3977        Sp        = ckbs_sumsq_obj(xp, z, g, h, dg, dh, qinv, rinv);
3978        %
3979        check  = (Sp - Sm) / ( 2 * step);
3980        diff   = grad(i, k) - check;
3981        ok     = ok &amp; ( abs(diff) &lt; 1e-10 );
3982end
3983end
3984return
3985end
3986</pre></font></code>
3987 
3988
3989<hr>Input File: test/sumsq_grad_ok.m
3990
3991<hr>
3992 
3993
3994
3995<center><b><big><big><a name="5.5" id="5.5">5.5: Affine Residual Sum of Squares Hessian</a>
3996</big></big></b></center>
3997<br>
3998<b><big><a name="5.5.a" id="5.5.a">5.5.a: Syntax</a></big></b>
3999
4000<br>
4001<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>D</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>A</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_sumsq_hes(</span></font></code><i><span style='white-space: nowrap'>dg</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dh</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>qinv</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>rinv</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
4002
4003<br>
4004<br>
4005<b><big><a name="5.5.b" id="5.5.b">5.5.b: Purpose</a></big></b>
4006<br>
4007This routine returns the diagonal and off diagonal blocks corresponding to
4008the Hessian of the affine Kalman-Bucy smoother residual sum of squares.
4009
4010<br>
4011<br>
4012<b><big><a name="5.5.c" id="5.5.c">5.5.c: Notation</a></big></b>
4013<br>
4014The affine Kalman-Bucy smoother residual sum of squares is defined by
4015<code>
4016<span style='white-space: nowrap'>&nbsp;\[<br>
4017\begin{array}{rcl}<br>
4018S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;\sum_{k=1}^N&nbsp;S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;\\<br>
4019S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
4020\frac{1}{2}&nbsp;<br>
4021(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)^\T&nbsp;*&nbsp;R_k^{-1}&nbsp;*&nbsp;(&nbsp;z_k&nbsp;-&nbsp;h_k&nbsp;-&nbsp;H_k&nbsp;*&nbsp;x_k&nbsp;)<br>
4022\\<br>
4023&amp;&nbsp;+&nbsp;&amp;<br>
4024\frac{1}{2}&nbsp;<br>
4025(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)^\T&nbsp;*&nbsp;Q_k^{-1}&nbsp;*&nbsp;(&nbsp;x_k&nbsp;-&nbsp;g_k&nbsp;-&nbsp;G_k&nbsp;*&nbsp;x_{k-1}&nbsp;)<br>
4026\end{array}<br>
4027\]&nbsp;</span></code>
4028
4029where the matrices <code>
4030<span style='white-space: nowrap'>&nbsp;R_k</span></code>
4031 and <code>
4032<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
4033 are
4034symmetric positive definite and
4035<code>
4036<span style='white-space: nowrap'>&nbsp;x_0</span></code>
4037 is the constant zero.
4038
4039<br>
4040<br>
4041<b><big><a name="5.5.d" id="5.5.d">5.5.d: Hessian</a></big></b>
4042<br>
4043If we define <code>
4044<span style='white-space: nowrap'>&nbsp;Q_{N+1}</span></code>
4045 to be the <code>
4046<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
4047 identity
4048matrix and <code>
4049<span style='white-space: nowrap'>&nbsp;G_{N+1}</span></code>
4050 to be zero,
4051the Hessian of the
4052affine Kalman-Bucy smoother residual sum of squares is
4053<code>
4054<span style='white-space: nowrap'>&nbsp;\[<br>
4055\begin{array}{rcl}<br>
4056S^{(2)}&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;<br>
4057\left(&nbsp;\begin{array}{cccc}<br>
4058D_1&nbsp;&amp;&nbsp;A_2^\T&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4059A_2&nbsp;&amp;&nbsp;D_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;A_3^\T&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
40600&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4061&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;A_N&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;D_N&nbsp;<br>
4062\end{array}&nbsp;\right)<br>
4063\\<br>
4064D_k&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;H_k^\T&nbsp;*&nbsp;R_k^{-1}&nbsp;*&nbsp;H_k&nbsp;+&nbsp;Q_k^{-1}&nbsp;<br>
4065&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;G_{k+1}^\T&nbsp;*&nbsp;Q_{k+1}^{-1}&nbsp;*&nbsp;G_{k+1}&nbsp;<br>
4066\\<br>
4067A_k&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;-&nbsp;Q_k^{-1}&nbsp;*&nbsp;G_k<br>
4068\end{array}<br>
4069\]&nbsp;</span></code>
4070
4071
4072<br>
4073<br>
4074<b><big><a name="5.5.e" id="5.5.e">5.5.e: dg</a></big></b>
4075<br>
4076The argument <i>dg</i> is a three dimensional array,
4077for <code>
4078<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4079
4080<code>
4081<span style='white-space: nowrap'>&nbsp;\[<br>
4082&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
4083\]</span></code>
4084
4085and <i>dg</i> has size <code>
4086<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4087.
4088
4089<br>
4090<br>
4091<b><big><a name="5.5.f" id="5.5.f">5.5.f: dh</a></big></b>
4092<br>
4093The argument <i>dh</i> is a three dimensional array,
4094for <code>
4095<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4096
4097<code>
4098<span style='white-space: nowrap'>&nbsp;\[<br>
4099&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
4100\]</span></code>
4101
4102and <i>dh</i> has size <code>
4103<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4104.
4105
4106<br>
4107<br>
4108<b><big><a name="5.5.g" id="5.5.g">5.5.g: qinv</a></big></b>
4109<br>
4110The argument <i>qinv</i> is a three dimensional array,
4111for <code>
4112<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4113
4114<code>
4115<span style='white-space: nowrap'>&nbsp;\[<br>
4116&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,k)<br>
4117\]</span></code>
4118
4119and <i>qinv</i> has size <code>
4120<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4121.
4122
4123<br>
4124<br>
4125<b><big><a name="5.5.h" id="5.5.h">5.5.h: rinv</a></big></b>
4126<br>
4127The argument <i>rinv</i> is a three dimensional array,
4128for <code>
4129<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4130
4131<code>
4132<span style='white-space: nowrap'>&nbsp;\[<br>
4133&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,k)<br>
4134\]</span></code>
4135
4136and <i>rinv</i> has size <code>
4137<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
4138.
4139
4140<br>
4141<br>
4142<b><big><a name="5.5.i" id="5.5.i">5.5.i: D</a></big></b>
4143<br>
4144The result <i>D</i> is a three dimensional array,
4145for <code>
4146<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4147
4148<code>
4149<span style='white-space: nowrap'>&nbsp;\[<br>
4150&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D_k&nbsp;=&nbsp;D(:,:,k)<br>
4151\]</span></code>
4152
4153and <i>D</i> has size <code>
4154<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4155.
4156
4157<br>
4158<br>
4159<b><big><a name="5.5.j" id="5.5.j">5.5.j: A</a></big></b>
4160<br>
4161The result <i>A</i> is a three dimensional array,
4162for <code>
4163<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;2&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4164
4165<code>
4166<span style='white-space: nowrap'>&nbsp;\[<br>
4167&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A_k&nbsp;=&nbsp;A(:,:,k)<br>
4168\]</span></code>
4169
4170and <i>A</i> has size <code>
4171<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4172.
4173
4174
4175
4176
4177<br>
4178<br>
4179<b><big><a name="5.5.k" id="5.5.k">5.5.k: Example</a></big></b>
4180<br>
4181The file <a href="#5.5.1">5.5.1: <span style='white-space: nowrap'>sumsq_hes_ok.m</span></a>
4182 contains an example and test of
4183<code><font color="blue">ckbs_sumsq_hes</font></code>.
4184It returns true if <code><font color="blue">ckbs_sumsq_hes</font></code> passes the test
4185and false otherwise.
4186
4187
4188<hr>Input File: src/ckbs_sumsq_hes.m
4189
4190<hr>
4191 
4192
4193
4194<center><b><big><big><a name="5.5.1" id="5.5.1">5.5.1: ckbs_sumsq_hes Example and Test</a>
4195</big></big></b></center>
4196<br>
4197<b><big><a name="5.5.1.a" id="5.5.1.a">5.5.1.a: Source Code</a></big></b>
4198
4199 <code><font color='blue'><pre style='display:inline'> 
4200function [ok] = sumsq_hes_ok()
4201ok = true;
4202% --------------------------------------------------------
4203% You can change these parameters
4204m    = 1;   % number of measurements per time point
4205n    = 2;   % number of state vector components per time point
4206N    = 3;   % number of time points
4207% ---------------------------------------------------------
4208%  Define the problem
4209rand('seed', 123);
4210dg   = zeros(n, n, N);
4211dh   = zeros(m, n, N);
4212qinv = zeros(n, n, N);
4213rinv = zeros(m, m, N);
4214for k = 1 : N
4215        dh(:, :, k)   = rand(m, n);
4216        dg(:, :, k)   = rand(n, n);
4217        tmp           = rand(m, m);
4218        rinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(m);
4219        tmp           = rand(n, n);
4220        qinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(n);
4221end
4222% ---------------------------------------------------------
4223% Compute the Hessian using ckbs_sumsq_hes
4224[D, A] = ckbs_sumsq_hes(dg, dh, qinv, rinv);
4225% ---------------------------------------------------------
4226H    = zeros(n * N , n * N );
4227for k = 1 : N
4228        index           = (k - 1) * n + (1 : n);
4229        H(index, index) = D(:, :, k);
4230        if k &gt; 1
4231                H(index - n, index) = A(:, :, k)';
4232                H(index, index - n) = A(:, :, k);
4233        end
4234end
4235%
4236% Use finite differences to check Hessian
4237x    = rand(n, N);
4238z    = rand(m, N);
4239h    = rand(m, N);
4240g    = rand(n, N);
4241%
4242step   = 1;
4243for k = 1 : N
4244        for i = 1 : n
4245                % Check second partial w.r.t x(i, k)
4246                xm       = x;
4247                xm(i, k) = xm(i, k) - step;
4248                gradm = ckbs_sumsq_grad(xm, z, g, h, dg, dh, qinv, rinv);
4249                %
4250                xp       = x;
4251                xp(i, k) = xp(i, k) + step;
4252                gradp = ckbs_sumsq_grad(xp, z, g, h, dg, dh, qinv, rinv);
4253                %
4254                check  = (gradp - gradm) / ( 2 * step );
4255                for k1 = 1 : N
4256                        for i1 = 1 : n
4257                                value = H(i + (k-1)*n, i1 + (k1-1)*n);
4258                                diff  = check(i1, k1) - value;
4259                                ok     = ok &amp; ( abs(diff) &lt; 1e-10 );
4260                        end
4261                end
4262        end
4263end
4264return
4265end
4266</pre></font></code>
4267 
4268
4269<hr>Input File: test/sumsq_hes_ok.m
4270
4271<hr>
4272 
4273
4274
4275<center><b><big><big><a name="5.6" id="5.6">5.6: Symmetric Block Tridiagonal Algorithm</a>
4276</big></big></b></center>
4277<br>
4278<b><big><a name="5.6.a" id="5.6.a">5.6.a: Syntax</a></big></b>
4279
4280<br>
4281
4282<code><font color="blue"><span style='white-space: nowrap'>[</span></font><i><font color="black"><span style='white-space: nowrap'>e</span></font></i><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font><i><font color="black"><span style='white-space: nowrap'>lambda</span></font></i><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_tridiag_solve(</span></font><i><font color="black"><span style='white-space: nowrap'>b</span></font></i><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font><i><font color="black"><span style='white-space: nowrap'>c</span></font></i><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
4283
4284
4285<br>
4286<br>
4287<b><big><a name="5.6.b" id="5.6.b">5.6.b: Purpose</a></big></b>
4288<br>
4289This routine solves the following linear system of equations for
4290<code>
4291<span style='white-space: nowrap'>&nbsp;e</span></code>
4292:
4293<code>
4294<span style='white-space: nowrap'>&nbsp;\[<br>
4295&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;*&nbsp;e&nbsp;=&nbsp;r<br>
4296\]&nbsp;</span></code>
4297
4298where the symmetric block tridiagonal matrix <code>
4299<span style='white-space: nowrap'>&nbsp;A</span></code>
4300 is defined by
4301<code>
4302<span style='white-space: nowrap'>&nbsp;\[<br>
4303A&nbsp;=<br>
4304\left(&nbsp;\begin{array}{ccccc}<br>
4305b_1&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;c_2^\T&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\cdots&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4306c_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;b_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;c_3^\T&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\vdots&nbsp;\\<br>
4307\vdots&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
43080&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\cdots&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;b_N&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;c_N<br>
4309\end{array}&nbsp;\right)<br>
4310\]&nbsp;</span></code>
4311
4312
4313<br>
4314<br>
4315<b><big><a name="5.6.c" id="5.6.c">5.6.c: b</a></big></b>
4316<br>
4317The argument
4318<code><i><font color="black"><span style='white-space: nowrap'>b</span></font></i></code>
4319 is a three dimensional array,
4320for <code>
4321<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4322
4323<code>
4324<span style='white-space: nowrap'>&nbsp;\[<br>
4325&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b_k&nbsp;=&nbsp;b(:,:,k)<br>
4326\]</span></code>
4327
4328and
4329<code><i><font color="black"><span style='white-space: nowrap'>b</span></font></i></code>
4330 has size <code>
4331<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4332.
4333
4334<br>
4335<br>
4336<b><big><a name="5.6.d" id="5.6.d">5.6.d: c</a></big></b>
4337<br>
4338The argument
4339<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i></code>
4340 is a three dimensional array,
4341for <code>
4342<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;2&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4343
4344<code>
4345<span style='white-space: nowrap'>&nbsp;\[<br>
4346&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c_k&nbsp;=&nbsp;c(:,:,k)<br>
4347\]</span></code>
4348
4349and
4350<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i></code>
4351 has size <code>
4352<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4353.
4354
4355<br>
4356<br>
4357<b><big><a name="5.6.e" id="5.6.e">5.6.e: r</a></big></b>
4358<br>
4359The argument
4360<code><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
4361 is an <code>
4362<span style='white-space: nowrap'>&nbsp;(n&nbsp;*&nbsp;N)&nbsp;\times&nbsp;m</span></code>
4363 matrix.
4364
4365<br>
4366<br>
4367<b><big><a name="5.6.f" id="5.6.f">5.6.f: e</a></big></b>
4368<br>
4369The result
4370<code><i><font color="black"><span style='white-space: nowrap'>e</span></font></i></code>
4371 is an <code>
4372<span style='white-space: nowrap'>&nbsp;(n&nbsp;*&nbsp;N)&nbsp;\times&nbsp;m</span></code>
4373 matrix.
4374
4375<br>
4376<br>
4377<b><big><a name="5.6.g" id="5.6.g">5.6.g: lambda</a></big></b>
4378<br>
4379The result
4380<code><i><font color="black"><span style='white-space: nowrap'>lambda</span></font></i></code>
4381 is a scalar equal to the
4382logarithm of the determinant of <code>
4383<span style='white-space: nowrap'>&nbsp;A</span></code>
4384.
4385
4386<br>
4387<br>
4388<b><big><a name="5.6.h" id="5.6.h">5.6.h: Reference</a></big></b>
4389
4390<i><br>
4391The marginal likelihood for parameters in a discrete
4392Gauss Markov process</i>,
4393Bradley M. Bell,
4394IEEE Transactions on Signal Processing,
4395Vol. 48,
4396No. 3,
4397March 2000.
4398
4399<br>
4400<br>
4401<b><big><a name="5.6.i" id="5.6.i">5.6.i: Lemma</a></big></b>
4402<br>
4403The following result is proven as Lemma 6 of the reference above:
4404Suppose that for <code>
4405<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4406
4407<code>
4408<span style='white-space: nowrap'>&nbsp;\[<br>
4409\begin{array}{rcl}<br>
4410&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b_k&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;u_k&nbsp;+&nbsp;q_{k-1}^{-1}&nbsp;+&nbsp;a_k&nbsp;*&nbsp;q_k^{-1}&nbsp;*&nbsp;a_k^\T&nbsp;&nbsp;\\<br>
4411&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c_k&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;q_{k-1}^{-1}&nbsp;*&nbsp;a_k^\T<br>
4412\end{array}<br>
4413\]&nbsp;</span></code>
4414
4415where <code>
4416<span style='white-space: nowrap'>&nbsp;u_k</span></code>
4417 is symmetric positive semi-definite and
4418<code>
4419<span style='white-space: nowrap'>&nbsp;q_k</span></code>
4420 is symmetric positive definite.
4421It follows that the algorithm used by <code><font color="blue">ckbs_tridiag_solve</font></code>
4422is well conditioned and will not try to invert singular matrices.
4423
4424
4425
4426<br>
4427<br>
4428<b><big><a name="5.6.j" id="5.6.j">5.6.j: Example</a></big></b>
4429<br>
4430The file <a href="#5.6.1">5.6.1: <span style='white-space: nowrap'>tridiag_solve_ok.m</span></a>
4431 contains an example and test of
4432<code><font color="blue">ckbs_tridiag_solve</font></code>.
4433It returns true if <code><font color="blue">ckbs_tridiag_solve</font></code> passes the test
4434and false otherwise.
4435
4436
4437<hr>Input File: src/ckbs_tridiag_solve.m
4438
4439<hr>
4440 
4441
4442
4443<center><b><big><big><a name="5.6.1" id="5.6.1">5.6.1: ckbs_tridiag_solve Example and Test</a>
4444</big></big></b></center>
4445<br>
4446<b><big><a name="5.6.1.a" id="5.6.1.a">5.6.1.a: Source Code</a></big></b>
4447
4448 <code><font color='blue'><pre style='display:inline'> 
4449function [ok] = tridiag_solve_ok()
4450ok = true;
4451m  = 2;
4452n  = 3;
4453N  = 4;
4454% case where uk = 0, qk = I, and ak is random
4455rand('seed', 123);
4456a = rand(n, n, N);
4457r = rand(n * N, m);
4458c = zeros(n, n, N);
4459for k = 1 : N
4460        ak         = a(:, :, k);
4461        b(:, :, k) = 2 * eye(n) + ak * ak';
4462        c(:, :, k) = ak';
4463end 
4464% ----------------------------------------
4465[e, lambda] = ckbs_tridiag_solve(b, c, r);
4466% ----------------------------------------
4467%
4468% check equation corresponding to first row
4469blk_n = 1 : n;
4470lhs   = b(:, :, 1) * e(blk_n, :) + c(:, :, 2)' * e(blk_n + n, :);
4471ok    = ok &amp; ( max( max( abs( lhs - r(blk_n, :) ) ) ) &lt; 1e-10 );
4472%
4473% check equation corresponding to last row
4474blk_n = (N-1) * n + (1 : n);
4475lhs   = c(:, :, N) * e(blk_n - n, :) + b(:, :, N) * e(blk_n, :);
4476ok    = ok &amp; ( max( max( abs( lhs - r(blk_n, :) ) ) ) &lt; 1e-10 );
4477%
4478% check other rows
4479blk_n = 1 : n;
4480for k = 2 : N-1
4481        blk_n = blk_n + n;
4482        lhs   = c(:, :, k)    * e(blk_n - n, :)  ...
4483              + b(:, :, k)    * e(blk_n, :)    ...
4484              + c(:, :, k+1)' * e(blk_n + n, :);
4485        ok    = ok &amp; ( max( max( abs( lhs - r(blk_n, :) ) ) ) &lt; 1e-10 );
4486end
4487return
4488end
4489</pre></font></code>
4490 
4491
4492<hr>Input File: test/tridiag_solve_ok.m
4493
4494<hr>
4495 
4496
4497
4498<center><b><big><big><a name="5.7" id="5.7">5.7: Affine Constrained Kalman Bucy Smoother Newton Step</a>
4499</big></big></b></center>
4500<br>
4501<b><big><a name="5.7.a" id="5.7.a">5.7.a: Syntax</a></big></b>
4502
4503<br>
4504<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>ds</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>dy</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>du</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_newton_step(</span></font></code><i><span style='white-space: nowrap'>mu</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>s</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>b</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>d</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Bdia</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Hdia</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Hlow</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
4505
4506<br>
4507<br>
4508<b><big><a name="5.7.b" id="5.7.b">5.7.b: Purpose</a></big></b>
4509<br>
4510This routine computes one step of Newton's method for solving
4511the non-linear Kuhn-Tucker conditions for
4512the <code>
4513<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4514-relaxed affine constrained Kalman-Bucy smoother problem.
4515
4516
4517<br>
4518<br>
4519<b><big><a name="5.7.c" id="5.7.c">5.7.c: Problem</a></big></b>
4520<br>
4521Given
4522<code>
4523<span style='white-space: nowrap'>&nbsp;\mu&nbsp;\in&nbsp;\R_+</span></code>
4524,
4525<code>
4526<span style='white-space: nowrap'>&nbsp;H&nbsp;\in&nbsp;\R^{p&nbsp;\times&nbsp;p}</span></code>
4527,
4528<code>
4529<span style='white-space: nowrap'>&nbsp;d&nbsp;\in&nbsp;\R^p</span></code>
4530,
4531<code>
4532<span style='white-space: nowrap'>&nbsp;b&nbsp;\in&nbsp;\R^r</span></code>
4533, and
4534<code>
4535<span style='white-space: nowrap'>&nbsp;B&nbsp;\in&nbsp;\R^{r&nbsp;\times&nbsp;p}</span></code>
4536,
4537the <code>
4538<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4539-relaxed affine constrained Kalman-Bucy smoother problem is:
4540<code>
4541<span style='white-space: nowrap'>&nbsp;\[<br>
4542\begin{array}{rl}<br>
4543{\rm&nbsp;minimize}&nbsp;&amp;&nbsp;\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
4544-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
4545\;&nbsp;{\rm&nbsp;w.r.t}&nbsp;\;&nbsp;y&nbsp;\in&nbsp;\R^p&nbsp;\;&nbsp;,&nbsp;\;&nbsp;s&nbsp;\in&nbsp;\R_+^r<br>
4546\\<br>
4547{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;&amp;&nbsp;s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;=&nbsp;0&nbsp;<br>
4548\end{array}<br>
4549\]&nbsp;</span></code>
4550
4551In addition, <code>
4552<span style='white-space: nowrap'>&nbsp;H</span></code>
4553 is symmetric block tri-diagonal with each block of
4554size <code>
4555<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
4556 and
4557<code>
4558<span style='white-space: nowrap'>&nbsp;B</span></code>
4559 is block diagonal with each block of size <code>
4560<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n</span></code>
4561
4562(there is an integer <code>
4563<span style='white-space: nowrap'>&nbsp;N</span></code>
4564 such that
4565<code>
4566<span style='white-space: nowrap'>&nbsp;p&nbsp;=&nbsp;n&nbsp;*&nbsp;N</span></code>
4567 and <code>
4568<span style='white-space: nowrap'>&nbsp;r&nbsp;=&nbsp;m&nbsp;*&nbsp;N</span></code>
4569).
4570
4571
4572<br>
4573<br>
4574<b><a name="5.7.c.a" id="5.7.c.a">5.7.c.a: Lagrangian</a></b>
4575<br>
4576We use <code>
4577<span style='white-space: nowrap'>&nbsp;u&nbsp;\in&nbsp;\R^r</span></code>
4578
4579to denote the Lagrange multipliers corresponding to the constraint equation.
4580The corresponding Lagrangian is
4581<code>
4582<span style='white-space: nowrap'>&nbsp;\[<br>
4583L(y,&nbsp;s,&nbsp;u)&nbsp;&nbsp;=<br>
4584\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
4585-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
4586+&nbsp;u^\T&nbsp;(s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y)<br>
4587\]&nbsp;</span></code>
4588
4589The partial gradients of the Lagrangian are given by
4590<code>
4591<span style='white-space: nowrap'>&nbsp;\[<br>
4592\begin{array}{rcl}<br>
4593\nabla_y&nbsp;L(y,&nbsp;s,&nbsp;u&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;\\<br>
4594\nabla_s&nbsp;L(y,&nbsp;s,&nbsp;u&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;u&nbsp;-&nbsp;\mu&nbsp;/&nbsp;s&nbsp;\\<br>
4595\nabla_u&nbsp;L(y,&nbsp;s,&nbsp;u&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;\\<br>
4596\end{array}<br>
4597\]&nbsp;</span></code>
4598
4599where <code>
4600<span style='white-space: nowrap'>&nbsp;\mu&nbsp;/&nbsp;s&nbsp;</span></code>
4601 is the component by component division of
4602<code>
4603<span style='white-space: nowrap'>&nbsp;\mu&nbsp;</span></code>
4604 by the components of the <code>
4605<span style='white-space: nowrap'>&nbsp;s</span></code>
4606.
4607Note, from the second equation, that we only need consider
4608<code>
4609<span style='white-space: nowrap'>&nbsp;u&nbsp;\geq&nbsp;0</span></code>
4610 because <code>
4611<span style='white-space: nowrap'>&nbsp;s&nbsp;\geq&nbsp;0</span></code>
4612.
4613
4614<br>
4615<br>
4616<b><a name="5.7.c.b" id="5.7.c.b">5.7.c.b: Kuhn-Tucker Conditions</a></b>
4617<br>
4618We use <code>
4619<span style='white-space: nowrap'>&nbsp;D(s)</span></code>
4620 
4621to denote the diagonal matrix with <code>
4622<span style='white-space: nowrap'>&nbsp;s</span></code>
4623
4624along its diagonal and <code>
4625<span style='white-space: nowrap'>&nbsp;1_r</span></code>
4626 
4627to denote the vector, of length <code>
4628<span style='white-space: nowrap'>&nbsp;r</span></code>
4629 with all its components
4630equal to one.
4631We define
4632<code>
4633<span style='white-space: nowrap'>&nbsp;F&nbsp;:&nbsp;\R^{r&nbsp;+&nbsp;p&nbsp;+&nbsp;r}&nbsp;\rightarrow&nbsp;\R^{r&nbsp;+&nbsp;p&nbsp;+&nbsp;r}</span></code>
4634
4635by
4636<code>
4637<span style='white-space: nowrap'>&nbsp;\[<br>
4638F(s,&nbsp;y,&nbsp;u)<br>
4639=<br>
4640\left(<br>
4641\begin{array}{c}<br>
4642s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4643H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
4644D(s)&nbsp;D(u)&nbsp;1_r&nbsp;-&nbsp;\mu&nbsp;1_r<br>
4645\end{array}<br>
4646\right)<br>
4647\]&nbsp;</span></code>
4648
4649The Kuhn-Tucker conditions for a solution of the
4650<code>
4651<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4652-relaxed constrained affine Kalman-Bucy smoother problem is
4653<code>
4654<span style='white-space: nowrap'>&nbsp;F(s,&nbsp;y,&nbsp;u)&nbsp;=&nbsp;0&nbsp;</span></code>
4655.
4656
4657<br>
4658<br>
4659<b><a name="5.7.c.c" id="5.7.c.c">5.7.c.c: Newton Step</a></b>
4660<br>
4661Given a value for <code>
4662<span style='white-space: nowrap'>&nbsp;(s,&nbsp;y,&nbsp;u)</span></code>
4663, the Newton step
4664<code>
4665<span style='white-space: nowrap'>&nbsp;(&nbsp;\Delta&nbsp;s^\T&nbsp;,&nbsp;\Delta&nbsp;y^\T&nbsp;,&nbsp;\Delta&nbsp;u^\T&nbsp;)^\T</span></code>
4666 solves the problem:
4667<code>
4668<span style='white-space: nowrap'>&nbsp;\[<br>
4669F^{(1)}&nbsp;(s,&nbsp;y,&nbsp;u)&nbsp;<br>
4670\left(&nbsp;\begin{array}{c}&nbsp;\Delta&nbsp;s&nbsp;\\&nbsp;\Delta&nbsp;y&nbsp;\\&nbsp;\Delta&nbsp;u&nbsp;\end{array}&nbsp;\right)<br>
4671=<br>
4672-&nbsp;F(s,&nbsp;y,&nbsp;u)<br>
4673\]&nbsp;</span></code>
4674
4675
4676<br>
4677<br>
4678<b><big><a name="5.7.d" id="5.7.d">5.7.d: mu</a></big></b>
4679<br>
4680The argument <i>mu</i> is a positive scalar specifying the
4681relaxation parameter <code>
4682<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4683.
4684
4685<br>
4686<br>
4687<b><big><a name="5.7.e" id="5.7.e">5.7.e: s</a></big></b>
4688<br>
4689The argument <i>s</i> is a column vector of length <code>
4690<span style='white-space: nowrap'>&nbsp;r</span></code>
4691.
4692All the elements of <i>s</i> are greater than zero.
4693
4694<br>
4695<br>
4696<b><big><a name="5.7.f" id="5.7.f">5.7.f: y</a></big></b>
4697<br>
4698The argument <i>y</i> is a column vector of length <code>
4699<span style='white-space: nowrap'>&nbsp;p</span></code>
4700
4701
4702<br>
4703<br>
4704<b><big><a name="5.7.g" id="5.7.g">5.7.g: u</a></big></b>
4705<br>
4706The argument <i>u</i> is a column vector of length <code>
4707<span style='white-space: nowrap'>&nbsp;r</span></code>
4708.
4709All the elements of <i>s</i> are greater than zero.
4710
4711<br>
4712<br>
4713<b><big><a name="5.7.h" id="5.7.h">5.7.h: b</a></big></b>
4714<br>
4715The argument <i>b</i> is a column vector of length <code>
4716<span style='white-space: nowrap'>&nbsp;r</span></code>
4717.
4718
4719<br>
4720<br>
4721<b><big><a name="5.7.i" id="5.7.i">5.7.i: d</a></big></b>
4722<br>
4723The argument <i>d</i> is a column vector of length <code>
4724<span style='white-space: nowrap'>&nbsp;p</span></code>
4725
4726
4727<br>
4728<br>
4729<b><big><a name="5.7.j" id="5.7.j">5.7.j: Bdia</a></big></b>
4730<br>
4731The argument <i>Bdia</i> is an <code>
4732<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4733 array.
4734For <code>
4735<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4736 we define <code>
4737<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
4738 by
4739<code>
4740<span style='white-space: nowrap'>&nbsp;\[<br>
4741&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
4742\]&nbsp;</span></code>
4743
4744
4745<br>
4746<br>
4747<b><big><a name="5.7.k" id="5.7.k">5.7.k: B</a></big></b>
4748<br>
4749The matrix <code>
4750<span style='white-space: nowrap'>&nbsp;B</span></code>
4751 is defined by
4752<code>
4753<span style='white-space: nowrap'>&nbsp;\[<br>
4754B&nbsp;<br>
4755=<br>
4756\left(&nbsp;\begin{array}{cccc}<br>
4757B_1&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
47580&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
47590&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4760&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_N&nbsp;<br>
4761\end{array}&nbsp;\right)<br>
4762\]&nbsp;</span></code>
4763
4764
4765<br>
4766<br>
4767<b><big><a name="5.7.l" id="5.7.l">5.7.l: Hdia</a></big></b>
4768<br>
4769The argument <i>Hdia</i> is an <code>
4770<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4771 array.
4772For <code>
4773<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4774 we define <code>
4775<span style='white-space: nowrap'>&nbsp;H_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
4776 by
4777<code>
4778<span style='white-space: nowrap'>&nbsp;\[<br>
4779&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;Hdia(:,&nbsp;:,&nbsp;k)<br>
4780\]&nbsp;</span></code>
4781
4782
4783
4784<br>
4785<br>
4786<b><big><a name="5.7.m" id="5.7.m">5.7.m: Hlow</a></big></b>
4787<br>
4788The argument <i>Hlow</i> is an <code>
4789<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4790 array.
4791For <code>
4792<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4793 we define <code>
4794<span style='white-space: nowrap'>&nbsp;L_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
4795 by
4796<code>
4797<span style='white-space: nowrap'>&nbsp;\[<br>
4798&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L_k&nbsp;=&nbsp;Hlow(:,&nbsp;:,&nbsp;k)<br>
4799\]&nbsp;</span></code>
4800
4801
4802<br>
4803<br>
4804<b><big><a name="5.7.n" id="5.7.n">5.7.n: H</a></big></b>
4805<br>
4806The matrix <code>
4807<span style='white-space: nowrap'>&nbsp;H</span></code>
4808 is defined by
4809<code>
4810<span style='white-space: nowrap'>&nbsp;\[<br>
4811H&nbsp;<br>
4812=<br>
4813\left(&nbsp;\begin{array}{cccc}<br>
4814H_1&nbsp;&amp;&nbsp;L_2^\T&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4815L_2&nbsp;&amp;&nbsp;H_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;L_3^\T&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
48160&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4817&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;L_N&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H_N&nbsp;<br>
4818\end{array}&nbsp;\right)<br>
4819\]&nbsp;</span></code>
4820
4821
4822<br>
4823<br>
4824<b><big><a name="5.7.o" id="5.7.o">5.7.o: ds</a></big></b>
4825<br>
4826The result <i>ds</i> is a column vector of length <code>
4827<span style='white-space: nowrap'>&nbsp;r</span></code>
4828 
4829equal to the <code>
4830<span style='white-space: nowrap'>&nbsp;\Delta&nbsp;s</span></code>
4831 components of the Newton step.
4832
4833<br>
4834<br>
4835<b><big><a name="5.7.p" id="5.7.p">5.7.p: dy</a></big></b>
4836<br>
4837The result <i>dy</i> is a column vector of length <code>
4838<span style='white-space: nowrap'>&nbsp;p</span></code>
4839 
4840equal to the <code>
4841<span style='white-space: nowrap'>&nbsp;\Delta&nbsp;y</span></code>
4842 components of the Newton step.
4843
4844<br>
4845<br>
4846<b><big><a name="5.7.q" id="5.7.q">5.7.q: du</a></big></b>
4847<br>
4848The result <i>du</i> is a column vector of length <code>
4849<span style='white-space: nowrap'>&nbsp;r</span></code>
4850 
4851equal to the <code>
4852<span style='white-space: nowrap'>&nbsp;\Delta&nbsp;u</span></code>
4853 components of the Newton step.
4854
4855
4856
4857<br>
4858<br>
4859<b><big><a name="5.7.r" id="5.7.r">5.7.r: Example</a></big></b>
4860<br>
4861The file <a href="#5.7.1">5.7.1: <span style='white-space: nowrap'>newton_step_ok.m</span></a>
4862 contains an example and test of
4863<code><font color="blue">ckbs_newton_step</font></code>.
4864It returns true if <code><font color="blue">ckbs_newton_step</font></code> passes the test
4865and false otherwise.
4866
4867<br>
4868<br>
4869<b><big><a name="5.7.s" id="5.7.s">5.7.s: Method</a></big></b>
4870<br>
4871The derivative of <code>
4872<span style='white-space: nowrap'>&nbsp;F</span></code>
4873 is given by
4874<code>
4875<span style='white-space: nowrap'>&nbsp;\[<br>
4876F^{(1)}&nbsp;(s,&nbsp;y,&nbsp;u)&nbsp;=<br>
4877\left(<br>
4878\begin{array}{ccccc}<br>
4879D(&nbsp;1_r&nbsp;)&nbsp;&amp;&nbsp;B&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
48800&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H&nbsp;&nbsp;&nbsp;&amp;&nbsp;B^\T&nbsp;&nbsp;\\<br>
4881D(&nbsp;u&nbsp;)&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;D(s)<br>
4882\end{array}<br>
4883\right)<br>
4884\]&nbsp;</span></code>
4885
4886It follows that
4887<code>
4888<span style='white-space: nowrap'>&nbsp;\[<br>
4889\left(&nbsp;\begin{array}{ccc}<br>
4890D(&nbsp;1_r&nbsp;)&nbsp;&amp;&nbsp;B&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
48910&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H&nbsp;&nbsp;&nbsp;&amp;&nbsp;B^\T&nbsp;&nbsp;\\<br>
4892D(&nbsp;u&nbsp;)&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;D(s)<br>
4893\end{array}&nbsp;\right)<br>
4894\left(&nbsp;\begin{array}{c}&nbsp;\Delta&nbsp;s&nbsp;\\&nbsp;\Delta&nbsp;y&nbsp;\\&nbsp;\Delta&nbsp;u&nbsp;\end{array}&nbsp;\right)<br>
4895=<br>
4896-<br>
4897\left(&nbsp;\begin{array}{c}<br>
4898s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4899H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
4900D(s)&nbsp;D(u)&nbsp;1_r&nbsp;-&nbsp;\mu&nbsp;1_r<br>
4901\end{array}&nbsp;\right)<br>
4902\]&nbsp;</span></code>
4903
4904Replacing the bottom row by the bottom row minus
4905<code>
4906<span style='white-space: nowrap'>&nbsp;D(u)</span></code>
4907 times the top row,
4908we obtain the reduced set of equations
4909<code>
4910<span style='white-space: nowrap'>&nbsp;\[<br>
4911\left(&nbsp;\begin{array}{cc}<br>
4912&nbsp;H&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;B^\T&nbsp;&nbsp;\\<br>
4913-D(u)&nbsp;B&nbsp;&amp;&nbsp;D(s)&nbsp;<br>
4914\end{array}&nbsp;\right)&nbsp;<br>
4915\left(&nbsp;\begin{array}{c}&nbsp;\Delta&nbsp;y&nbsp;\\&nbsp;\Delta&nbsp;u&nbsp;\end{array}&nbsp;\right)<br>
4916=<br>
4917\left(&nbsp;\begin{array}{c}<br>
4918-&nbsp;H&nbsp;y&nbsp;-&nbsp;B^\T&nbsp;u&nbsp;-&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
4919\mu&nbsp;1_r&nbsp;+&nbsp;D(u)&nbsp;(&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;)<br>
4920\end{array}&nbsp;\right)<br>
4921\]&nbsp;</span></code>
4922
4923Replacing the top row by <code>
4924<span style='white-space: nowrap'>&nbsp;H^{-1}</span></code>
4925 times the top row we obtain
4926<code>
4927<span style='white-space: nowrap'>&nbsp;\[<br>
4928\left(&nbsp;\begin{array}{cc}<br>
4929&nbsp;D(&nbsp;1_p&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H^{-1}&nbsp;B^\T&nbsp;&nbsp;\\<br>
4930-D(u)&nbsp;B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;D(s)&nbsp;<br>
4931\end{array}&nbsp;\right)&nbsp;<br>
4932\left(&nbsp;\begin{array}{c}&nbsp;\Delta&nbsp;y&nbsp;\\&nbsp;\Delta&nbsp;u&nbsp;\end{array}&nbsp;\right)<br>
4933=<br>
4934\left(&nbsp;\begin{array}{c}<br>
4935-&nbsp;y&nbsp;-&nbsp;H^{-1}(&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;)&nbsp;&nbsp;&nbsp;\\<br>
4936\mu&nbsp;1_r&nbsp;+&nbsp;D(u)&nbsp;(&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;)<br>
4937\end{array}&nbsp;\right)<br>
4938\]&nbsp;</span></code>
4939
4940Replacing the bottom row by
4941the <code>
4942<span style='white-space: nowrap'>&nbsp;D(u)^{-1}</span></code>
4943 times the bottom row
4944plus <code>
4945<span style='white-space: nowrap'>&nbsp;B</span></code>
4946 times the top row,
4947we obtain the reduced equation
4948<code>
4949<span style='white-space: nowrap'>&nbsp;\[<br>
4950\begin{array}{rcl}<br>
4951[&nbsp;B&nbsp;H^{-1}&nbsp;B^\T&nbsp;+&nbsp;D(s&nbsp;/&nbsp;u)&nbsp;]&nbsp;\Delta&nbsp;u&nbsp;<br>
4952&amp;&nbsp;=&nbsp;&amp;<br>
4953\mu&nbsp;(&nbsp;1_r&nbsp;/&nbsp;u&nbsp;)&nbsp;+&nbsp;b&nbsp;-&nbsp;B&nbsp;H^{-1}(&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;)&nbsp;<br>
4954\end{array}<br>
4955\]&nbsp;</span></code>
4956
4957Thus we obtain the following solution for the Newton step:
4958<code>
4959<span style='white-space: nowrap'>&nbsp;\[<br>
4960\begin{array}{rcl}<br>
4961\Delta&nbsp;u&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
4962&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[&nbsp;B&nbsp;H^{-1}&nbsp;B^\T&nbsp;+&nbsp;D(s&nbsp;/&nbsp;u)&nbsp;]^{-1}&nbsp;<br>
4963&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[&nbsp;\mu&nbsp;(&nbsp;1_r&nbsp;/&nbsp;u&nbsp;)&nbsp;+&nbsp;b&nbsp;-&nbsp;B&nbsp;H^{-1}(&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;)&nbsp;]<br>
4964\\<br>
4965\Delta&nbsp;y&nbsp;&amp;&nbsp;=&nbsp;&amp;<br>
4966-&nbsp;y&nbsp;-&nbsp;H^{-1}&nbsp;[&nbsp;d&nbsp;+&nbsp;B^\T&nbsp;(&nbsp;u&nbsp;+&nbsp;\Delta&nbsp;u&nbsp;)&nbsp;]&nbsp;&nbsp;&nbsp;\\<br>
4967\\<br>
4968\Delta&nbsp;s&nbsp;&amp;&nbsp;=&nbsp;&amp;<br>
4969-&nbsp;s&nbsp;-&nbsp;b&nbsp;-&nbsp;B&nbsp;(&nbsp;y&nbsp;+&nbsp;\Delta&nbsp;y&nbsp;)<br>
4970\end{array}<br>
4971\]&nbsp;</span></code>
4972
4973It follows from the matrix inversion lemma that
4974<code>
4975<span style='white-space: nowrap'>&nbsp;\[<br>
4976[&nbsp;B&nbsp;H^{-1}&nbsp;B^\T&nbsp;+&nbsp;D(s&nbsp;/&nbsp;u)&nbsp;]^{-1}&nbsp;<br>
4977=&nbsp;<br>
4978D(s/u)^{-1}&nbsp;-&nbsp;D(s/u)^{-1}&nbsp;B&nbsp;[&nbsp;H&nbsp;+&nbsp;B^\T&nbsp;D(s/u)^{-1}&nbsp;B&nbsp;]^{-1}&nbsp;B^\T&nbsp;D(s/u)^{-1}<br>
4979\]&nbsp;</span></code>
4980
4981
4982
4983<hr>Input File: src/ckbs_newton_step.m
4984
4985<hr>
4986 
4987
4988
4989<center><b><big><big><a name="5.7.1" id="5.7.1">5.7.1: ckbs_newton_step Example and Test</a>
4990</big></big></b></center>
4991<br>
4992<b><big><a name="5.7.1.a" id="5.7.1.a">5.7.1.a: Source Code</a></big></b>
4993
4994 <code><font color='blue'><pre style='display:inline'> 
4995function [ok] = newton_step_ok()
4996ok = true;
4997% --------------------------------------------------------
4998% You can change these parameters
4999m    = 2;   % number of measurements per time point
5000n    = 3;   % number of state vector components per time point
5001N    = 4;   % number of time points
5002% ---------------------------------------------------------
5003%  Define the problem
5004rand('seed', 123);
5005mu    = .5;
5006r     = m * N;
5007p     = n * N;
5008s     = rand(r, 1) + 1;
5009y     = rand(p, 1);
5010u     = rand(r, 1) + 1;
5011b     = rand(r, 1);
5012d     = rand(p, 1);
5013H     = zeros(p, p);
5014B     = zeros(r, r);
5015Hdia  = zeros(n, n, N);
5016Hlow  = zeros(n, n, N);
5017Bdia  = zeros(m, n, N);
5018blk_m = m * N + (1 : m);
5019blk_n = n * N + (1 : n);
5020for k = N : -1 : 1
5021        blk_n = blk_n - n;
5022        blk_m = blk_m - m;
5023        %
5024        Bdia(:,:, k)    = rand(m, n);
5025        tmp             = rand(n, n);
5026        Hlow(:,:, k)    = tmp;
5027        Hdia(:,:, k)   = (tmp * tmp') + 4 * eye(n);
5028        %
5029        B(blk_m, blk_n) = Bdia(:,:, k);
5030        H(blk_n, blk_n) = Hdia(:,:, k);
5031        if k &gt; 1
5032                H(blk_n, blk_n - n) = Hlow(:,:, k);
5033        end
5034        if k &lt; N
5035                H(blk_n, blk_n + n) = Hlow(:,:, k + 1)';
5036        end
5037end
5038% -------------------------------------------------------------------
5039[ds, dy, du] = ckbs_newton_step(mu, s, y, u, b, d, Bdia, Hdia, Hlow);
5040% -------------------------------------------------------------------
5041F      = [ ...
5042        s + b + B * y
5043        H * y + B' * u + d
5044        s .* u - mu ...
5045];
5046dF     = [ ...
5047        eye(r)      , B           , zeros(r, r)
5048        zeros(p, r) , H           , B'
5049        diag(u)     , zeros(r, p) , diag(s) ...
5050];
5051delta        = [ ds ; dy ; du ];
5052ok           = ok &amp; ( max( abs( F + dF * delta ) ) &lt;= 1e-10 );
5053return
5054end
5055</pre></font></code>
5056 
5057
5058<hr>Input File: test/newton_step_ok.m
5059
5060<hr>
5061 
5062
5063
5064<center><b><big><big><a name="5.8" id="5.8">5.8: Compute Residual in Kuhn-Tucker Conditions</a>
5065</big></big></b></center>
5066<br>
5067<b><big><a name="5.8.a" id="5.8.a">5.8.a: Syntax</a></big></b>
5068
5069<br>
5070<code><font color="blue"><span style='white-space: nowrap'>[</span></font></code><i><span style='white-space: nowrap'>F</span></i><code><font color="blue"><span style='white-space: nowrap'>]&nbsp;=&nbsp;ckbs_kuhn_tucker(</span></font></code><i><span style='white-space: nowrap'>mu</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>s</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>y</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>u</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>b</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>d</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Bdia</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Hdia</span></i><code><font color="blue"><span style='white-space: nowrap'>,&nbsp;</span></font></code><i><span style='white-space: nowrap'>Hlow</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
5071
5072<br>
5073<br>
5074<b><big><a name="5.8.b" id="5.8.b">5.8.b: Purpose</a></big></b>
5075<br>
5076This routine computes the residual in the Kuhn-Tucker conditions for
5077the <code>
5078<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5079-relaxed affine constrained Kalman-Bucy smoother problem.
5080
5081<br>
5082<br>
5083<b><big><a name="5.8.c" id="5.8.c">5.8.c: Problem</a></big></b>
5084<br>
5085Given
5086<code>
5087<span style='white-space: nowrap'>&nbsp;\mu&nbsp;\in&nbsp;\R_+</span></code>
5088,
5089<code>
5090<span style='white-space: nowrap'>&nbsp;H&nbsp;\in&nbsp;\R^{p&nbsp;\times&nbsp;p}</span></code>
5091,
5092<code>
5093<span style='white-space: nowrap'>&nbsp;d&nbsp;\in&nbsp;\R^p</span></code>
5094,
5095<code>
5096<span style='white-space: nowrap'>&nbsp;b&nbsp;\in&nbsp;\R^r</span></code>
5097, and
5098<code>
5099<span style='white-space: nowrap'>&nbsp;B&nbsp;\in&nbsp;\R^{r&nbsp;\times&nbsp;p}</span></code>
5100,
5101the <code>
5102<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5103-relaxed affine constrained Kalman-Bucy smoother problem is:
5104<code>
5105<span style='white-space: nowrap'>&nbsp;\[<br>
5106\begin{array}{rl}<br>
5107{\rm&nbsp;minimize}&nbsp;&amp;&nbsp;\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
5108-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
5109\;&nbsp;{\rm&nbsp;w.r.t}&nbsp;\;&nbsp;y&nbsp;\in&nbsp;\R^p&nbsp;\;&nbsp;,&nbsp;\;&nbsp;s&nbsp;\in&nbsp;\R_+^r<br>
5110\\<br>
5111{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;&amp;&nbsp;s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;=&nbsp;0&nbsp;<br>
5112\end{array}<br>
5113\]&nbsp;</span></code>
5114
5115In addition, <code>
5116<span style='white-space: nowrap'>&nbsp;H</span></code>
5117 is symmetric block tri-diagonal with each block of
5118size <code>
5119<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
5120 and
5121<code>
5122<span style='white-space: nowrap'>&nbsp;B</span></code>
5123 is block diagonal with each block of size <code>
5124<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n</span></code>
5125
5126(there is an integer <code>
5127<span style='white-space: nowrap'>&nbsp;N</span></code>
5128 such that
5129<code>
5130<span style='white-space: nowrap'>&nbsp;p&nbsp;=&nbsp;n&nbsp;*&nbsp;N</span></code>
5131 and <code>
5132<span style='white-space: nowrap'>&nbsp;r&nbsp;=&nbsp;m&nbsp;*&nbsp;N</span></code>
5133).
5134
5135
5136<br>
5137<br>
5138<b><big><a name="5.8.d" id="5.8.d">5.8.d: Lagrangian</a></big></b>
5139<br>
5140We use <code>
5141<span style='white-space: nowrap'>&nbsp;u&nbsp;\in&nbsp;\R^r</span></code>
5142
5143to denote the Lagrange multipliers corresponding to the constraint equation.
5144The corresponding Lagrangian is
5145<code>
5146<span style='white-space: nowrap'>&nbsp;\[<br>
5147L(y,&nbsp;s,&nbsp;u)&nbsp;&nbsp;=<br>
5148\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
5149-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
5150+&nbsp;u^\T&nbsp;(s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y)<br>
5151\]&nbsp;</span></code>
5152
5153The partial gradients of the Lagrangian are given by
5154<code>
5155<span style='white-space: nowrap'>&nbsp;\[<br>
5156\begin{array}{rcl}<br>
5157\nabla_y&nbsp;L(y,&nbsp;s,&nbsp;u&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;\\<br>
5158\nabla_s&nbsp;L(y,&nbsp;s,&nbsp;u&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;u&nbsp;-&nbsp;\mu&nbsp;/&nbsp;s&nbsp;\\<br>
5159\nabla_u&nbsp;L(y,&nbsp;s,&nbsp;u&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;\\<br>
5160\end{array}<br>
5161\]&nbsp;</span></code>
5162
5163where <code>
5164<span style='white-space: nowrap'>&nbsp;\mu&nbsp;/&nbsp;s&nbsp;</span></code>
5165 is the component by component division of
5166<code>
5167<span style='white-space: nowrap'>&nbsp;\mu&nbsp;</span></code>
5168 by the components of the <code>
5169<span style='white-space: nowrap'>&nbsp;s</span></code>
5170.
5171Note, from the second equation, that we only need consider
5172<code>
5173<span style='white-space: nowrap'>&nbsp;u&nbsp;\geq&nbsp;0</span></code>
5174 because <code>
5175<span style='white-space: nowrap'>&nbsp;s&nbsp;\geq&nbsp;0</span></code>
5176.
5177
5178<br>
5179<br>
5180<b><big><a name="5.8.e" id="5.8.e">5.8.e: Kuhn-Tucker Residual</a></big></b>
5181<br>
5182We use <code>
5183<span style='white-space: nowrap'>&nbsp;D(s)</span></code>
5184 
5185to denote the diagonal matrix with <code>
5186<span style='white-space: nowrap'>&nbsp;s</span></code>
5187
5188along its diagonal and <code>
5189<span style='white-space: nowrap'>&nbsp;1_r</span></code>
5190 
5191to denote the vector, of length <code>
5192<span style='white-space: nowrap'>&nbsp;r</span></code>
5193 with all its components
5194equal to one.
5195The Kuhn-Tucker Residual function
5196<code>
5197<span style='white-space: nowrap'>&nbsp;F&nbsp;:&nbsp;\R^{r&nbsp;+&nbsp;p&nbsp;+&nbsp;r}&nbsp;\rightarrow&nbsp;\R^{r&nbsp;+&nbsp;p&nbsp;+&nbsp;r}</span></code>
5198
5199is defined by
5200<code>
5201<span style='white-space: nowrap'>&nbsp;\[<br>
5202F(s,&nbsp;y,&nbsp;u)<br>
5203=<br>
5204\left(<br>
5205\begin{array}{c}<br>
5206s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
5207H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
5208D(s)&nbsp;D(u)&nbsp;1_r&nbsp;-&nbsp;\mu&nbsp;1_r<br>
5209\end{array}<br>
5210\right)<br>
5211\]&nbsp;</span></code>
5212
5213The Kuhn-Tucker conditions for a solution of the
5214<code>
5215<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5216-relaxed constrained affine Kalman-Bucy smoother problem is
5217<code>
5218<span style='white-space: nowrap'>&nbsp;F(s,&nbsp;y,&nbsp;u)&nbsp;=&nbsp;0&nbsp;</span></code>
5219.
5220
5221<br>
5222<br>
5223<b><big><a name="5.8.f" id="5.8.f">5.8.f: mu</a></big></b>
5224<br>
5225The argument <i>mu</i> is a positive scalar specifying the
5226relaxation parameter <code>
5227<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5228.
5229
5230<br>
5231<br>
5232<b><big><a name="5.8.g" id="5.8.g">5.8.g: s</a></big></b>
5233<br>
5234The argument <i>s</i> is a column vector of length <code>
5235<span style='white-space: nowrap'>&nbsp;r</span></code>
5236.
5237All the elements of <i>s</i> are greater than zero.
5238
5239<br>
5240<br>
5241<b><big><a name="5.8.h" id="5.8.h">5.8.h: y</a></big></b>
5242<br>
5243The argument <i>y</i> is a column vector of length <code>
5244<span style='white-space: nowrap'>&nbsp;p</span></code>
5245
5246
5247<br>
5248<br>
5249<b><big><a name="5.8.i" id="5.8.i">5.8.i: u</a></big></b>
5250<br>
5251The argument <i>u</i> is a column vector of length <code>
5252<span style='white-space: nowrap'>&nbsp;r</span></code>
5253.
5254All the elements of <i>s</i> are greater than zero.
5255
5256<br>
5257<br>
5258<b><big><a name="5.8.j" id="5.8.j">5.8.j: b</a></big></b>
5259<br>
5260The argument <i>b</i> is a column vector of length <code>
5261<span style='white-space: nowrap'>&nbsp;r</span></code>
5262.
5263
5264<br>
5265<br>
5266<b><big><a name="5.8.k" id="5.8.k">5.8.k: d</a></big></b>
5267<br>
5268The argument <i>d</i> is a column vector of length <code>
5269<span style='white-space: nowrap'>&nbsp;p</span></code>
5270
5271
5272<br>
5273<br>
5274<b><big><a name="5.8.l" id="5.8.l">5.8.l: Bdia</a></big></b>
5275<br>
5276The argument <i>Bdia</i> is an <code>
5277<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
5278 array.
5279For <code>
5280<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
5281 we define <code>
5282<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
5283 by
5284<code>
5285<span style='white-space: nowrap'>&nbsp;\[<br>
5286&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
5287\]&nbsp;</span></code>
5288
5289
5290<br>
5291<br>
5292<b><big><a name="5.8.m" id="5.8.m">5.8.m: B</a></big></b>
5293<br>
5294The matrix <code>
5295<span style='white-space: nowrap'>&nbsp;B</span></code>
5296 is defined by
5297<code>
5298<span style='white-space: nowrap'>&nbsp;\[<br>
5299B&nbsp;<br>
5300=<br>
5301\left(&nbsp;\begin{array}{cccc}<br>
5302B_1&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
53030&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
53040&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
5305&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;B_N&nbsp;<br>
5306\end{array}&nbsp;\right)<br>
5307\]&nbsp;</span></code>
5308
5309
5310<br>
5311<br>
5312<b><big><a name="5.8.n" id="5.8.n">5.8.n: Hdia</a></big></b>
5313<br>
5314The argument <i>Hdia</i> is an <code>
5315<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
5316 array.
5317For <code>
5318<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
5319 we define <code>
5320<span style='white-space: nowrap'>&nbsp;H_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
5321 by
5322<code>
5323<span style='white-space: nowrap'>&nbsp;\[<br>
5324&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;Hdia(:,&nbsp;:,&nbsp;k)<br>
5325\]&nbsp;</span></code>
5326
5327
5328
5329<br>
5330<br>
5331<b><big><a name="5.8.o" id="5.8.o">5.8.o: Hlow</a></big></b>
5332<br>
5333The argument <i>Hlow</i> is an <code>
5334<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
5335 array.
5336For <code>
5337<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
5338 we define <code>
5339<span style='white-space: nowrap'>&nbsp;L_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
5340 by
5341<code>
5342<span style='white-space: nowrap'>&nbsp;\[<br>
5343&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L_k&nbsp;=&nbsp;Hlow(:,&nbsp;:,&nbsp;k)<br>
5344\]&nbsp;</span></code>
5345
5346
5347<br>
5348<br>
5349<b><big><a name="5.8.p" id="5.8.p">5.8.p: H</a></big></b>
5350<br>
5351The matrix <code>
5352<span style='white-space: nowrap'>&nbsp;H</span></code>
5353 is defined by
5354<code>
5355<span style='white-space: nowrap'>&nbsp;\[<br>
5356H&nbsp;<br>
5357=<br>
5358\left(&nbsp;\begin{array}{cccc}<br>
5359H_1&nbsp;&amp;&nbsp;L_2^\T&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
5360L_2&nbsp;&amp;&nbsp;H_2&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;L_3^\T&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
53610&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
5362&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;L_N&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H_N&nbsp;<br>
5363\end{array}&nbsp;\right)<br>
5364\]&nbsp;</span></code>
5365
5366
5367<br>
5368<br>
5369<b><big><a name="5.8.q" id="5.8.q">5.8.q: F</a></big></b>
5370<br>
5371The result <i>F</i> is a column vector of length <code>
5372<span style='white-space: nowrap'>&nbsp;r&nbsp;+&nbsp;p&nbsp;+&nbsp;r</span></code>
5373
5374containing the value of the
5375<a href="#5.8.e">5.8.e: <span style='white-space: nowrap'>Kuhn-Tucker&nbsp;residual</span></a>
5376; i.e.,
5377<code>
5378<span style='white-space: nowrap'>&nbsp;F(s,&nbsp;y,&nbsp;u)</span></code>
5379.
5380
5381
5382
5383<br>
5384<br>
5385<b><big><a name="5.8.r" id="5.8.r">5.8.r: Example</a></big></b>
5386<br>
5387The file <a href="#5.8.1">5.8.1: <span style='white-space: nowrap'>kuhn_tucker_ok.m</span></a>
5388 contains an example and test of
5389<code><font color="blue">ckbs_kuhn_tucker</font></code>.
5390It returns true if <code><font color="blue">ckbs_kuhn_tucker</font></code> passes the test
5391and false otherwise.
5392
5393
5394<hr>Input File: src/ckbs_kuhn_tucker.m
5395
5396<hr>
5397 
5398
5399
5400<center><b><big><big><a name="5.8.1" id="5.8.1">5.8.1: ckbs_kuhn_tucker Example and Test</a>
5401</big></big></b></center>
5402<br>
5403<b><big><a name="5.8.1.a" id="5.8.1.a">5.8.1.a: Source Code</a></big></b>
5404<