source: html/ckbs/_printable.htm @ 68

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

[html/ckbs] bring documentation up to date before creating stable version

File size: 255.5 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: Using Subversion</a></b>
49<br>
50If you have subversion, you can download a copy of the most recent
51version of ckbs with the command
52
53<code><font color="blue"><span style='white-space: nowrap'><br>
54&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;web=&quot;https://projects.coin-or.org/svn/CoinBazaar/projects/ckbs&quot;<br>
55&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;svn&nbsp;checkout&nbsp;$web/trunk&nbsp;ckbs-0.20100228.0<br>
56</span></font></code>
57You can download a previous release of ckbs with the command
58
59<code><font color="blue"><span style='white-space: nowrap'><br>
60&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>
61</span></font></code>
62where
63<code><i><font color="black"><span style='white-space: nowrap'>yyyy</span></font></i></code>
64 is the year,
65
66<code><i><font color="black"><span style='white-space: nowrap'>mm</span></font></i></code>
67 is the month,
68
69<code><i><font color="black"><span style='white-space: nowrap'>dd</span></font></i></code>
70 is the day,
71and
72<code><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
73 is the release number for the release you want.
74In either case, this creates the directory
75
76<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>
77.
78<code><span style='white-space: nowrap'><br>
79<br>
80</span></code>The release number (
81<code><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
82 above)
83starts at zero and is incremented for bug fixes.
84The date (
85<code><i><font color="black"><span style='white-space: nowrap'>yyyymmdd</span></font></i></code>
86 above)
87is incremented with feature changes which are discussed by date
88in the <a href="#7">7: <span style='white-space: nowrap'>whatsnew</span></a>
89 section of this documentation
90
91<br>
92<br>
93<b><a name="c.b" id="c.b">c.b: Release Tarballs</a></b>
94<br>
95If you do not have subversion you can download the tarball
96
97<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><font color="blue"><span style='white-space: nowrap'>.tgz</span></font></code>
98 from the release download directory
99<code><font color='blue'><pre style='display:inline'> 
100        http://www.coin-or.org/download/source/CoinBazaar
101</pre></font></code>
102
103You can extract the files from the tarball using the command
104
105<code><font color="blue"><span style='white-space: nowrap'><br>
106&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>
107</span></font></code>
108This will create the directory
109
110<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>
111.
112
113<br>
114<br>
115<b><big><a name="d" id="d">d: Test Install</a></big></b>
116<br>
117Using Matlab&#174; or Octave, to change into the directory
118
119<code><font color="blue"><span style='white-space: nowrap'><br>
120&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>
121</span></font></code>
122and run the program <code><font color="blue">all_ok.m</font></code>.
123It will print the test results for all the components of <code><font color="blue">ckbs</font></code>.
124
125<br>
126<br>
127<b><big><a name="e" id="e">e: Documentation</a></big></b>
128<br>
129A copy of the documentation for your version of ckbs can
130be built by executing the command
131<code><font color='blue'><pre style='display:inline'> 
132        ./build_doc.sh
133</pre></font></code>
134
135in the <code><font color="blue">ckbs-0.%yyyymmdd%.%r%</font></code> directory.
136You can then view the documentation by loading the file
137
138<code><font color="blue"><span style='white-space: nowrap'><br>
139&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>
140</span></font></code>
141into your browser.
142
143<br>
144<br>
145<b><big><a name="f" id="f">f: Contents</a></big></b>
146<br>
147<table>
148<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>
149<hr>Input File: ckbs.omh
150
151<hr>
152<center><b><big><big>
1531: Table of Contents</big></big></b></center>
154
155<pre>
156ckbs-0.20100228.0: A Constrained Kalman-Bucy Smoother: <a href="#">: ckbs</a>
157    Table of Contents: <a href="#1">1: _contents</a>
158    Your License to use the ckbs Software: <a href="#2">2: license</a>
159    The Nonlinear Constrained Kalman-Bucy Smoother: <a href="#3">3: ckbs_nonlinear</a>
160        Simple ckbs_nonlinear Example and Test: <a href="#3.1">3.1: nonlinear_ok_simple.m</a>
161            Example Constraint Function: nonlinear_ok_simple_f: <a href="#3.1.1">3.1.1: nonlinear_ok_simple_f.m</a>
162            Example Transition Function: nonlinear_ok_simple_g: <a href="#3.1.2">3.1.2: nonlinear_ok_simple_g.m</a>
163            Example Measurement Function: nonlinear_ok_simple_h: <a href="#3.1.3">3.1.3: nonlinear_ok_simple_h.m</a>
164        ckbs_nonlinear Box Constrained Tracking Example and Test: <a href="#3.2">3.2: nonlinear_ok_box.m</a>
165            Example Constraint Function: nonlinear_ok_box_f: <a href="#3.2.1">3.2.1: nonlinear_ok_box_f.m</a>
166            Example Transition Function: nonlinear_ok_box_g: <a href="#3.2.2">3.2.2: nonlinear_ok_box_g.m</a>
167            Example Measurement Function: nonlinear_ok_box_h: <a href="#3.2.3">3.2.3: nonlinear_ok_box_h.m</a>
168            Example no Constraint Function: nonlinear_ok_box_nof: <a href="#3.2.4">3.2.4: nonlinear_ok_box_nof.m</a>
169        ckbs_nonlinear Sine Wave Constrained Tracking Example and Test: <a href="#3.3">3.3: nonlinear_ok_sin.m</a>
170            Example Constraint Function: nonlinear_ok_sin_f: <a href="#3.3.1">3.3.1: nonlinear_ok_sin_f.m</a>
171    Constrained Affine Kalman Bucy Smoother: <a href="#4">4: ckbs_affine</a>
172        ckbs_affine Box Constrained Smoothing Spline Example and Test: <a href="#4.1">4.1: affine_ok_box.m</a>
173    ckbs Utility Functions: <a href="#5">5: utility</a>
174        Packed Block Diagonal Matrix Times a Vector: <a href="#5.1">5.1: ckbs_blkdiag_mul</a>
175            blkdiag_mul Example and Test: <a href="#5.1.1">5.1.1: blkdiag_mul_ok.m</a>
176        Transpose of Packed Block Diagonal Matrix Times a Vector: <a href="#5.2">5.2: ckbs_blkdiag_mul_t</a>
177            blkdiag_mul_t Example and Test: <a href="#5.2.1">5.2.1: blkdiag_mul_t_ok.m</a>
178        Affine Residual Sum of Squares Objective: <a href="#5.3">5.3: ckbs_sumsq_obj</a>
179            ckbs_sumsq_obj Example and Test: <a href="#5.3.1">5.3.1: sumsq_obj_ok.m</a>
180        Affine Residual Sum of Squares Gradient: <a href="#5.4">5.4: ckbs_sumsq_grad</a>
181            ckbs_sumsq_grad Example and Test: <a href="#5.4.1">5.4.1: sumsq_grad_ok.m</a>
182        Affine Residual Sum of Squares Hessian: <a href="#5.5">5.5: ckbs_sumsq_hes</a>
183            ckbs_sumsq_hes Example and Test: <a href="#5.5.1">5.5.1: sumsq_hes_ok.m</a>
184        Symmetric Block Tridiagonal Algorithm: <a href="#5.6">5.6: ckbs_tridiag_solve</a>
185            ckbs_tridiag_solve Example and Test: <a href="#5.6.1">5.6.1: tridiag_solve_ok.m</a>
186        Affine Constrained Kalman Bucy Smoother Newton Step: <a href="#5.7">5.7: ckbs_newton_step</a>
187            ckbs_newton_step Example and Test: <a href="#5.7.1">5.7.1: newton_step_ok.m</a>
188        Compute Residual in Kuhn-Tucker Conditions: <a href="#5.8">5.8: ckbs_kuhn_tucker</a>
189            ckbs_kuhn_tucker Example and Test: <a href="#5.8.1">5.8.1: kuhn_tucker_ok.m</a>
190    Run All Correctness Tests: <a href="#6">6: all_ok.m</a>
191        Ensure Path is Set for Testing: <a href="#6.1">6.1: test_path.m</a>
192    Changes and Additions to ckbs: <a href="#7">7: whatsnew</a>
193    Alphabetic Listing of Cross Reference Tags: <a href="#8">8: _reference</a>
194    Keyword Index: <a href="#9">9: _index</a>
195    External Internet References: <a href="#10">10: _external</a>
196</pre>
197<hr>
198<center><b><big><big><a name="2" id="2">2: Your License to use the ckbs Software</a>
199</big></big></b></center>
200<code><span style='white-space: nowrap'><br>
201&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GNU&nbsp;GENERAL&nbsp;PUBLIC&nbsp;LICENSE<br>
202&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>
203<br>
204&nbsp;Copyright&nbsp;(C)&nbsp;1989,&nbsp;1991&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;Inc.,<br>
205&nbsp;51&nbsp;Franklin&nbsp;Street,&nbsp;Fifth&nbsp;Floor,&nbsp;Boston,&nbsp;MA&nbsp;02110-1301&nbsp;USA<br>
206&nbsp;Everyone&nbsp;is&nbsp;permitted&nbsp;to&nbsp;copy&nbsp;and&nbsp;distribute&nbsp;verbatim&nbsp;copies<br>
207&nbsp;of&nbsp;this&nbsp;license&nbsp;document,&nbsp;but&nbsp;changing&nbsp;it&nbsp;is&nbsp;not&nbsp;allowed.<br>
208<br>
209&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Preamble<br>
210<br>
211&nbsp;&nbsp;The&nbsp;licenses&nbsp;for&nbsp;most&nbsp;software&nbsp;are&nbsp;designed&nbsp;to&nbsp;take&nbsp;away&nbsp;your<br>
212freedom&nbsp;to&nbsp;share&nbsp;and&nbsp;change&nbsp;it.&nbsp;&nbsp;By&nbsp;contrast,&nbsp;the&nbsp;GNU&nbsp;General&nbsp;Public<br>
213License&nbsp;is&nbsp;intended&nbsp;to&nbsp;guarantee&nbsp;your&nbsp;freedom&nbsp;to&nbsp;share&nbsp;and&nbsp;change&nbsp;free<br>
214software--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>
215General&nbsp;Public&nbsp;License&nbsp;applies&nbsp;to&nbsp;most&nbsp;of&nbsp;the&nbsp;Free&nbsp;Software<br>
216Foundation's&nbsp;software&nbsp;and&nbsp;to&nbsp;any&nbsp;other&nbsp;program&nbsp;whose&nbsp;authors&nbsp;commit&nbsp;to<br>
217using&nbsp;it.&nbsp;&nbsp;(Some&nbsp;other&nbsp;Free&nbsp;Software&nbsp;Foundation&nbsp;software&nbsp;is&nbsp;covered&nbsp;by<br>
218the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;instead.)&nbsp;&nbsp;You&nbsp;can&nbsp;apply&nbsp;it&nbsp;to<br>
219your&nbsp;programs,&nbsp;too.<br>
220<br>
221&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>
222price.&nbsp;&nbsp;Our&nbsp;General&nbsp;Public&nbsp;Licenses&nbsp;are&nbsp;designed&nbsp;to&nbsp;make&nbsp;sure&nbsp;that&nbsp;you<br>
223have&nbsp;the&nbsp;freedom&nbsp;to&nbsp;distribute&nbsp;copies&nbsp;of&nbsp;free&nbsp;software&nbsp;(and&nbsp;charge&nbsp;for<br>
224this&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>
225if&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>
226in&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>
227<br>
228&nbsp;&nbsp;To&nbsp;protect&nbsp;your&nbsp;rights,&nbsp;we&nbsp;need&nbsp;to&nbsp;make&nbsp;restrictions&nbsp;that&nbsp;forbid<br>
229anyone&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>
230These&nbsp;restrictions&nbsp;translate&nbsp;to&nbsp;certain&nbsp;responsibilities&nbsp;for&nbsp;you&nbsp;if&nbsp;you<br>
231distribute&nbsp;copies&nbsp;of&nbsp;the&nbsp;software,&nbsp;or&nbsp;if&nbsp;you&nbsp;modify&nbsp;it.<br>
232<br>
233&nbsp;&nbsp;For&nbsp;example,&nbsp;if&nbsp;you&nbsp;distribute&nbsp;copies&nbsp;of&nbsp;such&nbsp;a&nbsp;program,&nbsp;whether<br>
234gratis&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>
235you&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>
236source&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>
237rights.<br>
238<br>
239&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>
240(2)&nbsp;offer&nbsp;you&nbsp;this&nbsp;license&nbsp;which&nbsp;gives&nbsp;you&nbsp;legal&nbsp;permission&nbsp;to&nbsp;copy,<br>
241distribute&nbsp;and/or&nbsp;modify&nbsp;the&nbsp;software.<br>
242<br>
243&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>
244that&nbsp;everyone&nbsp;understands&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;warranty&nbsp;for&nbsp;this&nbsp;free<br>
245software.&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>
246want&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>
247that&nbsp;any&nbsp;problems&nbsp;introduced&nbsp;by&nbsp;others&nbsp;will&nbsp;not&nbsp;reflect&nbsp;on&nbsp;the&nbsp;original<br>
248authors'&nbsp;reputations.<br>
249<br>
250&nbsp;&nbsp;Finally,&nbsp;any&nbsp;free&nbsp;program&nbsp;is&nbsp;threatened&nbsp;constantly&nbsp;by&nbsp;software<br>
251patents.&nbsp;&nbsp;We&nbsp;wish&nbsp;to&nbsp;avoid&nbsp;the&nbsp;danger&nbsp;that&nbsp;redistributors&nbsp;of&nbsp;a&nbsp;free<br>
252program&nbsp;will&nbsp;individually&nbsp;obtain&nbsp;patent&nbsp;licenses,&nbsp;in&nbsp;effect&nbsp;making&nbsp;the<br>
253program&nbsp;proprietary.&nbsp;&nbsp;To&nbsp;prevent&nbsp;this,&nbsp;we&nbsp;have&nbsp;made&nbsp;it&nbsp;clear&nbsp;that&nbsp;any<br>
254patent&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>
255<br>
256&nbsp;&nbsp;The&nbsp;precise&nbsp;terms&nbsp;and&nbsp;conditions&nbsp;for&nbsp;copying,&nbsp;distribution&nbsp;and<br>
257modification&nbsp;follow.<br>
258<br>
259&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GNU&nbsp;GENERAL&nbsp;PUBLIC&nbsp;LICENSE<br>
260&nbsp;&nbsp;&nbsp;TERMS&nbsp;AND&nbsp;CONDITIONS&nbsp;FOR&nbsp;COPYING,&nbsp;DISTRIBUTION&nbsp;AND&nbsp;MODIFICATION<br>
261<br>
262&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>
263a&nbsp;notice&nbsp;placed&nbsp;by&nbsp;the&nbsp;copyright&nbsp;holder&nbsp;saying&nbsp;it&nbsp;may&nbsp;be&nbsp;distributed<br>
264under&nbsp;the&nbsp;terms&nbsp;of&nbsp;this&nbsp;General&nbsp;Public&nbsp;License.&nbsp;&nbsp;The&nbsp;&quot;Program&quot;,&nbsp;below,<br>
265refers&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>
266means&nbsp;either&nbsp;the&nbsp;Program&nbsp;or&nbsp;any&nbsp;derivative&nbsp;work&nbsp;under&nbsp;copyright&nbsp;law:<br>
267that&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>
268either&nbsp;verbatim&nbsp;or&nbsp;with&nbsp;modifications&nbsp;and/or&nbsp;translated&nbsp;into&nbsp;another<br>
269language.&nbsp;&nbsp;(Hereinafter,&nbsp;translation&nbsp;is&nbsp;included&nbsp;without&nbsp;limitation&nbsp;in<br>
270the&nbsp;term&nbsp;&quot;modification&quot;.)&nbsp;&nbsp;Each&nbsp;licensee&nbsp;is&nbsp;addressed&nbsp;as&nbsp;&quot;you&quot;.<br>
271<br>
272Activities&nbsp;other&nbsp;than&nbsp;copying,&nbsp;distribution&nbsp;and&nbsp;modification&nbsp;are&nbsp;not<br>
273covered&nbsp;by&nbsp;this&nbsp;License;&nbsp;they&nbsp;are&nbsp;outside&nbsp;its&nbsp;scope.&nbsp;&nbsp;The&nbsp;act&nbsp;of<br>
274running&nbsp;the&nbsp;Program&nbsp;is&nbsp;not&nbsp;restricted,&nbsp;and&nbsp;the&nbsp;output&nbsp;from&nbsp;the&nbsp;Program<br>
275is&nbsp;covered&nbsp;only&nbsp;if&nbsp;its&nbsp;contents&nbsp;constitute&nbsp;a&nbsp;work&nbsp;based&nbsp;on&nbsp;the<br>
276Program&nbsp;(independent&nbsp;of&nbsp;having&nbsp;been&nbsp;made&nbsp;by&nbsp;running&nbsp;the&nbsp;Program).<br>
277Whether&nbsp;that&nbsp;is&nbsp;true&nbsp;depends&nbsp;on&nbsp;what&nbsp;the&nbsp;Program&nbsp;does.<br>
278<br>
279&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>
280source&nbsp;code&nbsp;as&nbsp;you&nbsp;receive&nbsp;it,&nbsp;in&nbsp;any&nbsp;medium,&nbsp;provided&nbsp;that&nbsp;you<br>
281conspicuously&nbsp;and&nbsp;appropriately&nbsp;publish&nbsp;on&nbsp;each&nbsp;copy&nbsp;an&nbsp;appropriate<br>
282copyright&nbsp;notice&nbsp;and&nbsp;disclaimer&nbsp;of&nbsp;warranty;&nbsp;keep&nbsp;intact&nbsp;all&nbsp;the<br>
283notices&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>
284and&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>
285along&nbsp;with&nbsp;the&nbsp;Program.<br>
286<br>
287You&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>
288you&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>
289<br>
290&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>
291of&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>
292distribute&nbsp;such&nbsp;modifications&nbsp;or&nbsp;work&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;Section&nbsp;1<br>
293above,&nbsp;provided&nbsp;that&nbsp;you&nbsp;also&nbsp;meet&nbsp;all&nbsp;of&nbsp;these&nbsp;conditions:<br>
294<br>
295&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>
296&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>
297<br>
298&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>
299&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>
300&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>
301&nbsp;&nbsp;&nbsp;&nbsp;parties&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;this&nbsp;License.<br>
302<br>
303&nbsp;&nbsp;&nbsp;&nbsp;c)&nbsp;If&nbsp;the&nbsp;modified&nbsp;program&nbsp;normally&nbsp;reads&nbsp;commands&nbsp;interactively<br>
304&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>
305&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>
306&nbsp;&nbsp;&nbsp;&nbsp;announcement&nbsp;including&nbsp;an&nbsp;appropriate&nbsp;copyright&nbsp;notice&nbsp;and&nbsp;a<br>
307&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>
308&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;warranty)&nbsp;and&nbsp;that&nbsp;users&nbsp;may&nbsp;redistribute&nbsp;the&nbsp;program&nbsp;under<br>
309&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>
310&nbsp;&nbsp;&nbsp;&nbsp;License.&nbsp;&nbsp;(Exception:&nbsp;if&nbsp;the&nbsp;Program&nbsp;itself&nbsp;is&nbsp;interactive&nbsp;but<br>
311&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>
312&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;Program&nbsp;is&nbsp;not&nbsp;required&nbsp;to&nbsp;print&nbsp;an&nbsp;announcement.)<br>
313<br>
314These&nbsp;requirements&nbsp;apply&nbsp;to&nbsp;the&nbsp;modified&nbsp;work&nbsp;as&nbsp;a&nbsp;whole.&nbsp;&nbsp;If<br>
315identifiable&nbsp;sections&nbsp;of&nbsp;that&nbsp;work&nbsp;are&nbsp;not&nbsp;derived&nbsp;from&nbsp;the&nbsp;Program,<br>
316and&nbsp;can&nbsp;be&nbsp;reasonably&nbsp;considered&nbsp;independent&nbsp;and&nbsp;separate&nbsp;works&nbsp;in<br>
317themselves,&nbsp;then&nbsp;this&nbsp;License,&nbsp;and&nbsp;its&nbsp;terms,&nbsp;do&nbsp;not&nbsp;apply&nbsp;to&nbsp;those<br>
318sections&nbsp;when&nbsp;you&nbsp;distribute&nbsp;them&nbsp;as&nbsp;separate&nbsp;works.&nbsp;&nbsp;But&nbsp;when&nbsp;you<br>
319distribute&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>
320on&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>
321this&nbsp;License,&nbsp;whose&nbsp;permissions&nbsp;for&nbsp;other&nbsp;licensees&nbsp;extend&nbsp;to&nbsp;the<br>
322entire&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>
323<br>
324Thus,&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>
325your&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>
326exercise&nbsp;the&nbsp;right&nbsp;to&nbsp;control&nbsp;the&nbsp;distribution&nbsp;of&nbsp;derivative&nbsp;or<br>
327collective&nbsp;works&nbsp;based&nbsp;on&nbsp;the&nbsp;Program.<br>
328<br>
329In&nbsp;addition,&nbsp;mere&nbsp;aggregation&nbsp;of&nbsp;another&nbsp;work&nbsp;not&nbsp;based&nbsp;on&nbsp;the&nbsp;Program<br>
330with&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>
331a&nbsp;storage&nbsp;or&nbsp;distribution&nbsp;medium&nbsp;does&nbsp;not&nbsp;bring&nbsp;the&nbsp;other&nbsp;work&nbsp;under<br>
332the&nbsp;scope&nbsp;of&nbsp;this&nbsp;License.<br>
333<br>
334&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>
335under&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>
336Sections&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>
337<br>
338&nbsp;&nbsp;&nbsp;&nbsp;a)&nbsp;Accompany&nbsp;it&nbsp;with&nbsp;the&nbsp;complete&nbsp;corresponding&nbsp;machine-readable<br>
339&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>
340&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>
341<br>
342&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>
343&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>
344&nbsp;&nbsp;&nbsp;&nbsp;cost&nbsp;of&nbsp;physically&nbsp;performing&nbsp;source&nbsp;distribution,&nbsp;a&nbsp;complete<br>
345&nbsp;&nbsp;&nbsp;&nbsp;machine-readable&nbsp;copy&nbsp;of&nbsp;the&nbsp;corresponding&nbsp;source&nbsp;code,&nbsp;to&nbsp;be<br>
346&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>
347&nbsp;&nbsp;&nbsp;&nbsp;customarily&nbsp;used&nbsp;for&nbsp;software&nbsp;interchange;&nbsp;or,<br>
348<br>
349&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>
350&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;distribute&nbsp;corresponding&nbsp;source&nbsp;code.&nbsp;&nbsp;(This&nbsp;alternative&nbsp;is<br>
351&nbsp;&nbsp;&nbsp;&nbsp;allowed&nbsp;only&nbsp;for&nbsp;noncommercial&nbsp;distribution&nbsp;and&nbsp;only&nbsp;if&nbsp;you<br>
352&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>
353&nbsp;&nbsp;&nbsp;&nbsp;an&nbsp;offer,&nbsp;in&nbsp;accord&nbsp;with&nbsp;Subsection&nbsp;b&nbsp;above.)<br>
354<br>
355The&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>
356making&nbsp;modifications&nbsp;to&nbsp;it.&nbsp;&nbsp;For&nbsp;an&nbsp;executable&nbsp;work,&nbsp;complete&nbsp;source<br>
357code&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>
358associated&nbsp;interface&nbsp;definition&nbsp;files,&nbsp;plus&nbsp;the&nbsp;scripts&nbsp;used&nbsp;to<br>
359control&nbsp;compilation&nbsp;and&nbsp;installation&nbsp;of&nbsp;the&nbsp;executable.&nbsp;&nbsp;However,&nbsp;as&nbsp;a<br>
360special&nbsp;exception,&nbsp;the&nbsp;source&nbsp;code&nbsp;distributed&nbsp;need&nbsp;not&nbsp;include<br>
361anything&nbsp;that&nbsp;is&nbsp;normally&nbsp;distributed&nbsp;(in&nbsp;either&nbsp;source&nbsp;or&nbsp;binary<br>
362form)&nbsp;with&nbsp;the&nbsp;major&nbsp;components&nbsp;(compiler,&nbsp;kernel,&nbsp;and&nbsp;so&nbsp;on)&nbsp;of&nbsp;the<br>
363operating&nbsp;system&nbsp;on&nbsp;which&nbsp;the&nbsp;executable&nbsp;runs,&nbsp;unless&nbsp;that&nbsp;component<br>
364itself&nbsp;accompanies&nbsp;the&nbsp;executable.<br>
365<br>
366If&nbsp;distribution&nbsp;of&nbsp;executable&nbsp;or&nbsp;object&nbsp;code&nbsp;is&nbsp;made&nbsp;by&nbsp;offering<br>
367access&nbsp;to&nbsp;copy&nbsp;from&nbsp;a&nbsp;designated&nbsp;place,&nbsp;then&nbsp;offering&nbsp;equivalent<br>
368access&nbsp;to&nbsp;copy&nbsp;the&nbsp;source&nbsp;code&nbsp;from&nbsp;the&nbsp;same&nbsp;place&nbsp;counts&nbsp;as<br>
369distribution&nbsp;of&nbsp;the&nbsp;source&nbsp;code,&nbsp;even&nbsp;though&nbsp;third&nbsp;parties&nbsp;are&nbsp;not<br>
370compelled&nbsp;to&nbsp;copy&nbsp;the&nbsp;source&nbsp;along&nbsp;with&nbsp;the&nbsp;object&nbsp;code.<br>
371<br>
372&nbsp;&nbsp;4.&nbsp;You&nbsp;may&nbsp;not&nbsp;copy,&nbsp;modify,&nbsp;sublicense,&nbsp;or&nbsp;distribute&nbsp;the&nbsp;Program<br>
373except&nbsp;as&nbsp;expressly&nbsp;provided&nbsp;under&nbsp;this&nbsp;License.&nbsp;&nbsp;Any&nbsp;attempt<br>
374otherwise&nbsp;to&nbsp;copy,&nbsp;modify,&nbsp;sublicense&nbsp;or&nbsp;distribute&nbsp;the&nbsp;Program&nbsp;is<br>
375void,&nbsp;and&nbsp;will&nbsp;automatically&nbsp;terminate&nbsp;your&nbsp;rights&nbsp;under&nbsp;this&nbsp;License.<br>
376However,&nbsp;parties&nbsp;who&nbsp;have&nbsp;received&nbsp;copies,&nbsp;or&nbsp;rights,&nbsp;from&nbsp;you&nbsp;under<br>
377this&nbsp;License&nbsp;will&nbsp;not&nbsp;have&nbsp;their&nbsp;licenses&nbsp;terminated&nbsp;so&nbsp;long&nbsp;as&nbsp;such<br>
378parties&nbsp;remain&nbsp;in&nbsp;full&nbsp;compliance.<br>
379<br>
380&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>
381signed&nbsp;it.&nbsp;&nbsp;However,&nbsp;nothing&nbsp;else&nbsp;grants&nbsp;you&nbsp;permission&nbsp;to&nbsp;modify&nbsp;or<br>
382distribute&nbsp;the&nbsp;Program&nbsp;or&nbsp;its&nbsp;derivative&nbsp;works.&nbsp;&nbsp;These&nbsp;actions&nbsp;are<br>
383prohibited&nbsp;by&nbsp;law&nbsp;if&nbsp;you&nbsp;do&nbsp;not&nbsp;accept&nbsp;this&nbsp;License.&nbsp;&nbsp;Therefore,&nbsp;by<br>
384modifying&nbsp;or&nbsp;distributing&nbsp;the&nbsp;Program&nbsp;(or&nbsp;any&nbsp;work&nbsp;based&nbsp;on&nbsp;the<br>
385Program),&nbsp;you&nbsp;indicate&nbsp;your&nbsp;acceptance&nbsp;of&nbsp;this&nbsp;License&nbsp;to&nbsp;do&nbsp;so,&nbsp;and<br>
386all&nbsp;its&nbsp;terms&nbsp;and&nbsp;conditions&nbsp;for&nbsp;copying,&nbsp;distributing&nbsp;or&nbsp;modifying<br>
387the&nbsp;Program&nbsp;or&nbsp;works&nbsp;based&nbsp;on&nbsp;it.<br>
388<br>
389&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>
390Program),&nbsp;the&nbsp;recipient&nbsp;automatically&nbsp;receives&nbsp;a&nbsp;license&nbsp;from&nbsp;the<br>
391original&nbsp;licensor&nbsp;to&nbsp;copy,&nbsp;distribute&nbsp;or&nbsp;modify&nbsp;the&nbsp;Program&nbsp;subject&nbsp;to<br>
392these&nbsp;terms&nbsp;and&nbsp;conditions.&nbsp;&nbsp;You&nbsp;may&nbsp;not&nbsp;impose&nbsp;any&nbsp;further<br>
393restrictions&nbsp;on&nbsp;the&nbsp;recipients'&nbsp;exercise&nbsp;of&nbsp;the&nbsp;rights&nbsp;granted&nbsp;herein.<br>
394You&nbsp;are&nbsp;not&nbsp;responsible&nbsp;for&nbsp;enforcing&nbsp;compliance&nbsp;by&nbsp;third&nbsp;parties&nbsp;to<br>
395this&nbsp;License.<br>
396<br>
397&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>
398infringement&nbsp;or&nbsp;for&nbsp;any&nbsp;other&nbsp;reason&nbsp;(not&nbsp;limited&nbsp;to&nbsp;patent&nbsp;issues),<br>
399conditions&nbsp;are&nbsp;imposed&nbsp;on&nbsp;you&nbsp;(whether&nbsp;by&nbsp;court&nbsp;order,&nbsp;agreement&nbsp;or<br>
400otherwise)&nbsp;that&nbsp;contradict&nbsp;the&nbsp;conditions&nbsp;of&nbsp;this&nbsp;License,&nbsp;they&nbsp;do&nbsp;not<br>
401excuse&nbsp;you&nbsp;from&nbsp;the&nbsp;conditions&nbsp;of&nbsp;this&nbsp;License.&nbsp;&nbsp;If&nbsp;you&nbsp;cannot<br>
402distribute&nbsp;so&nbsp;as&nbsp;to&nbsp;satisfy&nbsp;simultaneously&nbsp;your&nbsp;obligations&nbsp;under&nbsp;this<br>
403License&nbsp;and&nbsp;any&nbsp;other&nbsp;pertinent&nbsp;obligations,&nbsp;then&nbsp;as&nbsp;a&nbsp;consequence&nbsp;you<br>
404may&nbsp;not&nbsp;distribute&nbsp;the&nbsp;Program&nbsp;at&nbsp;all.&nbsp;&nbsp;For&nbsp;example,&nbsp;if&nbsp;a&nbsp;patent<br>
405license&nbsp;would&nbsp;not&nbsp;permit&nbsp;royalty-free&nbsp;redistribution&nbsp;of&nbsp;the&nbsp;Program&nbsp;by<br>
406all&nbsp;those&nbsp;who&nbsp;receive&nbsp;copies&nbsp;directly&nbsp;or&nbsp;indirectly&nbsp;through&nbsp;you,&nbsp;then<br>
407the&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>
408refrain&nbsp;entirely&nbsp;from&nbsp;distribution&nbsp;of&nbsp;the&nbsp;Program.<br>
409<br>
410If&nbsp;any&nbsp;portion&nbsp;of&nbsp;this&nbsp;section&nbsp;is&nbsp;held&nbsp;invalid&nbsp;or&nbsp;unenforceable&nbsp;under<br>
411any&nbsp;particular&nbsp;circumstance,&nbsp;the&nbsp;balance&nbsp;of&nbsp;the&nbsp;section&nbsp;is&nbsp;intended&nbsp;to<br>
412apply&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>
413circumstances.<br>
414<br>
415It&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>
416patents&nbsp;or&nbsp;other&nbsp;property&nbsp;right&nbsp;claims&nbsp;or&nbsp;to&nbsp;contest&nbsp;validity&nbsp;of&nbsp;any<br>
417such&nbsp;claims;&nbsp;this&nbsp;section&nbsp;has&nbsp;the&nbsp;sole&nbsp;purpose&nbsp;of&nbsp;protecting&nbsp;the<br>
418integrity&nbsp;of&nbsp;the&nbsp;free&nbsp;software&nbsp;distribution&nbsp;system,&nbsp;which&nbsp;is<br>
419implemented&nbsp;by&nbsp;public&nbsp;license&nbsp;practices.&nbsp;&nbsp;Many&nbsp;people&nbsp;have&nbsp;made<br>
420generous&nbsp;contributions&nbsp;to&nbsp;the&nbsp;wide&nbsp;range&nbsp;of&nbsp;software&nbsp;distributed<br>
421through&nbsp;that&nbsp;system&nbsp;in&nbsp;reliance&nbsp;on&nbsp;consistent&nbsp;application&nbsp;of&nbsp;that<br>
422system;&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>
423to&nbsp;distribute&nbsp;software&nbsp;through&nbsp;any&nbsp;other&nbsp;system&nbsp;and&nbsp;a&nbsp;licensee&nbsp;cannot<br>
424impose&nbsp;that&nbsp;choice.<br>
425<br>
426This&nbsp;section&nbsp;is&nbsp;intended&nbsp;to&nbsp;make&nbsp;thoroughly&nbsp;clear&nbsp;what&nbsp;is&nbsp;believed&nbsp;to<br>
427be&nbsp;a&nbsp;consequence&nbsp;of&nbsp;the&nbsp;rest&nbsp;of&nbsp;this&nbsp;License.<br>
428<br>
429&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>
430certain&nbsp;countries&nbsp;either&nbsp;by&nbsp;patents&nbsp;or&nbsp;by&nbsp;copyrighted&nbsp;interfaces,&nbsp;the<br>
431original&nbsp;copyright&nbsp;holder&nbsp;who&nbsp;places&nbsp;the&nbsp;Program&nbsp;under&nbsp;this&nbsp;License<br>
432may&nbsp;add&nbsp;an&nbsp;explicit&nbsp;geographical&nbsp;distribution&nbsp;limitation&nbsp;excluding<br>
433those&nbsp;countries,&nbsp;so&nbsp;that&nbsp;distribution&nbsp;is&nbsp;permitted&nbsp;only&nbsp;in&nbsp;or&nbsp;among<br>
434countries&nbsp;not&nbsp;thus&nbsp;excluded.&nbsp;&nbsp;In&nbsp;such&nbsp;case,&nbsp;this&nbsp;License&nbsp;incorporates<br>
435the&nbsp;limitation&nbsp;as&nbsp;if&nbsp;written&nbsp;in&nbsp;the&nbsp;body&nbsp;of&nbsp;this&nbsp;License.<br>
436<br>
437&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>
438of&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>
439be&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>
440address&nbsp;new&nbsp;problems&nbsp;or&nbsp;concerns.<br>
441<br>
442Each&nbsp;version&nbsp;is&nbsp;given&nbsp;a&nbsp;distinguishing&nbsp;version&nbsp;number.&nbsp;&nbsp;If&nbsp;the&nbsp;Program<br>
443specifies&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>
444later&nbsp;version&quot;,&nbsp;you&nbsp;have&nbsp;the&nbsp;option&nbsp;of&nbsp;following&nbsp;the&nbsp;terms&nbsp;and&nbsp;conditions<br>
445either&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>
446Software&nbsp;Foundation.&nbsp;&nbsp;If&nbsp;the&nbsp;Program&nbsp;does&nbsp;not&nbsp;specify&nbsp;a&nbsp;version&nbsp;number&nbsp;of<br>
447this&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>
448Foundation.<br>
449<br>
450&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>
451programs&nbsp;whose&nbsp;distribution&nbsp;conditions&nbsp;are&nbsp;different,&nbsp;write&nbsp;to&nbsp;the&nbsp;author<br>
452to&nbsp;ask&nbsp;for&nbsp;permission.&nbsp;&nbsp;For&nbsp;software&nbsp;which&nbsp;is&nbsp;copyrighted&nbsp;by&nbsp;the&nbsp;Free<br>
453Software&nbsp;Foundation,&nbsp;write&nbsp;to&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation;&nbsp;we&nbsp;sometimes<br>
454make&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>
455of&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>
456of&nbsp;promoting&nbsp;the&nbsp;sharing&nbsp;and&nbsp;reuse&nbsp;of&nbsp;software&nbsp;generally.<br>
457<br>
458&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NO&nbsp;WARRANTY<br>
459<br>
460&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>
461FOR&nbsp;THE&nbsp;PROGRAM,&nbsp;TO&nbsp;THE&nbsp;EXTENT&nbsp;PERMITTED&nbsp;BY&nbsp;APPLICABLE&nbsp;LAW.&nbsp;&nbsp;EXCEPT&nbsp;WHEN<br>
462OTHERWISE&nbsp;STATED&nbsp;IN&nbsp;WRITING&nbsp;THE&nbsp;COPYRIGHT&nbsp;HOLDERS&nbsp;AND/OR&nbsp;OTHER&nbsp;PARTIES<br>
463PROVIDE&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>
464OR&nbsp;IMPLIED,&nbsp;INCLUDING,&nbsp;BUT&nbsp;NOT&nbsp;LIMITED&nbsp;TO,&nbsp;THE&nbsp;IMPLIED&nbsp;WARRANTIES&nbsp;OF<br>
465MERCHANTABILITY&nbsp;AND&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;THE&nbsp;ENTIRE&nbsp;RISK&nbsp;AS<br>
466TO&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>
467PROGRAM&nbsp;PROVE&nbsp;DEFECTIVE,&nbsp;YOU&nbsp;ASSUME&nbsp;THE&nbsp;COST&nbsp;OF&nbsp;ALL&nbsp;NECESSARY&nbsp;SERVICING,<br>
468REPAIR&nbsp;OR&nbsp;CORRECTION.<br>
469<br>
470&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>
471WILL&nbsp;ANY&nbsp;COPYRIGHT&nbsp;HOLDER,&nbsp;OR&nbsp;ANY&nbsp;OTHER&nbsp;PARTY&nbsp;WHO&nbsp;MAY&nbsp;MODIFY&nbsp;AND/OR<br>
472REDISTRIBUTE&nbsp;THE&nbsp;PROGRAM&nbsp;AS&nbsp;PERMITTED&nbsp;ABOVE,&nbsp;BE&nbsp;LIABLE&nbsp;TO&nbsp;YOU&nbsp;FOR&nbsp;DAMAGES,<br>
473INCLUDING&nbsp;ANY&nbsp;GENERAL,&nbsp;SPECIAL,&nbsp;INCIDENTAL&nbsp;OR&nbsp;CONSEQUENTIAL&nbsp;DAMAGES&nbsp;ARISING<br>
474OUT&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>
475TO&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>
476YOU&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>
477PROGRAMS),&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>
478POSSIBILITY&nbsp;OF&nbsp;SUCH&nbsp;DAMAGES.<br>
479<br>
480&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>
481<br>
482&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>
483<br>
484&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>
485possible&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>
486free&nbsp;software&nbsp;which&nbsp;everyone&nbsp;can&nbsp;redistribute&nbsp;and&nbsp;change&nbsp;under&nbsp;these&nbsp;terms.<br>
487<br>
488&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>
489to&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>
490convey&nbsp;the&nbsp;exclusion&nbsp;of&nbsp;warranty;&nbsp;and&nbsp;each&nbsp;file&nbsp;should&nbsp;have&nbsp;at&nbsp;least<br>
491the&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>
492<br>
493&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>
494&nbsp;&nbsp;&nbsp;&nbsp;Copyright&nbsp;(C)&nbsp;&lt;year&gt;&nbsp;&nbsp;&lt;name&nbsp;of&nbsp;author&gt;<br>
495<br>
496&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>
497&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>
498&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>
499&nbsp;&nbsp;&nbsp;&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
500<br>
501&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>
502&nbsp;&nbsp;&nbsp;&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
503&nbsp;&nbsp;&nbsp;&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
504&nbsp;&nbsp;&nbsp;&nbsp;GNU&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
505<br>
506&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>
507&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>
508&nbsp;&nbsp;&nbsp;&nbsp;51&nbsp;Franklin&nbsp;Street,&nbsp;Fifth&nbsp;Floor,&nbsp;Boston,&nbsp;MA&nbsp;02110-1301&nbsp;USA.<br>
509<br>
510Also&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>
511<br>
512If&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>
513when&nbsp;it&nbsp;starts&nbsp;in&nbsp;an&nbsp;interactive&nbsp;mode:<br>
514<br>
515&nbsp;&nbsp;&nbsp;&nbsp;Gnomovision&nbsp;version&nbsp;69,&nbsp;Copyright&nbsp;(C)&nbsp;year&nbsp;name&nbsp;of&nbsp;author<br>
516&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>
517&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>
518&nbsp;&nbsp;&nbsp;&nbsp;under&nbsp;certain&nbsp;conditions;&nbsp;type&nbsp;`show&nbsp;c'&nbsp;for&nbsp;details.<br>
519<br>
520The&nbsp;hypothetical&nbsp;commands&nbsp;`show&nbsp;w'&nbsp;and&nbsp;`show&nbsp;c'&nbsp;should&nbsp;show&nbsp;the&nbsp;appropriate<br>
521parts&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>
522be&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>
523mouse-clicks&nbsp;or&nbsp;menu&nbsp;items--whatever&nbsp;suits&nbsp;your&nbsp;program.<br>
524<br>
525You&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>
526school,&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>
527necessary.&nbsp;&nbsp;Here&nbsp;is&nbsp;a&nbsp;sample;&nbsp;alter&nbsp;the&nbsp;names:<br>
528<br>
529&nbsp;&nbsp;Yoyodyne,&nbsp;Inc.,&nbsp;hereby&nbsp;disclaims&nbsp;all&nbsp;copyright&nbsp;interest&nbsp;in&nbsp;the&nbsp;program<br>
530&nbsp;&nbsp;`Gnomovision'&nbsp;(which&nbsp;makes&nbsp;passes&nbsp;at&nbsp;compilers)&nbsp;written&nbsp;by&nbsp;James&nbsp;Hacker.<br>
531<br>
532&nbsp;&nbsp;&lt;signature&nbsp;of&nbsp;Ty&nbsp;Coon&gt;,&nbsp;1&nbsp;April&nbsp;1989<br>
533&nbsp;&nbsp;Ty&nbsp;Coon,&nbsp;President&nbsp;of&nbsp;Vice<br>
534<br>
535This&nbsp;General&nbsp;Public&nbsp;License&nbsp;does&nbsp;not&nbsp;permit&nbsp;incorporating&nbsp;your&nbsp;program&nbsp;into<br>
536proprietary&nbsp;programs.&nbsp;&nbsp;If&nbsp;your&nbsp;program&nbsp;is&nbsp;a&nbsp;subroutine&nbsp;library,&nbsp;you&nbsp;may<br>
537consider&nbsp;it&nbsp;more&nbsp;useful&nbsp;to&nbsp;permit&nbsp;linking&nbsp;proprietary&nbsp;applications&nbsp;with&nbsp;the<br>
538library.&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>
539Public&nbsp;License&nbsp;instead&nbsp;of&nbsp;this&nbsp;License.<br>
540</span></code>
541<hr>Input File: ../omh/license.omh
542
543<hr>
544<center><b><big><big><a name="3" id="3">3: The Nonlinear Constrained Kalman-Bucy Smoother</a>
545</big></big></b></center>
546<br>
547<b><big><a name="3.a" id="3.a">3.a: Syntax</a></big></b>
548
549<br>
550<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>
551&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>
552
553<br>
554<br>
555<b><big><a name="3.b" id="3.b">3.b: Purpose</a></big></b>
556<br>
557This routine minimizes the
558Kalman-Bucy smoother residual sum of squares objective
559for a general nonlinear model functions
560(in the case where the model functions are affine, the routine
561<a href="#4">4: <span style='white-space: nowrap'>ckbs_affine</span></a>
562 is more efficient).
563
564<br>
565<br>
566<b><big><a name="3.c" id="3.c">3.c: Notation</a></big></b>
567<br>
568The Kalman-Bucy smoother residual sum of squares is defined by
569<code>
570<span style='white-space: nowrap'>&nbsp;\[<br>
571\begin{array}{rcl}<br>
572S&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>
573S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
574\frac{1}{2}&nbsp;<br>
575[&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>
576\\<br>
577&amp;&nbsp;+&nbsp;&amp;<br>
578\frac{1}{2}&nbsp;<br>
579[&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>
580\\<br>
581\end{array}<br>
582\]&nbsp;</span></code>
583
584where the matrices <code>
585<span style='white-space: nowrap'>&nbsp;R_k</span></code>
586 and <code>
587<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
588 are
589symmetric positive definite and
590<code>
591<span style='white-space: nowrap'>&nbsp;x_0</span></code>
592 is the constant zero.
593Note that <code>
594<span style='white-space: nowrap'>&nbsp;g_1&nbsp;(&nbsp;x_0&nbsp;)</span></code>
595 is the initial state estimate
596and <code>
597<span style='white-space: nowrap'>&nbsp;Q_1</span></code>
598 is the corresponding covariance.
599
600<br>
601<br>
602<b><big><a name="3.d" id="3.d">3.d: Problem</a></big></b>
603<br>
604Our constrained Kalman-Bucy smoother problem is
605<code>
606<span style='white-space: nowrap'>&nbsp;\[<br>
607\begin{array}{rll}<br>
608{\rm&nbsp;minimize}&nbsp;<br>
609&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;S(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;<br>
610&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>
611\\<br>
612{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;<br>
613&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;f_k(x_k)&nbsp;\leq&nbsp;0&nbsp;<br>
614&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;{\rm&nbsp;for}&nbsp;\;&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N<br>
615\end{array}<br>
616\]&nbsp;</span></code>
617
618
619<br>
620<br>
621<b><big><a name="3.e" id="3.e">3.e: First Order Conditions</a></big></b>
622<br>
623A state sequence <code>
624<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
625 is considered a solution
626if there is a Lagrange multiplier sequence <code>
627<span style='white-space: nowrap'>&nbsp;(&nbsp;u_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;u_N&nbsp;)</span></code>
628 
629such that the following conditions are satisfied for
630<code>
631<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
632 and <code>
633<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
634:
635<code>
636<span style='white-space: nowrap'>&nbsp;\[<br>
637\begin{array}{rcl}<br>
638f_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>
6390&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>
640|&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>
641&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>
642|&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>
643\end{array}<br>
644\]&nbsp;</span></code>
645
646Here the notation
647<code>
648<span style='white-space: nowrap'>&nbsp;\partial_k</span></code>
649 is used for the partial derivative of
650with respect to <code>
651<span style='white-space: nowrap'>&nbsp;x_k</span></code>
652 and the notation
653<code>
654<span style='white-space: nowrap'>&nbsp;(u_k)_i</span></code>
655 denotes the <i>i</i>-th component of <code>
656<span style='white-space: nowrap'>&nbsp;u_k</span></code>
657.
658
659<br>
660<br>
661<b><big><a name="3.f" id="3.f">3.f: f_fun</a></big></b>
662<br>
663The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>f_fun</i> 
664is a function that supports both of the
665following syntaxes
666<code><font color="blue"><span style='white-space: nowrap'><br>
667&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>
668&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>
669</span></font></code>In the case where there are no constraints,
670one can use the following function for <i>f_fun</i>:
671<code><font color='blue'><pre style='display:inline'> 
672        [fk, Fk] = f_fun(k, xk)
673        n  = size(xk, 1);
674        fk = -1;
675        Fk =  zeros(1, n);
676        return
677        end
678</pre></font></code>
679
680
681<br>
682<br>
683<b><a name="3.f.a" id="3.f.a">3.f.a: k</a></b>
684<br>
685The <i>f_fun</i> argument <i>k</i> is an integer with
686<code>
687<span style='white-space: nowrap'>&nbsp;1&nbsp;\leq&nbsp;k&nbsp;\leq&nbsp;N</span></code>
688.
689
690<br>
691<br>
692<b><a name="3.f.b" id="3.f.b">3.f.b: xk</a></b>
693<br>
694The <i>f_fun</i> argument <i>xk</i> is an column vector with
695length <code>
696<span style='white-space: nowrap'>&nbsp;n</span></code>
697. It specifies the state vector at time index <i>k</i>
698<code>
699<span style='white-space: nowrap'>&nbsp;\[<br>
700&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xk&nbsp;=&nbsp;x_k<br>
701\]&nbsp;</span></code>
702.
703
704<br>
705<br>
706<b><a name="3.f.c" id="3.f.c">3.f.c: fk</a></b>
707<br>
708The <i>f_fun</i> result <i>fk</i> is an column vector with
709length <code>
710<span style='white-space: nowrap'>&nbsp;\ell</span></code>
711 and
712<code>
713<span style='white-space: nowrap'>&nbsp;\[<br>
714&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fk&nbsp;=&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
715\]&nbsp;</span></code>
716
717
718<br>
719<br>
720<b><a name="3.f.d" id="3.f.d">3.f.d: Fk</a></b>
721<br>
722If the <i>f_fun</i> result <i>Fk</i> is present in the syntax,
723it is the <code>
724<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;n</span></code>
725 matrix given by
726and
727<code>
728<span style='white-space: nowrap'>&nbsp;\[<br>
729&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fk&nbsp;=&nbsp;\partial_k&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
730\]&nbsp;</span></code>
731
732
733<br>
734<br>
735<b><big><a name="3.g" id="3.g">3.g: g_fun</a></big></b>
736<br>
737The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>g_fun</i> 
738is a function that supports both of
739the following syntaxes
740<code><font color="blue"><span style='white-space: nowrap'><br>
741&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>
742&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>
743</span></font></code><br>
744<b><a name="3.g.a" id="3.g.a">3.g.a: k</a></b>
745<br>
746The <i>g_fun</i> argument <i>k</i> is an integer with
747<code>
748<span style='white-space: nowrap'>&nbsp;1&nbsp;\leq&nbsp;k&nbsp;\leq&nbsp;N</span></code>
749.
750The case <code>
751<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
752 serves to specify the initial state estimate.
753
754<br>
755<br>
756<b><a name="3.g.b" id="3.g.b">3.g.b: xk1</a></b>
757<br>
758The <i>g_fun</i> argument <i>xk1</i> is an column vector with
759length <code>
760<span style='white-space: nowrap'>&nbsp;n</span></code>
761. It specifies the state vector at time index <i>k</i>
762<code>
763<span style='white-space: nowrap'>&nbsp;\[<br>
764&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xk1&nbsp;=&nbsp;x_{k-1}<br>
765\]&nbsp;</span></code>
766.
767In the case <code>
768<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
769, the value of <i>xk1</i> does not matter.
770
771<br>
772<br>
773<b><a name="3.g.c" id="3.g.c">3.g.c: gk</a></b>
774<br>
775The <i>g_fun</i> result <i>gk</i> is an column vector with
776length <code>
777<span style='white-space: nowrap'>&nbsp;n</span></code>
778 and
779<code>
780<span style='white-space: nowrap'>&nbsp;\[<br>
781&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gk&nbsp;=&nbsp;g_k&nbsp;(&nbsp;x_{k-1}&nbsp;)&nbsp;<br>
782\]&nbsp;</span></code>
783
784In the case <code>
785<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
786, the value of <i>gk</i> is the initial state
787estimate at time index <i>k</i>.
788
789<br>
790<br>
791<b><a name="3.g.d" id="3.g.d">3.g.d: Gk</a></b>
792<br>
793If the <i>g_fun</i> result <i>Gk</i> is present in the syntax,
794it is the <code>
795<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
796 matrix given by
797and
798<code>
799<span style='white-space: nowrap'>&nbsp;\[<br>
800&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gk&nbsp;=&nbsp;\partial_{k-1}&nbsp;g_k&nbsp;(&nbsp;x_{k-1}&nbsp;)&nbsp;<br>
801\]&nbsp;</span></code>
802
803In the case <code>
804<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
805, the value of <i>Gk</i> is the zero matrix;
806i.e., <code>
807<span style='white-space: nowrap'>&nbsp;g_k</span></code>
808 does not depend on the value of <code>
809<span style='white-space: nowrap'>&nbsp;x_{k-1}</span></code>
810.
811
812<br>
813<br>
814<b><big><a name="3.h" id="3.h">3.h: h_fun</a></big></b>
815<br>
816The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>h_fun</i> 
817is a function that supports both of the
818following syntaxes
819<code><font color="blue"><span style='white-space: nowrap'><br>
820&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>
821&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>
822</span></font></code><br>
823<b><a name="3.h.a" id="3.h.a">3.h.a: k</a></b>
824<br>
825The <i>h_fun</i> argument <i>k</i> is an integer with
826<code>
827<span style='white-space: nowrap'>&nbsp;1&nbsp;\leq&nbsp;k&nbsp;\leq&nbsp;N</span></code>
828.
829
830<br>
831<br>
832<b><a name="3.h.b" id="3.h.b">3.h.b: xk</a></b>
833<br>
834The <i>h_fun</i> argument <i>xk</i> is an column vector with
835length <code>
836<span style='white-space: nowrap'>&nbsp;n</span></code>
837. It specifies the state vector at time index <i>k</i>
838<code>
839<span style='white-space: nowrap'>&nbsp;\[<br>
840&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xk&nbsp;=&nbsp;x_k<br>
841\]&nbsp;</span></code>
842.
843
844<br>
845<br>
846<b><a name="3.h.c" id="3.h.c">3.h.c: hk</a></b>
847<br>
848The <i>h_fun</i> result <i>hk</i> is an column vector with
849length <code>
850<span style='white-space: nowrap'>&nbsp;m</span></code>
851 and
852<code>
853<span style='white-space: nowrap'>&nbsp;\[<br>
854&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hk&nbsp;=&nbsp;h_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
855\]&nbsp;</span></code>
856
857
858<br>
859<br>
860<b><a name="3.h.d" id="3.h.d">3.h.d: Hk</a></b>
861<br>
862If the <i>h_fun</i> result <i>Hk</i> is present in the syntax,
863it is the <code>
864<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n</span></code>
865 matrix given by
866and
867<code>
868<span style='white-space: nowrap'>&nbsp;\[<br>
869&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hk&nbsp;=&nbsp;\partial_k&nbsp;h_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;<br>
870\]&nbsp;</span></code>
871
872
873<br>
874<br>
875<b><big><a name="3.i" id="3.i">3.i: max_itr</a></big></b>
876<br>
877The integer scalar <i>max_itr</i> specifies the maximum number of
878iterations of the algorithm to execute. It must be greater than or
879equal to zero. Note that if it is zero, the first row of the
880<a href="#3.r">3.r: <span style='white-space: nowrap'>info</span></a>
881 return value will still be computed.
882This can be useful for deciding what is a good value for the argument
883<a href="#3.j">3.j: <span style='white-space: nowrap'>epsilon</span></a>
884.
885
886<br>
887<br>
888<b><big><a name="3.j" id="3.j">3.j: epsilon</a></big></b>
889<br>
890The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>epsilon</i> is a positive scalar.
891It specifies the convergence
892criteria value; i.e.,
893<code>
894<span style='white-space: nowrap'>&nbsp;\[<br>
895&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\varepsilon&nbsp;=&nbsp;epsilon<br>
896\]&nbsp;</span></code>
897
898In some instances, <code><font color="blue">ckbs_nonlinear</font></code> will return after printing
899a warning without convergence; see <a href="#3.r">3.r: <span style='white-space: nowrap'>info</span></a>
900.
901
902<br>
903<br>
904<b><big><a name="3.k" id="3.k">3.k: x_in</a></big></b>
905<br>
906The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>x_in</i> 
907is a two dimensional array with size <code>
908<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
909.
910It specifies a sequence of state values; i.e.,
911for <code>
912<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
913
914<code>
915<span style='white-space: nowrap'>&nbsp;\[<br>
916&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x\_in&nbsp;(:,&nbsp;k)&nbsp;=&nbsp;x_k<br>
917\]&nbsp;</span></code>
918
919The closer the initial state sequence is to the solution
920the faster, and more likely, the <code><font color="blue">ckbs_nonlinear</font></code> will converge.
921The initial state sequence need not be feasible; i.e.
922it is not necessary that
923<code>
924<span style='white-space: nowrap'>&nbsp;\[<br>
925&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f_k&nbsp;(&nbsp;x_k&nbsp;)&nbsp;\leq&nbsp;0<br>
926\]&nbsp;</span></code>
927
928for all <code>
929<span style='white-space: nowrap'>&nbsp;k</span></code>
930.
931
932<br>
933<br>
934<b><big><a name="3.l" id="3.l">3.l: z</a></big></b>
935<br>
936The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>z</i> is a two dimensional array
937with size <code>
938<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
939.
940It specifies the sequence of measurement vectors; i.e.,
941for <code>
942<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
943
944<code>
945<span style='white-space: nowrap'>&nbsp;\[<br>
946&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z(:,&nbsp;k)&nbsp;=&nbsp;z_k<br>
947\]</span></code>
948
949
950<br>
951<br>
952<b><big><a name="3.m" id="3.m">3.m: qinv</a></big></b>
953<br>
954The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>qinv</i> 
955is a three dimensional array
956with size <code>
957<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
958.
959It specifies the inverse of the variance of the measurement noise; i.e.,
960for <code>
961<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
962
963<code>
964<span style='white-space: nowrap'>&nbsp;\[<br>
965&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;qinv(:,:,&nbsp;k)&nbsp;=&nbsp;Q_k^{-1}<br>
966\]</span></code>
967
968In the case <code>
969<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1</span></code>
970, the value of <code>
971<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
972 is the variance
973of the initial state estimate (see <a href="#3.g">3.g: <span style='white-space: nowrap'>g_fun</span></a>
974.
975
976<br>
977<br>
978<b><big><a name="3.n" id="3.n">3.n: rinv</a></big></b>
979<br>
980The <code><font color="blue">ckbs_nonlinear</font></code> argument <i>rinv</i> 
981is a three dimensional array,
982with size <code>
983<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
984.
985it specifies the inverse of the variance of the transition noise; i.e.,
986for <code>
987<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
988
989<code>
990<span style='white-space: nowrap'>&nbsp;\[<br>
991&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rinv(:,:,&nbsp;k)&nbsp;=&nbsp;R_k^{-1}<br>
992\]</span></code>
993
994It is ok to signify a missing data value by setting the corresponding
995row and column of <i>rinv</i> to zero. This also enables use
996to interpolate the state vector <code>
997<span style='white-space: nowrap'>&nbsp;x_k</span></code>
998 to points where
999there are no measurements.
1000
1001<br>
1002<br>
1003<b><big><a name="3.o" id="3.o">3.o: level</a></big></b>
1004<br>
1005The integer scalar <i>level</i> specifies the level of tracing to do.
1006If <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.
1007If <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>
1008and the correspond row of <i>info</i> 
1009are printed as soon as soon as they are computed.
1010If <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
1011is printed before the calculations start. In this case, control will
1012return to the keyboard so that you can print values, continue,
1013or abort the calculation.
1014
1015<br>
1016<br>
1017<b><big><a name="3.p" id="3.p">3.p: x_out</a></big></b>
1018<br>
1019The result <i>x_out</i> 
1020is a two dimensional array with size <code>
1021<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
1022.
1023<code>
1024<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
1025.
1026It contains an approximation for the optimal sequence; i.e.,
1027for <code>
1028<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1029
1030<code>
1031<span style='white-space: nowrap'>&nbsp;\[<br>
1032&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x\_out(:,&nbsp;k)&nbsp;=&nbsp;x_k<br>
1033\]</span></code>
1034
1035
1036<br>
1037<br>
1038<b><big><a name="3.q" id="3.q">3.q: u_out</a></big></b>
1039<br>
1040The result <i>u_out</i> 
1041is a two dimensional array with size % <code>
1042<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;N</span></code>
1043.
1044It contains the Lagrange multiplier sequence
1045corresponding to <i>x_out</i>; i.e.,
1046for <code>
1047<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1048
1049<code>
1050<span style='white-space: nowrap'>&nbsp;\[<br>
1051&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u\_out(:,&nbsp;k)&nbsp;=&nbsp;u_k<br>
1052\]</span></code>
1053
1054The pair <i>x_out</i>, <i>u_out</i> satisfy the
1055<a href="#3.e">3.e: <span style='white-space: nowrap'>first&nbsp;order&nbsp;conditions</span></a>
1056.
1057
1058<br>
1059<br>
1060<b><big><a name="3.r" id="3.r">3.r: info</a></big></b>
1061<br>
1062The result <i>info</i> is a matrix with each row corresponding
1063to an iteration of the algorithm.
1064Note that <code><font color="blue">ckbs_nonlinear</font></code> has satisfied the convergence condition if
1065and only if
1066<code><font color="blue"><span style='white-space: nowrap'><br>
1067&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>
1068</span></font></code><code><span style='white-space: nowrap'><br>
1069<br>
1070</span></code>We use <code>
1071<span style='white-space: nowrap'>&nbsp;\{&nbsp;x_k^q&nbsp;\}</span></code>
1072 to denote the state vector sequence at the
1073at the end of iteration <code>
1074<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1075 and
1076<code>
1077<span style='white-space: nowrap'>&nbsp;\{&nbsp;u_k^q&nbsp;\}</span></code>
1078 for the dual vector sequence (<code>
1079<span style='white-space: nowrap'>&nbsp;u_k^q&nbsp;\geq&nbsp;0</span></code>
1080).
1081
1082<br>
1083<br>
1084<b><a name="3.r.a" id="3.r.a">3.r.a: max_f</a></b>
1085<br>
1086The value
1087<code><font color="blue"><span style='white-space: nowrap'><br>
1088&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>
1089</span></font></code>is a bound on the constraint functions
1090at the end of iteration <i>q-1</i>. To be specific
1091<code>
1092<span style='white-space: nowrap'>&nbsp;\[<br>
1093&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>
1094\]&nbsp;</span></code>
1095
1096where the maximum is with respect to
1097<code>
1098<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
1099 and
1100<code>
1101<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1102.
1103Convergence requires this value to be less than or equal <i>epsilon</i>.
1104
1105<br>
1106<br>
1107<b><a name="3.r.b" id="3.r.b">3.r.b: max_grad</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_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>
1112</span></font></code>is a bound on the partial of the
1113Lagrangian with respect to <code>
1114<span style='white-space: nowrap'>&nbsp;x</span></code>
1115
1116at the end of iteration <i>q-1</i>. To be specific
1117<code>
1118<span style='white-space: nowrap'>&nbsp;\[<br>
1119max\_grad(q)&nbsp;=&nbsp;\max_{j,&nbsp;k}&nbsp;\left[&nbsp;\left|<br>
1120(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>
1121\right|&nbsp;\right]_j<br>
1122\]&nbsp;</span></code>
1123
1124where the maximum is with respect to
1125<code>
1126<span style='white-space: nowrap'>&nbsp;j&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;n</span></code>
1127 and
1128<code>
1129<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1130.
1131This value should converge to zero.
1132
1133<br>
1134<br>
1135<b><a name="3.r.c" id="3.r.c">3.r.c: max_fu</a></b>
1136<br>
1137The value
1138<code><font color="blue"><span style='white-space: nowrap'><br>
1139&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>
1140</span></font></code>is a bound on
1141the complementarity conditions
1142at the end of iteration <i>q-1</i>. To be specific
1143<code>
1144<span style='white-space: nowrap'>&nbsp;\[<br>
1145max\_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>
1146\]&nbsp;</span></code>
1147
1148where the maximum is with respect to
1149<code>
1150<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
1151 and
1152<code>
1153<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
1154.
1155This value should converge to be less than or equal zero.
1156
1157<br>
1158<br>
1159<b><a name="3.r.d" id="3.r.d">3.r.d: obj_cur</a></b>
1160<br>
1161The value
1162<code><font color="blue"><span style='white-space: nowrap'><br>
1163&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>
1164</span></font></code>is the value of the objective function
1165at the end of <code>
1166<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1167; i.e.,
1168<code>
1169<span style='white-space: nowrap'>&nbsp;\[<br>
1170&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>
1171\]&nbsp;</span></code>
1172
1173(Note that <code>
1174<span style='white-space: nowrap'>&nbsp;info(1,&nbsp;4)%</span></code>
1175 is the value of the objective
1176corresponding to <i>x_in</i>.
1177
1178<br>
1179<br>
1180<b><a name="3.r.e" id="3.r.e">3.r.e: lambda</a></b>
1181<br>
1182The value
1183<code><font color="blue"><span style='white-space: nowrap'><br>
1184&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>
1185</span></font></code>is the line search step size used during
1186iteration <code>
1187<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1188 of <code><font color="blue">ckbs_nonlinear</font></code>.
1189If the problem is nearly affine (if the affine approximate is accurate)
1190this will be one.
1191Much small step sizes indicate highly non-affine problems
1192(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).
1193
1194<br>
1195<br>
1196<b><a name="3.r.f" id="3.r.f">3.r.f: lam_aff</a></b>
1197<br>
1198The value
1199<code><font color="blue"><span style='white-space: nowrap'><br>
1200&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>
1201</span></font></code>is the minimum line search step size
1202while solving the affine sub-problem that corresponds to
1203iteration <code>
1204<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1205 of <code><font color="blue">ckbs_nonlinear</font></code>.
1206If the sub-problem solution is working well,
1207this will be one.
1208Much small step sizes indicate the sub-problem solution is not working well.
1209
1210
1211
1212<br>
1213<br>
1214<b><a name="3.r.g" id="3.r.g">3.r.g: Penalty Parameter</a></b>
1215<br>
1216The exact penalty function
1217<code>
1218<span style='white-space: nowrap'>&nbsp;\[<br>
1219&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;S(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_k&nbsp;)&nbsp;<br>
1220&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>
1221\]&nbsp;</span></code>
1222
1223is used to determine the line search step size.
1224The 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
1225<code>
1226<span style='white-space: nowrap'>&nbsp;\alpha</span></code>
1227 during iteration <code>
1228<span style='white-space: nowrap'>&nbsp;q-1</span></code>
1229 of <code><font color="blue">ckbs_nonlinear</font></code>.
1230
1231<br>
1232<br>
1233<b><big><a name="3.s" id="3.s">3.s: Example</a></big></b>
1234
1235
1236<br>
1237<br>
1238<b><a name="3.s.a" id="3.s.a">3.s.a: Simple</a></b>
1239<br>
1240The file <a href="#3.1">3.1: <span style='white-space: nowrap'>nonlinear_ok_simple.m</span></a>
1241 contains a simple example
1242and test of <code><font color="blue">ckbs_nonlinear</font></code>.
1243It returns true if <code><font color="blue">ckbs_nonlinear</font></code> passes the tests
1244and false otherwise.
1245
1246<br>
1247<br>
1248<b><a name="3.s.b" id="3.s.b">3.s.b: Box Constraints</a></b>
1249<br>
1250The file <a href="#3.2">3.2: <span style='white-space: nowrap'>nonlinear_ok_box.m</span></a>
1251 contains an example
1252and test of <code><font color="blue">ckbs_nonlinear</font></code> with box constraints
1253and a nonlinear measurement function.
1254It returns true if <code><font color="blue">ckbs_nonlinear</font></code> passes the tests
1255and false otherwise.
1256
1257<br>
1258<br>
1259<b><a name="3.s.c" id="3.s.c">3.s.c: Nonlinear Constraints</a></b>
1260<br>
1261The file <a href="#3.3">3.3: <span style='white-space: nowrap'>nonlinear_ok_sin.m</span></a>
1262 contains an example
1263and test of <code><font color="blue">ckbs_nonlinear</font></code> with a sine wave constraint
1264and a nonlinear measurement function.
1265It returns true if <code><font color="blue">ckbs_nonlinear</font></code> passes the tests
1266and false otherwise.
1267
1268
1269
1270<hr>Input File: ../src/ckbs_nonlinear.m
1271
1272<hr>
1273 
1274
1275
1276<center><b><big><big><a name="3.1" id="3.1">3.1: Simple ckbs_nonlinear Example and Test</a>
1277</big></big></b></center>
1278<br>
1279<b><big><a name="3.1.a" id="3.1.a">3.1.a: Call Back Functions</a></big></b>
1280
1281<table><tr><td align='left'  valign='top'>
1282
1283<a href="#3.1.1">3.1.1: nonlinear_ok_simple_f.m</a></td><td>
1284Example Constraint Function: nonlinear_ok_simple_f</td></tr>
1285<tr><td>
1286
1287<a href="#3.1.2">3.1.2: nonlinear_ok_simple_g.m</a></td><td>
1288Example Transition Function: nonlinear_ok_simple_g</td></tr>
1289<tr><td>
1290
1291<a href="#3.1.3">3.1.3: nonlinear_ok_simple_h.m</a></td><td>
1292Example Measurement Function: nonlinear_ok_simple_h</td></tr>
1293<tr><td>
1294
1295</td></tr>
1296</table>
1297<br>
1298<b><big><a name="3.1.b" id="3.1.b">3.1.b: Source Code</a></big></b>
1299
1300 <code><font color='blue'><pre style='display:inline'> 
1301function [ok] = nonlinear_ok_simple()
1302% --------------------------------------------------------------------
1303max_itr = 20;      % maximum number of iterations
1304epsilon = 1e-5;    % convergence criteria
1305N       = 3;       % number of time points
1306ell     = 2;       % number of constraints
1307m       = 1;       % number of measurements per time point
1308n       = 3;       % number of state vector components per time point
1309sigma   = 1;       % variance of measurement noise
1310level   = 0;       % level of tracing in ckbs_nonlinear
1311%
1312% simulated true trajectory
1313x_true  = ones(n, 1) * (1 : N);
1314%
1315% simulate measurement noise
1316e_true  = zeros(m, N);
1317%
1318% initial x vector
1319x_in = zeros(n, N);
1320%
1321% --------------------------------------------------------------------
1322if m &gt; n
1323        error('nonlinear_ok_simple: m &gt; n');
1324end
1325if ell &gt; n
1326        error('nonlinear_ok_simple: ell &gt; n');
1327end
1328%
1329global nonlinear_ok_simple_m
1330global nonlinear_ok_simple_ell
1331global nonlinear_ok_simple_N
1332%
1333nonlinear_ok_simple_m   = m;
1334nonlinear_ok_simple_ell = ell;
1335nonlinear_ok_simple_N   = N;
1336%
1337% measurement variances
1338rinv    = zeros(m, m, N);
1339qinv    = zeros(n, n, N);
1340qinvk   = eye(n) / (sigma * sigma);
1341rinvk   = eye(m) / (sigma * sigma);
1342z       = zeros(m, N);
1343for k = 1 : N
1344        xk           = x_true(:, k);
1345        ek           = e_true(:, k);
1346        hk           = nonlinear_ok_simple_h(k, xk);
1347        z(:, k)      = hk + ek;
1348        qinv(:,:, k) = qinvk;
1349        rinv(:,:, k) = rinvk;
1350end
1351%
1352% pass the maximum state value to f
1353global nonlinear_ok_simple_f_max
1354nonlinear_ok_simple_f_max = (N - .5) * ones(m, 1);
1355%
1356% ----------------------------------------------------------------------
1357f_fun = 'nonlinear_ok_simple_f';
1358g_fun = 'nonlinear_ok_simple_g';
1359h_fun = 'nonlinear_ok_simple_h';
1360[x_out, u_out, info] = ckbs_nonlinear( ...
1361        f_fun,    ...
1362        g_fun,    ...
1363        h_fun,    ...
1364        max_itr,  ...
1365        epsilon,  ...
1366        x_in,     ...
1367        z,        ...
1368        qinv,     ...
1369        rinv,     ...
1370        level     ...
1371);
1372% ----------------------------------------------------------------------
1373ok     = size(info, 1) &lt;= max_itr;
1374f_out  = zeros(ell, N);
1375g_out  = zeros(n,   N);
1376h_out  = zeros(m,   N);
1377df_out = zeros(ell, n, N);
1378dg_out = zeros(n, n,   N);
1379dh_out = zeros(m, n,   N);
1380xk1    = zeros(n, 1);
1381for k = 1 : N
1382        xk       = x_out(:, k);
1383        uk       = u_out(:, k);
1384        [fk, Fk] = feval(f_fun, k, xk);
1385        [gk, Gk] = feval(g_fun, k, xk1);
1386        [hk, Hk] = feval(h_fun, k, xk);
1387        %
1388        ok       = ok &amp; all( fk &lt;= epsilon);
1389        ok       = ok &amp; all( abs(fk) .* uk &lt;= epsilon );
1390        %
1391        f_out(:, k) = fk - Fk * xk;
1392        g_out(:, k) = gk - Gk * xk1;
1393        h_out(:, k) = hk - Hk * xk;
1394        df_out(:,:, k) = Fk;
1395        dg_out(:,:, k) = Gk;
1396        dh_out(:,:, k) = Hk;
1397        xk1 = xk;
1398end
1399ok   = ok &amp; all( all( u_out &gt;= 0 ) );
1400grad  = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
1401for k = 1 : N
1402        uk  = u_out(:, k);
1403        Fk  = df_out(:,:, k);
1404        dk  = grad(:, k);
1405        %
1406        ok  = ok &amp; all( abs(Fk' * uk + dk) &lt;= epsilon );
1407end
1408return
1409end
1410</pre></font></code>
1411 
1412
1413<hr>Input File: ../test/nonlinear_ok_simple.m
1414
1415<hr>
1416 
1417
1418
1419
1420<center><b><big><big><a name="3.1.1" id="3.1.1">3.1.1: Example Constraint Function: nonlinear_ok_simple_f</a>
1421</big></big></b></center>
1422<br>
1423<b><big><a name="3.1.1.a" id="3.1.1.a">3.1.1.a: Source Code</a></big></b>
1424
1425 <code><font color='blue'><pre style='display:inline'> 
1426function [fk, Fk] = nonlinear_ok_simple_f(k, xk)
1427        global nonlinear_ok_simple_N
1428        global nonlinear_ok_simple_ell
1429        %
1430        N   = nonlinear_ok_simple_N;
1431        ell = nonlinear_ok_simple_ell;
1432        n   = size(xk, 1);
1433        % xk(1:ell)^2 &lt;= N - .5
1434        fk = xk(1:ell).^2 - (N - .5);
1435        Fk = zeros(ell, n);
1436        for i = 1 : ell
1437                Fk(i, i) = 2 * xk(i);
1438        end
1439        return
1440end
1441</pre></font></code>
1442 
1443
1444<hr>Input File: ../test/nonlinear_ok_simple_f.m
1445
1446<hr>
1447 
1448
1449
1450
1451<center><b><big><big><a name="3.1.2" id="3.1.2">3.1.2: Example Transition Function: nonlinear_ok_simple_g</a>
1452</big></big></b></center>
1453<br>
1454<b><big><a name="3.1.2.a" id="3.1.2.a">3.1.2.a: Source Code</a></big></b>
1455
1456 <code><font color='blue'><pre style='display:inline'> 
1457function [gk, Gk] = nonlinear_ok_simple_g(k, xk1)
1458        n  = size(xk1, 1);
1459        if k == 1
1460                Gk = zeros(n, n);
1461                gk = Gk * xk1 + 1;
1462        else
1463                Gk = eye(n);
1464                gk = Gk * xk1 + 1;
1465        end
1466        return
1467end
1468</pre></font></code>
1469 
1470
1471<hr>Input File: ../test/nonlinear_ok_simple_g.m
1472
1473<hr>
1474 
1475
1476
1477
1478<center><b><big><big><a name="3.1.3" id="3.1.3">3.1.3: Example Measurement Function: nonlinear_ok_simple_h</a>
1479</big></big></b></center>
1480<br>
1481<b><big><a name="3.1.3.a" id="3.1.3.a">3.1.3.a: Source Code</a></big></b>
1482
1483 <code><font color='blue'><pre style='display:inline'> 
1484function [hk, Hk] = nonlinear_ok_simple_h(k, xk)
1485        global nonlinear_ok_simple_m
1486        %
1487        n        = size(xk, 1);
1488        m        = nonlinear_ok_simple_m;
1489        hk       = xk(1:m);
1490        Hk       = [ eye(m) , zeros(m, n-m) ];
1491        return
1492end
1493</pre></font></code>
1494 
1495
1496<hr>Input File: ../test/nonlinear_ok_simple_h.m
1497
1498<hr>
1499 
1500
1501
1502<center><b><big><big><a name="3.2" id="3.2">3.2: ckbs_nonlinear Box Constrained Tracking Example and Test</a>
1503</big></big></b></center>
1504<br>
1505<b><big><a name="3.2.a" id="3.2.a">3.2.a: Syntax</a></big></b>
1506
1507<br>
1508<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>
1509
1510<br>
1511<br>
1512<b><big><a name="3.2.b" id="3.2.b">3.2.b: draw_plot</a></big></b>
1513<br>
1514If this argument is true, a plot is drawn showing the results
1515and the <code><font color="blue">nonlinear_ok_box.out</font></code> file is written for use with
1516the program <code><font color="blue">nonlinear_ok_box.r</font></code>.
1517
1518<br>
1519<br>
1520<b><big><a name="3.2.c" id="3.2.c">3.2.c: ok</a></big></b>
1521<br>
1522If the return value <i>ok</i> is true, the test passed,
1523otherwise the test failed.
1524
1525<br>
1526<br>
1527<b><big><a name="3.2.d" id="3.2.d">3.2.d: State Vector</a></big></b>
1528
1529<table><tr><td align='left'  valign='top'>
1530
1531<code>
1532<span style='white-space: nowrap'>&nbsp;x1&nbsp;(t)</span></code>
1533  </td><td align='left'  valign='top'>
1534 first component of velocity  </td></tr><tr><td align='left'  valign='top'>
1535
1536<code>
1537<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
1538  </td><td align='left'  valign='top'>
1539 first component of position  </td></tr><tr><td align='left'  valign='top'>
1540
1541<code>
1542<span style='white-space: nowrap'>&nbsp;x3&nbsp;(t)</span></code>
1543  </td><td align='left'  valign='top'>
1544 second component of velocity  </td></tr><tr><td align='left'  valign='top'>
1545
1546<code>
1547<span style='white-space: nowrap'>&nbsp;x4&nbsp;(t)</span></code>
1548  </td><td align='left'  valign='top'>
1549 second component of position 
1550</td></tr>
1551</table>
1552<br>
1553<b><big><a name="3.2.e" id="3.2.e">3.2.e: Measurement Vector</a></big></b>
1554
1555<table><tr><td align='left'  valign='top'>
1556
1557<code>
1558<span style='white-space: nowrap'>&nbsp;z1&nbsp;(t)</span></code>
1559  </td><td align='left'  valign='top'>
1560 range to the station s1  plus noise </td></tr><tr><td align='left'  valign='top'>
1561
1562<code>
1563<span style='white-space: nowrap'>&nbsp;z2&nbsp;(t)</span></code>
1564  </td><td align='left'  valign='top'>
1565 range to the station s2  plus noise
1566</td></tr>
1567</table>
1568<br>
1569<b><big><a name="3.2.f" id="3.2.f">3.2.f: Constraint</a></big></b>
1570
1571<br>
1572<code>
1573<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>
1574.
1575
1576
1577<br>
1578<br>
1579<b><big><a name="3.2.g" id="3.2.g">3.2.g: Call Back Functions</a></big></b>
1580
1581<table><tr><td align='left'  valign='top'>
1582
1583<a href="#3.2.1">3.2.1: nonlinear_ok_box_f.m</a></td><td>
1584Example Constraint Function: nonlinear_ok_box_f</td></tr>
1585<tr><td>
1586
1587<a href="#3.2.2">3.2.2: nonlinear_ok_box_g.m</a></td><td>
1588Example Transition Function: nonlinear_ok_box_g</td></tr>
1589<tr><td>
1590
1591<a href="#3.2.3">3.2.3: nonlinear_ok_box_h.m</a></td><td>
1592Example Measurement Function: nonlinear_ok_box_h</td></tr>
1593<tr><td>
1594
1595<a href="#3.2.4">3.2.4: nonlinear_ok_box_nof.m</a></td><td>
1596Example no Constraint Function: nonlinear_ok_box_nof</td></tr>
1597<tr><td>
1598
1599</td></tr>
1600</table>
1601<br>
1602<b><big><a name="3.2.h" id="3.2.h">3.2.h: Source Code</a></big></b>
1603
1604 <code><font color='blue'><pre style='display:inline'> 
1605function [ok] = nonlinear_ok_box(draw_plot)
1606if nargin &lt; 1
1607        draw_plot = false;
1608end
1609% --------------------------------------------------------
1610% You can change these parameters
1611N       = 50;            % number of measurement time points
1612dt      = 2 * pi / N;    % time between measurement points
1613sigma   = .25;           % standard deviation of measurement noise
1614gamma   = 1;             % multiplier for transition variance
1615max_itr = 50;            % maximum number of iterations
1616epsilon = 1e-4;          % convergence criteria
1617x4_min  = .25;           % minimum value for x4_true
1618h_min   = 0;             % minimum horizontal value in plots
1619h_max   = 7;             % maximum horizontal value in plots
1620v_min   = 0;             % minimum vertical value in plots
1621v_max   = 2.5;           % maximum vertical value in plots
1622s1      = [ 0 , 0 ];     % station one
1623s2      = [ 2*pi , 0 ];  % station two
1624%
1625% level of tracing during the optimization
1626if draw_plot
1627        level   = 1;
1628else
1629        level   = 0;
1630end
1631% ---------------------------------------------------------
1632%
1633% global variables used by nonlinear_ok_box_h
1634global nonlinear_ok_box_s1
1635global nonlinear_ok_box_s2
1636nonlinear_ok_box_s1 = s1;
1637nonlinear_ok_box_s2 = s2;
1638%
1639ok = true;
1640%
1641%  Define the problem
1642rand('seed', 1234);
1643%
1644% number of constraints per time point
1645ell   = 2;
1646%
1647% number of measurements per time point
1648m     = 2;
1649%
1650% number of state vector components per time point
1651n     = 4;
1652%
1653% simulate the true trajectory and measurement noise
1654t        =  (1 : N) * dt;
1655x2_true  = t;
1656x4_max   = x4_min + 2;
1657x4_true  = x4_min + 1 - sin(t);
1658x1_true  = ones(1, N);
1659x3_true  = - cos(t);
1660x_true   = [ x1_true ; x2_true ; x3_true ; x4_true ];
1661v1_true  = sigma * randn(1, N);
1662v2_true  = sigma * randn(1, N);
1663%
1664% corresponding measurement values
1665rinv    = zeros(m, m, N);
1666z       = zeros(m, N);
1667rinvk   = eye(m) / (sigma * sigma);
1668for k = 1 : N
1669        x_k          = x_true(:, k);
1670        h_k          = nonlinear_ok_box_h(k, x_k);
1671        z(:, k)      = h_k + [ v1_true(k) ; v2_true(k) ];
1672        rinv(:,:, k) = rinvk;
1673end
1674%
1675% covariance for the transition noise
1676qk       = diag( [ dt, dt^3 / 3 , dt, dt^3 / 3 ] );
1677qk(1, 2) = dt^2 / 2;
1678qk(2, 1) = dt^2 / 2;
1679qk(3, 4) = dt^2 / 2;
1680qk(4, 3) = dt^2 / 2;
1681qk       = qk * gamma;
1682qinvk    = inv(qk);
1683qinv     = zeros(n, n, N);
1684for k = 2 : N
1685        qinv(:,:, k) = qinvk;
1686end
1687%
1688% covariance for the initial estimate
1689qinv(:,:,1) = eye(n) * 100 * gamma;
1690%
1691% initial x vector
1692x_in = zeros(n, N);
1693for k = 1 : N
1694        x_in(:, k) = [ 0 ; 1 ; 0 ; 1 ];
1695end
1696%
1697% global variables used by nonlinear_ok_box_f
1698global nonlinear_ok_box_x4_min
1699global nonlinear_ok_box_x4_max
1700nonlinear_ok_box_x4_min = x4_min;
1701nonlinear_ok_box_x4_max = x4_max;
1702%
1703% global variables used by nonlinear_ok_box_g
1704global nonlinear_ok_box_x1
1705global nonlinear_ok_box_dt
1706nonlinear_ok_box_x1 = x_true(:, 1);
1707nonlinear_ok_box_dt = dt;
1708%
1709% ----------------------------------------------------------------------
1710f_fun = 'nonlinear_ok_box_f';
1711g_fun = 'nonlinear_ok_box_g';
1712h_fun = 'nonlinear_ok_box_h';
1713[x_out, u_out, info] = ckbs_nonlinear( ...
1714        f_fun,    ...
1715        g_fun,    ...
1716        h_fun,    ...
1717        max_itr,  ...
1718        epsilon,  ...
1719        x_in,     ...
1720        z,        ...
1721        qinv,     ...
1722        rinv,     ...
1723        level     ...
1724);
1725% ----------------------------------------------------------------------
1726ok         = ok &amp; (size(info,1) &lt;= max_itr);
1727f_out      = zeros(ell, N);
1728g_out      = zeros(n, N);
1729h_out      = zeros(m, N);
1730df_out     = zeros(ell, n, N);
1731dg_out     = zeros(n, n, N);
1732dh_out     = zeros(m, n, N);
1733xk1        = zeros(n, 1);
1734for k = 1 : N
1735        xk    = x_out(:, k);
1736        uk    = u_out(:, k);
1737        [fk, Fk]   = nonlinear_ok_box_f(k, xk);
1738        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
1739        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
1740        %
1741        ok   = ok &amp; all( fk &lt;= epsilon );
1742        ok   = ok &amp; all( abs(fk) .* uk &lt;= epsilon );
1743        %
1744        df_out(:,:, k) = Fk;
1745        dg_out(:,:, k) = Gk;
1746        dh_out(:,:, k) = Hk;
1747        f_out(:, k)    = fk - Fk * xk;
1748        g_out(:, k)    = gk - Gk * xk1;
1749        h_out(:, k)    = hk - Hk * xk;
1750        xk1 = xk;
1751end
1752ok   = ok &amp; all( all( u_out &gt;= 0 ) );
1753%
1754d_out = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
1755for k = 1 : N
1756        uk = u_out(:, k);
1757        Fk = df_out(:,:, k);
1758        dk = d_out(:, k);
1759        %
1760        ok = ok &amp; (max ( abs( Fk' * uk + dk ) ) &lt;= epsilon);
1761end
1762if ~ ok
1763        keyboard
1764end
1765if draw_plot
1766        figure(1);
1767        clf
1768        hold on
1769        plot(x_true(2,:)', x_true(4,:)', 'b-' );
1770        plot(x_out(2,:)', x_out(4,:)', 'g-' );
1771        plot(x_true(2,:)', x4_min * ones(N,1), 'r-');
1772        plot(x_true(2,:)', x4_max * ones(N,1), 'r-');
1773        axis([h_min, h_max, v_min, v_max]);
1774        title('Constrained: blue=truth, green=estimate, red=constraint');
1775        hold off
1776        %
1777        % constrained estimate
1778        x_con = x_out;
1779end
1780% ----------------------------------------------------------------------
1781% Unconstrained case
1782f_fun = 'nonlinear_ok_box_nof';
1783[x_out, u_out, info] = ckbs_nonlinear( ...
1784        f_fun,    ...
1785        g_fun,    ...
1786        h_fun,    ...
1787        max_itr,  ...
1788        epsilon,  ...
1789        x_in,     ...
1790        z,        ...
1791        qinv,     ...
1792        rinv,     ...
1793        level     ...
1794);
1795% ----------------------------------------------------------------------
1796ok   = ok &amp; (size(info,1) &lt;= max_itr);
1797xk1  = zeros(n, 1);
1798for k = 1 : N
1799        xk    = x_out(:, k);
1800        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
1801        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
1802        %
1803        dg_out(:,:, k) = Gk;
1804        dh_out(:,:, k) = Hk;
1805        g_out(:, k)    = gk - Gk * xk1;
1806        h_out(:, k)    = hk - Hk * xk;
1807        xk1 = xk;
1808end
1809d_out  = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
1810ok     = ok &amp; (max( max( abs(d_out) ) ) &lt;= epsilon);
1811if draw_plot
1812        figure(2);
1813        clf
1814        hold on
1815        plot(x_true(2,:)', x_true(4,:)', 'b-' );
1816        plot(x_out(2,:)', x_out(4,:)', 'g-' );
1817        plot(x_true(2,:)', x4_min * ones(1,N), 'r-');
1818        plot(x_true(2,:)', x4_max * ones(1,N), 'r-');
1819        axis([h_min, h_max, v_min, v_max]);
1820        title('Unconstrained: blue=truth, green=estimate, red=constraint');
1821        hold off
1822        %
1823        % unconstrained estimate
1824        x_free = x_out;
1825        %
1826        % write out constrained and unconstrained results
1827        [fid, msg] = fopen('nonlinear_ok_box.out', 'wt');
1828        if size(msg, 2) &gt; 0
1829                disp(['nonlinear_ok: ', msg]);
1830        end
1831        %                      123456789012345678901234'
1832        heading =             ' x2_true  x2_con x2_free'  ;
1833        heading = [ heading , ' x4_true  x4_con x4_free' ];
1834        heading = [ heading , '      z1      z2\n'       ];
1835        fprintf(fid, heading);
1836        for k = 1 : N
1837                fprintf(fid,'%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f\n', ...
1838                        x_true(2,k), x_con(2,k), x_free(2,k), ...
1839                        x_true(4,k), x_con(4,k), x_free(4,k), ...
1840                        z(1,k), z(2,k) ...
1841                );
1842        end
1843        fclose(fid);
1844end
1845return
1846end
1847</pre></font></code>
1848 
1849
1850<hr>Input File: ../test/nonlinear_ok_box.m
1851
1852<hr>
1853 
1854
1855
1856
1857<center><b><big><big><a name="3.2.1" id="3.2.1">3.2.1: Example Constraint Function: nonlinear_ok_box_f</a>
1858</big></big></b></center>
1859<br>
1860<b><big><a name="3.2.1.a" id="3.2.1.a">3.2.1.a: Source Code</a></big></b>
1861
1862 <code><font color='blue'><pre style='display:inline'> 
1863function [fk, Fk] = nonlinear_ok_box_f(k, xk)
1864        global nonlinear_ok_box_x4_min
1865        global nonlinear_ok_box_x4_max
1866        %
1867        % constrained so that x4_min &lt;= x4(t) &lt;= x4_max
1868        x4_min = nonlinear_ok_box_x4_min;
1869        x4_max = nonlinear_ok_box_x4_max;
1870        ell    = 2;
1871        n      = size(xk, 1);
1872        %
1873        fk = [ ...
1874                xk(4) - x4_max;
1875                x4_min - xk(4) ...
1876        ];
1877        Fk = zeros(ell, n);
1878        Fk(1, 4) = 1;
1879        Fk(2, 4) = -1;
1880        return
1881end
1882</pre></font></code>
1883 
1884
1885<hr>Input File: ../test/nonlinear_ok_box_f.m
1886
1887<hr>
1888 
1889
1890
1891
1892<center><b><big><big><a name="3.2.2" id="3.2.2">3.2.2: Example Transition Function: nonlinear_ok_box_g</a>
1893</big></big></b></center>
1894<br>
1895<b><big><a name="3.2.2.a" id="3.2.2.a">3.2.2.a: Source Code</a></big></b>
1896
1897 <code><font color='blue'><pre style='display:inline'> 
1898function [gk, Gk] = nonlinear_ok_box_g(k, xk1)
1899        global nonlinear_ok_box_x1
1900        global nonlinear_ok_box_dt
1901        if k == 1
1902                Gk = zeros(4, 4);
1903                gk = nonlinear_ok_box_x1;
1904                return;
1905        end
1906        dt = nonlinear_ok_box_dt;
1907        Gk = [ ...
1908                1  0  0  0
1909                dt 1  0  0
1910                0  0  1  0
1911                0  0  dt 1 ...
1912        ];
1913        gk = Gk * xk1;
1914        return
1915end
1916</pre></font></code>
1917 
1918
1919<hr>Input File: ../test/nonlinear_ok_box_g.m
1920
1921<hr>
1922 
1923
1924
1925
1926<center><b><big><big><a name="3.2.3" id="3.2.3">3.2.3: Example Measurement Function: nonlinear_ok_box_h</a>
1927</big></big></b></center>
1928<br>
1929<b><big><a name="3.2.3.a" id="3.2.3.a">3.2.3.a: Source Code</a></big></b>
1930
1931 <code><font color='blue'><pre style='display:inline'> 
1932function [hk, Hk] = nonlinear_ok_box_h(k, xk)
1933        global nonlinear_ok_box_s1
1934        global nonlinear_ok_box_s2
1935        s1  = nonlinear_ok_box_s1;
1936        s2  = nonlinear_ok_box_s2;
1937        r1  = sqrt( (xk(2) - s1(1))^2 + (xk(4) - s1(2))^2 );
1938        r2  = sqrt( (xk(2) - s2(1))^2 + (xk(4) - s2(2))^2 );
1939        hk = [ r1 ; r2 ];
1940        dr1 = [ 0, xk(2) - s1(1), 0, xk(4) - s1(2) ] / r1;
1941        dr2 = [ 0, xk(2) - s2(1), 0, xk(4) - s2(2) ] / r2;
1942        Hk = [ dr1 ; dr2 ];
1943        return
1944end
1945</pre></font></code>
1946 
1947
1948<hr>Input File: ../test/nonlinear_ok_box_h.m
1949
1950<hr>
1951 
1952
1953
1954
1955<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>
1956</big></big></b></center>
1957<br>
1958<b><big><a name="3.2.4.a" id="3.2.4.a">3.2.4.a: Source Code</a></big></b>
1959
1960 <code><font color='blue'><pre style='display:inline'> 
1961function [fk, Fk] = nonlinear_ok_box_nof(k, xk)
1962        % no constraint case
1963        n  = size(xk, 1);
1964        fk = -1;
1965        Fk = zeros(1, n);
1966        return
1967end
1968</pre></font></code>
1969 
1970
1971<hr>Input File: ../test/nonlinear_ok_box_nof.m
1972
1973<hr>
1974 
1975
1976
1977<center><b><big><big><a name="3.3" id="3.3">3.3: ckbs_nonlinear Sine Wave Constrained Tracking Example and Test</a>
1978</big></big></b></center>
1979<br>
1980<b><big><a name="3.3.a" id="3.3.a">3.3.a: Syntax</a></big></b>
1981
1982<br>
1983<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>
1984
1985<br>
1986<br>
1987<b><big><a name="3.3.b" id="3.3.b">3.3.b: draw_plot</a></big></b>
1988<br>
1989If this argument is true, a plot is drawn showing the results
1990and the <code><font color="blue">nonlinear_ok_sin.out</font></code> file is written for use with the
1991program <code><font color="blue">test/nonlinear_ok_sin.r</font></code>.
1992
1993<br>
1994<br>
1995<b><big><a name="3.3.c" id="3.3.c">3.3.c: ok</a></big></b>
1996<br>
1997If the return value <i>ok</i> is true, the test passed,
1998otherwise the test failed.
1999
2000<br>
2001<br>
2002<b><big><a name="3.3.d" id="3.3.d">3.3.d: State Vector</a></big></b>
2003
2004<table><tr><td align='left'  valign='top'>
2005
2006<code>
2007<span style='white-space: nowrap'>&nbsp;x1&nbsp;(t)</span></code>
2008  </td><td align='left'  valign='top'>
2009 first component of velocity   </td></tr><tr><td align='left'  valign='top'>
2010
2011<code>
2012<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
2013  </td><td align='left'  valign='top'>
2014 first component of position  </td></tr><tr><td align='left'  valign='top'>
2015
2016<code>
2017<span style='white-space: nowrap'>&nbsp;x3&nbsp;(t)</span></code>
2018  </td><td align='left'  valign='top'>
2019 second component of velocity   </td></tr><tr><td align='left'  valign='top'>
2020
2021<code>
2022<span style='white-space: nowrap'>&nbsp;x4&nbsp;(t)</span></code>
2023  </td><td align='left'  valign='top'>
2024 second component of position 
2025</td></tr>
2026</table>
2027<br>
2028<b><big><a name="3.3.e" id="3.3.e">3.3.e: Measurement Vector</a></big></b>
2029
2030<table><tr><td align='left'  valign='top'>
2031
2032<code>
2033<span style='white-space: nowrap'>&nbsp;z1&nbsp;(t)</span></code>
2034  </td><td align='left'  valign='top'>
2035 range to station s1 plus noise </td></tr><tr><td align='left'  valign='top'>
2036
2037<code>
2038<span style='white-space: nowrap'>&nbsp;z2&nbsp;(t)</span></code>
2039  </td><td align='left'  valign='top'>
2040 range to station s2  plus noise
2041</td></tr>
2042</table>
2043<br>
2044<b><big><a name="3.3.f" id="3.3.f">3.3.f: Constraint</a></big></b>
2045
2046<br>
2047<code>
2048<span style='white-space: nowrap'>&nbsp;&nbsp;x4(t)&nbsp;\geq&nbsp;1&nbsp;-&nbsp;sin(&nbsp;x2(t)&nbsp;)</span></code>
2049 
2050
2051
2052<br>
2053<br>
2054<b><big><a name="3.3.g" id="3.3.g">3.3.g: Call Back Functions</a></big></b>
2055
2056<table><tr><td align='left'  valign='top'>
2057
2058<a href="#3.3.1">3.3.1: nonlinear_ok_sin_f.m</a></td><td>
2059Example Constraint Function: nonlinear_ok_sin_f</td></tr>
2060<tr><td>
2061
2062<a href="#3.2.2">3.2.2: nonlinear_ok_box_g.m</a></td><td>
2063Example Transition Function: nonlinear_ok_box_g</td></tr>
2064<tr><td>
2065
2066<a href="#3.2.3">3.2.3: nonlinear_ok_box_h.m</a></td><td>
2067Example Measurement Function: nonlinear_ok_box_h</td></tr>
2068<tr><td>
2069
2070<a href="#3.2.4">3.2.4: nonlinear_ok_box_nof.m</a></td><td>
2071Example no Constraint Function: nonlinear_ok_box_nof</td></tr>
2072<tr><td>
2073
2074</td></tr>
2075</table>
2076<br>
2077<b><big><a name="3.3.h" id="3.3.h">3.3.h: Source Code</a></big></b>
2078
2079 <code><font color='blue'><pre style='display:inline'> 
2080function [ok] = nonlinear_ok_sin(draw_plot)
2081if nargin &lt; 1
2082        draw_plot = false;
2083end
2084% --------------------------------------------------------
2085% You can change these parameters
2086N       = 50;            % number of measurement time points
2087dt      = 2 * pi / N;    % time between measurement points
2088sigma   = .25;           % standard deviation of measurement noise
2089gamma   = 1.;            % multiplier for transition variance
2090max_itr = 50;            % maximum number of iterations
2091epsilon = 1e-4;          % convergence criteria
2092x4_min  = .25;           % minimum value for x4 constraint
2093h_min   = 0;             % minimum horizontal value in plots
2094h_max   = 7;             % maximum horizontal value in plots
2095v_min   = 0;             % minimum vertical value in plots
2096v_max   = 2.5;           % maximum vertical value in plots
2097x4_dist = .05;           % distance true path is from the constraint
2098s1      = [ 0 , 0 ];     % station one
2099s2      = [ 2*pi , 0 ];  % station two
2100%
2101% level of tracing during the optimization
2102if draw_plot
2103        level   = 1;
2104else
2105        level   = 0;
2106end
2107% ---------------------------------------------------------
2108% global variables used by nonlinear_ok_box_h
2109global nonlinear_ok_box_s1
2110global nonlinear_ok_box_s2
2111nonlinear_ok_box_s1 = s1;
2112nonlinear_ok_box_s2 = s2;
2113%
2114% global variable used by nonlinear_ok_sin_f
2115global nonlinear_ok_sin_x4_min
2116nonlinear_ok_sin_x4_min = x4_min;
2117%
2118ok = true;
2119%
2120%  Define the problem
2121rand('seed', 234);
2122%
2123% number of constraints per time point
2124ell   = 1;
2125%
2126% number of measurements per time point
2127m     = 2;
2128%
2129% number of state vector components per time point
2130n     = 4;
2131%
2132% simulate the true trajectory and measurement noise
2133t        =  (1 : N) * dt;
2134x1_true  = ones(1, N);
2135x2_true  = t;
2136x3_true  = - cos(t);
2137x4_true  = x4_dist + 1 - sin(t) + x4_min;
2138x_true   = [ x1_true ; x2_true ; x3_true ; x4_true ];
2139v1_true  = sigma * randn(1, N);
2140v2_true  = sigma * randn(1, N);
2141%
2142% corresponding measurement values
2143rinv    = zeros(m, m, N);
2144z       = zeros(m, N);
2145rinvk   = eye(m) / (sigma * sigma);
2146for k = 1 : N
2147        x_k          = x_true(:, k);
2148        h_k          = nonlinear_ok_box_h(k, x_k);
2149        z(:, k)      = h_k + [ v1_true(k) ; v2_true(k) ];
2150        rinv(:,:, k) = rinvk;
2151end
2152%
2153% covariance for the transition noise
2154qk       = diag( [ dt, dt^3 / 3 , dt, dt^3 / 3 ] );
2155qk(1, 2) = dt^2 / 2;
2156qk(2, 1) = dt^2 / 2;
2157qk(3, 4) = dt^2 / 2;
2158qk(4, 3) = dt^2 / 2;
2159qk       = qk * gamma;
2160qinvk    = inv(qk);
2161qinv     = zeros(n, n, N);
2162for k = 2 : N
2163        qinv(:,:, k) = qinvk;
2164end
2165%
2166% covariance for the initial estimate
2167qinv(:,:,1) = eye(n) * 100 * gamma;
2168%
2169% initial x vector
2170x_in       = zeros(n, N);
2171x_in(4, :) = 1;
2172%
2173% nonlinear_ok_sin use same g function as nonlinear_box_ok
2174% global variables used by nonlinear_ok_box_g
2175global nonlinear_ok_box_x1
2176global nonlinear_ok_box_dt
2177nonlinear_ok_box_x1 = x_true(:, 1);
2178nonlinear_ok_box_dt = dt;
2179%
2180% ----------------------------------------------------------------------
2181f_fun = 'nonlinear_ok_sin_f';  % special nonlinear_ok_sin constraints
2182g_fun = 'nonlinear_ok_box_g';  % same transition function as nonlinear_ok_box
2183h_fun = 'nonlinear_ok_box_h';  % same measurement function as nonlinear_ok_box
2184[x_out, u_out, info] = ckbs_nonlinear( ...
2185        f_fun,    ...
2186        g_fun,    ...
2187        h_fun,    ...
2188        max_itr,  ...
2189        epsilon,  ...
2190        x_in,     ...
2191        z,        ...
2192        qinv,     ...
2193        rinv,     ...
2194        level     ...
2195);
2196% ----------------------------------------------------------------------
2197ok         = ok &amp; (size(info,1) &lt;= max_itr);
2198f_out      = zeros(ell, N);
2199g_out      = zeros(n, N);
2200h_out      = zeros(m, N);
2201df_out     = zeros(ell, n, N);
2202dg_out     = zeros(n, n, N);
2203dh_out     = zeros(m, n, N);
2204xk1        = zeros(n, 1);
2205for k = 1 : N
2206        xk    = x_out(:, k);
2207        uk    = u_out(:, k);
2208        [fk, Fk]   = nonlinear_ok_sin_f(k, xk);
2209        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
2210        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
2211        %
2212        ok   = ok &amp; all( fk &lt;= epsilon );
2213        ok   = ok &amp; all( abs(fk) .* uk &lt;= epsilon );
2214        %
2215        df_out(:,:, k) = Fk;
2216        dg_out(:,:, k) = Gk;
2217        dh_out(:,:, k) = Hk;
2218        f_out(:, k)    = fk - Fk * xk;
2219        g_out(:, k)    = gk - Gk * xk1;
2220        h_out(:, k)    = hk - Hk * xk;
2221        xk1 = xk;
2222end
2223ok   = ok &amp; all( all( u_out &gt;= 0 ) );
2224%
2225d_out = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
2226for k = 1 : N
2227        uk = u_out(:, k);
2228        Fk = df_out(:,:, k);
2229        dk = d_out(:, k);
2230        %
2231        ok = ok &amp; (max ( abs( Fk' * uk + dk ) ) &lt;= epsilon);
2232end
2233if ~ ok
2234        keyboard
2235end
2236if draw_plot
2237        figure(1);
2238        clf
2239        hold on
2240        plot(x_true(2,:)', x_true(4,:)', 'b-' );
2241        plot(x_out(2,:)', x_out(4,:)', 'g-' );
2242        plot(x_true(2,:)', 1 - sin(x_true(2,:))' + x4_min, 'r-');
2243        axis([h_min, h_max, v_min, v_max]);
2244        title('Constrained: blue=truth, green=estimate, red=constraint');
2245        hold off
2246        %
2247        % constrained estimate
2248        x_con = x_out;
2249end
2250% ----------------------------------------------------------------------
2251% Unconstrained case
2252f_fun = 'nonlinear_ok_box_nof';  % same function as used by nonlinear_ok_box
2253[x_out, u_out, info] = ckbs_nonlinear( ...
2254        f_fun,    ...
2255        g_fun,    ...
2256        h_fun,    ...
2257        max_itr,  ...
2258        epsilon,  ...
2259        x_in,     ...
2260        z,        ...
2261        qinv,     ...
2262        rinv,     ...
2263        level     ...
2264);
2265% ----------------------------------------------------------------------
2266ok   = ok &amp; (size(info,1) &lt;= max_itr);
2267xk1  = zeros(n, 1);
2268for k = 1 : N
2269        xk    = x_out(:, k);
2270        [gk, Gk]   = nonlinear_ok_box_g(k, xk1);
2271        [hk, Hk]   = nonlinear_ok_box_h(k, xk);
2272        %
2273        dg_out(:,:, k) = Gk;
2274        dh_out(:,:, k) = Hk;
2275        g_out(:, k)    = gk - Gk * xk1;
2276        h_out(:, k)    = hk - Hk * xk;
2277        xk1 = xk;
2278end
2279d_out  = ckbs_sumsq_grad(x_out, z, g_out, h_out, dg_out, dh_out, qinv, rinv);
2280ok     = ok &amp; (max( max( abs(d_out) ) ) &lt;= epsilon);
2281if draw_plot
2282        figure(2);
2283        clf
2284        hold on
2285        plot(x_true(2,:)', x_true(4,:)', 'b-' );
2286        plot(x_out(2,:)', x_out(4,:)', 'g-' );
2287        plot(x_true(2,:)', 1 - sin(x_true(2,:))' + x4_min, 'r-');
2288        axis([h_min, h_max, v_min, v_max]);
2289        title('Unconstrained: blue=truth, green=estimate, red=constraint');
2290        hold off
2291        %
2292        % unconstrained estimate
2293        x_free = x_out;
2294        %
2295        % write out constrained and unconstrained results
2296        [fid, msg] = fopen('nonlinear_ok_sin.out', 'wt');
2297        if size(msg, 2) &gt; 0
2298                disp(['nonlinear_ok: ', msg]);
2299        end
2300        %                      123456789012345678901234'
2301        heading =             ' x2_true  x2_con x2_free'  ;
2302        heading = [ heading , ' x4_true  x4_con x4_free' ];
2303        heading = [ heading , '      z1      z2\n'       ];
2304        fprintf(fid, heading);
2305        for k = 1 : N
2306                fprintf(fid,'%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f%8.3f\n', ...
2307                        x_true(2,k), x_con(2,k), x_free(2,k), ...
2308                        x_true(4,k), x_con(4,k), x_free(4,k), ...
2309                        z(1,k), z(2,k) ...
2310                );
2311        end
2312        fclose(fid);
2313end
2314return
2315end
2316</pre></font></code>
2317 
2318
2319<hr>Input File: ../test/nonlinear_ok_sin.m
2320
2321<hr>
2322 
2323
2324
2325
2326<center><b><big><big><a name="3.3.1" id="3.3.1">3.3.1: Example Constraint Function: nonlinear_ok_sin_f</a>
2327</big></big></b></center>
2328<br>
2329<b><big><a name="3.3.1.a" id="3.3.1.a">3.3.1.a: Source Code</a></big></b>
2330
2331 <code><font color='blue'><pre style='display:inline'> 
2332function [fk, Fk] = nonlinear_ok_sin_f(k, xk)
2333        global nonlinear_ok_sin_x4_min
2334        x4_min = nonlinear_ok_sin_x4_min;
2335        %
2336        % constrained so that x(4) &gt;= 1 - sin( x(1) ) + x4_min
2337        ell      = 1;
2338        n        = size(xk, 1);
2339        %
2340        fk       = 1 - sin( xk(2) ) + x4_min - xk(4);
2341        Fk       = zeros(ell, n);
2342        Fk(1, 2) = - cos( xk(2) );
2343        Fk(1, 4) = -1;
2344        return
2345end
2346</pre></font></code>
2347 
2348
2349<hr>Input File: ../test/nonlinear_ok_sin_f.m
2350
2351<hr>
2352 
2353
2354
2355
2356
2357
2358
2359
2360
2361<center><b><big><big><a name="4" id="4">4: Constrained Affine Kalman Bucy Smoother</a>
2362</big></big></b></center>
2363<br>
2364<b><big><a name="4.a" id="4.a">4.a: Syntax</a></big></b>
2365
2366<br>
2367<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>
2368
2369<br>
2370<br>
2371<b><big><a name="4.b" id="4.b">4.b: Purpose</a></big></b>
2372<br>
2373This routine minimizes the
2374affine Kalman-Bucy smoother residual sum of squares objective
2375subject to an affine inequality constraint.
2376
2377<br>
2378<br>
2379<b><big><a name="4.c" id="4.c">4.c: Notation</a></big></b>
2380<br>
2381The affine Kalman-Bucy smoother residual sum of squares is defined by
2382<code>
2383<span style='white-space: nowrap'>&nbsp;\[<br>
2384\begin{array}{rcl}<br>
2385S&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>
2386S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
2387\frac{1}{2}&nbsp;<br>
2388(&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>
2389\\<br>
2390&amp;&nbsp;+&nbsp;&amp;<br>
2391\frac{1}{2}&nbsp;<br>
2392(&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>
2393\\<br>
2394\end{array}<br>
2395\]&nbsp;</span></code>
2396
2397where the matrices <code>
2398<span style='white-space: nowrap'>&nbsp;R_k</span></code>
2399 and <code>
2400<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
2401 are
2402symmetric positive definite and
2403<code>
2404<span style='white-space: nowrap'>&nbsp;x_0</span></code>
2405 is the constant zero.
2406Note that <code>
2407<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2408 is the initial state estimate
2409and <code>
2410<span style='white-space: nowrap'>&nbsp;Q_1</span></code>
2411 is the corresponding covariance.
2412
2413<br>
2414<br>
2415<b><big><a name="4.d" id="4.d">4.d: Problem</a></big></b>
2416<br>
2417The affine constrained Kalman-Bucy smoother problem is
2418<code>
2419<span style='white-space: nowrap'>&nbsp;\[<br>
2420\begin{array}{rll}<br>
2421{\rm&nbsp;minimize}&nbsp;<br>
2422&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;S(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;<br>
2423&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>
2424\\<br>
2425{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;<br>
2426&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;b_k&nbsp;+&nbsp;B_k&nbsp;*&nbsp;x_k&nbsp;&nbsp;\leq&nbsp;0&nbsp;<br>
2427&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;{\rm&nbsp;for}&nbsp;\;&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N<br>
2428\end{array}<br>
2429\]&nbsp;</span></code>
2430
2431
2432<br>
2433<br>
2434<b><big><a name="4.e" id="4.e">4.e: First Order Conditions</a></big></b>
2435<br>
2436A state sequence <code>
2437<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
2438 is considered a solution
2439if there is a Lagrange multiplier sequence <code>
2440<span style='white-space: nowrap'>&nbsp;(&nbsp;u_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;u_N&nbsp;)</span></code>
2441 
2442such that the following conditions are satisfied.
2443<code>
2444<span style='white-space: nowrap'>&nbsp;\[<br>
2445\begin{array}{rcl}<br>
2446&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>
2447&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>
2448&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>
2449&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>
2450\end{array}<br>
2451\]&nbsp;</span></code>
2452
2453for <code>
2454<span style='white-space: nowrap'>&nbsp;j&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;n</span></code>
2455,
2456<code>
2457<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
2458, and
2459<code>
2460<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2461.
2462Here
2463<code>
2464<span style='white-space: nowrap'>&nbsp;d_k</span></code>
2465 is the partial derivative of <code>
2466<span style='white-space: nowrap'>&nbsp;S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
2467
2468with respect to <code>
2469<span style='white-space: nowrap'>&nbsp;x_k</span></code>
2470
2471and <code>
2472<span style='white-space: nowrap'>&nbsp;(u_k)_i</span></code>
2473 denotes the <i>i</i>-th component of <code>
2474<span style='white-space: nowrap'>&nbsp;u_k</span></code>
2475.
2476
2477<br>
2478<br>
2479<b><big><a name="4.f" id="4.f">4.f: max_itr</a></big></b>
2480<br>
2481The integer scalar <i>max_itr</i> specifies the maximum number of
2482iterations of the algorithm to execute. It must be greater than or
2483equal to zero. Note that if it is zero, the first row of the
2484<a href="#4.s">4.s: <span style='white-space: nowrap'>info</span></a>
2485 return value will still be computed.
2486This can be useful for deciding what is a good value for the argument
2487<a href="#4.g">4.g: <span style='white-space: nowrap'>epsilon</span></a>
2488.
2489
2490<br>
2491<br>
2492<b><big><a name="4.g" id="4.g">4.g: epsilon</a></big></b>
2493<br>
2494The positive scalar <i>epsilon</i> specifies the convergence
2495criteria value; i.e.,
2496<code>
2497<span style='white-space: nowrap'>&nbsp;\[<br>
2498&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\varepsilon&nbsp;=&nbsp;epsilon<br>
2499\]&nbsp;</span></code>
2500
2501
2502<br>
2503<br>
2504<b><big><a name="4.h" id="4.h">4.h: z</a></big></b>
2505<br>
2506The argument <i>z</i> is a two dimensional array,
2507for <code>
2508<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2509
2510<code>
2511<span style='white-space: nowrap'>&nbsp;\[<br>
2512&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z_k&nbsp;=&nbsp;z(:,&nbsp;k)<br>
2513\]</span></code>
2514
2515and <i>z</i> has size <code>
2516<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
2517.
2518
2519<br>
2520<br>
2521<b><big><a name="4.i" id="4.i">4.i: b</a></big></b>
2522<br>
2523The argument <i>b</i> is a two dimensional array,
2524for <code>
2525<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2526
2527<code>
2528<span style='white-space: nowrap'>&nbsp;\[<br>
2529&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b_k&nbsp;=&nbsp;b(:,&nbsp;k)<br>
2530\]</span></code>
2531
2532and <i>b</i> has size <code>
2533<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;N</span></code>
2534.
2535If <code>
2536<span style='white-space: nowrap'>&nbsp;\ell&nbsp;=&nbsp;0</span></code>
2537, the problem is not constrained; i.e.,
2538it is the affine Kalman-Bucy smoother problem.
2539
2540<br>
2541<br>
2542<b><big><a name="4.j" id="4.j">4.j: g</a></big></b>
2543<br>
2544The argument <i>g</i> is a two dimensional array,
2545for <code>
2546<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2547
2548<code>
2549<span style='white-space: nowrap'>&nbsp;\[<br>
2550&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_k&nbsp;=&nbsp;g(:,&nbsp;k)<br>
2551\]</span></code>
2552
2553and <i>g</i> has size <code>
2554<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
2555.
2556The value <code>
2557<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2558 serves as the initial state estimate.
2559
2560<br>
2561<br>
2562<b><big><a name="4.k" id="4.k">4.k: h</a></big></b>
2563<br>
2564The argument <i>h</i> is a two dimensional array,
2565for <code>
2566<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2567
2568<code>
2569<span style='white-space: nowrap'>&nbsp;\[<br>
2570&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h_k&nbsp;=&nbsp;h(:,&nbsp;k)<br>
2571\]</span></code>
2572
2573and <i>h</i> has size <code>
2574<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
2575.
2576
2577<br>
2578<br>
2579<b><big><a name="4.l" id="4.l">4.l: db</a></big></b>
2580<br>
2581The argument <i>db</i> is a three dimensional array,
2582for <code>
2583<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2584
2585<code>
2586<span style='white-space: nowrap'>&nbsp;\[<br>
2587&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;db(:,:,k)<br>
2588\]</span></code>
2589
2590and <i>db</i> has size <code>
2591<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2592.
2593
2594
2595<br>
2596<br>
2597<b><big><a name="4.m" id="4.m">4.m: dg</a></big></b>
2598<br>
2599The argument <i>dg</i> is a three dimensional array,
2600for <code>
2601<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2602
2603<code>
2604<span style='white-space: nowrap'>&nbsp;\[<br>
2605&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
2606\]</span></code>
2607
2608and <i>dg</i> has size <code>
2609<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2610.
2611The initial state estimate <code>
2612<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2613 does not depend on the value of
2614<code>
2615<span style='white-space: nowrap'>&nbsp;x_0</span></code>
2616, hence <code>
2617<span style='white-space: nowrap'>&nbsp;G_1</span></code>
2618 should be zero.
2619
2620<br>
2621<br>
2622<b><big><a name="4.n" id="4.n">4.n: dh</a></big></b>
2623<br>
2624The argument <i>dh</i> is a three dimensional array,
2625for <code>
2626<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2627
2628<code>
2629<span style='white-space: nowrap'>&nbsp;\[<br>
2630&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
2631\]</span></code>
2632
2633and <i>dh</i> has size <code>
2634<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2635.
2636
2637<br>
2638<br>
2639<b><big><a name="4.o" id="4.o">4.o: qinv</a></big></b>
2640<br>
2641The argument <i>qinv</i> is a three dimensional array,
2642for <code>
2643<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2644
2645<code>
2646<span style='white-space: nowrap'>&nbsp;\[<br>
2647&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,&nbsp;k)<br>
2648\]</span></code>
2649
2650and <i>qinv</i> has size <code>
2651<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
2652.
2653The value of <code>
2654<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
2655 is the variance of the initial state
2656estimate <code>
2657<span style='white-space: nowrap'>&nbsp;g_1</span></code>
2658.
2659
2660<br>
2661<br>
2662<b><big><a name="4.p" id="4.p">4.p: rinv</a></big></b>
2663<br>
2664The argument <i>rinv</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;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,&nbsp;k)<br>
2671\]</span></code>
2672
2673and <i>rinv</i> has size <code>
2674<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
2675.
2676It is ok to signify a missing data value by setting the corresponding
2677row and column of <i>rinv</i> to zero. This also enables use
2678to interpolate the state vector <code>
2679<span style='white-space: nowrap'>&nbsp;x_k</span></code>
2680 to points where
2681there are no measurements.
2682
2683<br>
2684<br>
2685<b><big><a name="4.q" id="4.q">4.q: xOut</a></big></b>
2686<br>
2687The result <i>xOut</i> contains the optimal sequence
2688<code>
2689<span style='white-space: nowrap'>&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)</span></code>
2690.
2691For <code>
2692<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2693
2694<code>
2695<span style='white-space: nowrap'>&nbsp;\[<br>
2696&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x_k&nbsp;=&nbsp;xOut(:,&nbsp;k)<br>
2697\]</span></code>
2698
2699and <i>xOut</i> is a two dimensional array with size <code>
2700<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
2701.
2702
2703<br>
2704<br>
2705<b><big><a name="4.r" id="4.r">4.r: uOut</a></big></b>
2706<br>
2707The result <i>uOut</i> contains the Lagrange multiplier sequence
2708corresponding to <i>xOut</i>.
2709For <code>
2710<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2711
2712<code>
2713<span style='white-space: nowrap'>&nbsp;\[<br>
2714&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u_k&nbsp;=&nbsp;uOut(:,&nbsp;k)<br>
2715\]</span></code>
2716
2717and <i>uOut</i> is a two dimensional array with size
2718<code>
2719<span style='white-space: nowrap'>&nbsp;\ell&nbsp;\times&nbsp;N</span></code>
2720.
2721The pair <i>xOut</i>, <i>uOut</i> satisfy the
2722<a href="#4.e">4.e: <span style='white-space: nowrap'>first&nbsp;order&nbsp;conditions</span></a>
2723.
2724
2725<br>
2726<br>
2727<b><big><a name="4.s" id="4.s">4.s: info</a></big></b>
2728<br>
2729The result <i>info</i> is a matrix with each row corresponding
2730to an iteration of the algorithm.
2731Note that <code><font color="blue">ckbs_affine</font></code> has satisfied the convergence condition if
2732and only if
2733<code><font color="blue"><span style='white-space: nowrap'><br>
2734&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>
2735</span></font></code><code><span style='white-space: nowrap'><br>
2736<br>
2737</span></code>We use <code>
2738<span style='white-space: nowrap'>&nbsp;x_k^q</span></code>
2739 (<code>
2740<span style='white-space: nowrap'>&nbsp;u_k^q</span></code>
2741)
2742to denote the state vector (dual vector)
2743for time point <code>
2744<span style='white-space: nowrap'>&nbsp;k</span></code>
2745 and at the end of iteration <code>
2746<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2747
2748We use <code>
2749<span style='white-space: nowrap'>&nbsp;d_k^q</span></code>
2750 for the partial derivative of
2751<code>
2752<span style='white-space: nowrap'>&nbsp;S&nbsp;(&nbsp;x_1^q&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N^q&nbsp;)</span></code>
2753 with respect to <code>
2754<span style='white-space: nowrap'>&nbsp;x_k</span></code>
2755.
2756
2757<br>
2758<br>
2759<b><a name="4.s.a" id="4.s.a">4.s.a: Constraint Bound</a></b>
2760<br>
2761The 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
2762a bound on the constraint functions
2763at the end of iteration <code>
2764<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2765. To be specific
2766<code>
2767<span style='white-space: nowrap'>&nbsp;\[<br>
2768info(q,&nbsp;1)&nbsp;=&nbsp;\max_{i,k}&nbsp;(&nbsp;b_k&nbsp;+&nbsp;B_k&nbsp;*&nbsp;x_k&nbsp;)_i<br>
2769\]&nbsp;</span></code>
2770
2771
2772<br>
2773<br>
2774<b><a name="4.s.b" id="4.s.b">4.s.b: First Order Conditions</a></b>
2775<br>
2776The 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
2777a bound on the partial derivative of the Lagrangian with respect to
2778the state vector sequence
2779at the end of iteration <code>
2780<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2781:
2782<code>
2783<span style='white-space: nowrap'>&nbsp;\[<br>
2784info(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>
2785\]&nbsp;</span></code>
2786
2787where the maximum is with respect to <code>
2788<span style='white-space: nowrap'>&nbsp;j&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;n</span></code>
2789
2790and <code>
2791<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2792.
2793
2794<br>
2795<br>
2796<b><a name="4.s.c" id="4.s.c">4.s.c: Complementarity Conditions</a></b>
2797<br>
2798The 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
2799a bound on the complementarity conditions
2800at the end of iteration <code>
2801<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2802:
2803<code>
2804<span style='white-space: nowrap'>&nbsp;\[<br>
2805info(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>
2806\]&nbsp;</span></code>
2807
2808where the maximum is with respect to
2809<code>
2810<span style='white-space: nowrap'>&nbsp;i&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;\ell</span></code>
2811 and
2812<code>
2813<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
2814.
2815
2816
2817<br>
2818<br>
2819<b><a name="4.s.d" id="4.s.d">4.s.d: Step Size</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;4)</span></font></code> is the line search step size used during
2822iteration <code>
2823<span style='white-space: nowrap'>&nbsp;q-1</span></code>
2824.
2825Small step sizes indicate problems with the interior point method
2826used to solve the affine problem
2827(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).
2828
2829
2830
2831
2832<br>
2833<br>
2834<b><big><a name="4.t" id="4.t">4.t: Example</a></big></b>
2835<br>
2836The file <a href="#4.1">4.1: <span style='white-space: nowrap'>affine_ok_box.m</span></a>
2837 contains an example and test of
2838<code><font color="blue">ckbs_affine</font></code>.
2839It returns true if <code><font color="blue">ckbs_affine</font></code> passes the test
2840and false otherwise.
2841
2842
2843<hr>Input File: ../src/ckbs_affine.m
2844
2845<hr>
2846 
2847
2848
2849<center><b><big><big><a name="4.1" id="4.1">4.1: ckbs_affine Box Constrained Smoothing Spline Example and Test</a>
2850</big></big></b></center>
2851<br>
2852<b><big><a name="4.1.a" id="4.1.a">4.1.a: Syntax</a></big></b>
2853
2854<br>
2855<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>
2856
2857<br>
2858<br>
2859<b><big><a name="4.1.b" id="4.1.b">4.1.b: draw_plot</a></big></b>
2860<br>
2861If this argument is true, a plot is drawn showing the results
2862and the <code><font color="blue">nonlinear_ok_box.out</font></code> file is written for use with
2863the program <code><font color="blue">nonlinear_ok_box.r</font></code>.
2864
2865<br>
2866<br>
2867<b><big><a name="4.1.c" id="4.1.c">4.1.c: ok</a></big></b>
2868<br>
2869If the return value <i>ok</i> is true, the test passed,
2870otherwise the test failed.
2871
2872<br>
2873<br>
2874<b><big><a name="4.1.d" id="4.1.d">4.1.d: State Vector</a></big></b>
2875
2876<table><tr><td align='left'  valign='top'>
2877
2878<code>
2879<span style='white-space: nowrap'>&nbsp;x1&nbsp;(t)</span></code>
2880 </td><td align='left'  valign='top'>
2881 derivative of function we are estimating </td></tr><tr><td align='left'  valign='top'>
2882
2883<code>
2884<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
2885 </td><td align='left'  valign='top'>
2886 value of function we are estimating
2887</td></tr>
2888</table>
2889<br>
2890<b><big><a name="4.1.e" id="4.1.e">4.1.e: Measurement</a></big></b>
2891
2892<br>
2893<code>
2894<span style='white-space: nowrap'>&nbsp;z1&nbsp;(t)</span></code>
2895 value of <code>
2896<span style='white-space: nowrap'>&nbsp;x2&nbsp;(t)</span></code>
2897 plus noise
2898
2899<br>
2900<br>
2901<b><big><a name="4.1.f" id="4.1.f">4.1.f: Constraint</a></big></b>
2902
2903<br>
2904<code>
2905<span style='white-space: nowrap'>&nbsp;\[<br>
2906&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\begin{array}{c}<br>
2907&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-1&nbsp;\leq&nbsp;x1&nbsp;(t)&nbsp;\leq&nbsp;+1<br>
2908&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
2909&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-1&nbsp;\leq&nbsp;x2&nbsp;(t)&nbsp;\leq&nbsp;+1<br>
2910&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\end{array}<br>
2911\]</span></code>
2912.
2913
2914<br>
2915<br>
2916<b><big><a name="4.1.g" id="4.1.g">4.1.g: Source Code</a></big></b>
2917
2918
2919 <code><font color='blue'><pre style='display:inline'> 
2920function [ok] = affine_ok_box(draw_plot)
2921% --------------------------------------------------------
2922% You can change these parameters
2923N     = 50;        % number of measurement time points
2924dt    = 2*pi / N;  % time between measurement points
2925gamma =  1;        % transition covariance multiplier
2926sigma =  .5;       % standard deviation of measurement noise
2927max_itr = 30;      % maximum number of iterations
2928epsilon = 1e-5;    % convergence criteria
2929h_min   = 0;       % minimum horizontal value in plots
2930h_max   = 7;       % maximum horizontal value in plots
2931v_min   = -2.0;    % minimum vertical value in plots
2932v_max   = +2.0;    % maximum vertical value in plots
2933% ---------------------------------------------------------
2934ok = true;
2935if nargin &lt; 1
2936        draw_plot = false;
2937end
2938%  Define the problem
2939rand('seed', 1234);
2940%
2941% number of constraints per time point
2942ell   = 4;
2943%
2944% number of measurements per time point
2945m     = 1;
2946%
2947% number of state vector components per time point
2948n     = 2;
2949%
2950% simulate the true trajectory and measurement noise
2951t       =  (1 : N) * dt;
2952x1_true = - cos(t);
2953x2_true = - sin(t);
2954x_true  = [ x1_true ; x2_true ];
2955v_true  = sigma * rand(1, N);
2956%
2957% measurement values and model
2958v_true  = sigma * randn(1, N);
2959z       = x2_true + v_true;
2960rk      = sigma * sigma;
2961rinvk   = 1 / rk;
2962rinv    = zeros(m, m, N);
2963h       = zeros(m, N);
2964dh      = zeros(m, n, N);
2965for k = 1 : N
2966        rinv(:, :, k) = rinvk;
2967        h(:, k)       = 0;
2968        dh(:,:, k)    = [ 0 , 1 ];
2969end
2970%
2971% transition model
2972g       = zeros(n, N);
2973dg      = zeros(n, n, N);
2974qinv    = zeros(n, n, N);
2975qk      = gamma * [ dt , dt^2/2 ; dt^2/2 , dt^3/3 ];
2976qinvk   = inv(qk);
2977for k = 2 : N
2978        g(:, k)       = 0;
2979        dg(:,:, k)    = [ 1 , 0 ; dt , 1 ];
2980        qinv(:,:, k)  = qinvk;
2981end
2982%
2983% initial state estimate
2984g(:, 1)      = x_true(:, 1);
2985qinv(:,:, 1) = 100 * eye(2);
2986%
2987% constraints
2988b       = zeros(ell, N);
2989db      = zeros(ell, n, N);
2990for k = 1 : N
2991        %
2992        % b(:, k) + db(:,:, k) * x(:, k) &lt;= 0
2993        b(:, k)    = [ -1 ; -1 ; -1 ; -1 ];
2994        db(:,:, k) = [ -1 , 0 ; 1 , 0 ; 0 , -1 ; 0 , 1 ];
2995end
2996%
2997% -------------------------------------------------------------------------
2998[xOut, uOut, info] = ...
2999        ckbs_affine(max_itr, epsilon, z, b, g, h, db, dg, dh, qinv, rinv);
3000% --------------------------------------------------------------------------
3001ok   = ok &amp; all( info(end, 1:3) &lt;= epsilon);
3002d    = ckbs_sumsq_grad(xOut, z, g, h, dg, dh, qinv, rinv);
3003for k = 1 : N
3004        xk = xOut(:, k);
3005        uk = uOut(:, k);
3006        bk = b(:, k);
3007        Bk = db(:,:, k);
3008        dk = d(:, k);
3009        sk = - bk - Bk * xk;
3010        %
3011        ok = ok &amp; (min(uk) &gt;= 0.);
3012        ok = ok &amp; (max (bk + Bk * xk) &lt;= epsilon);
3013        ok = ok &amp; (max ( abs( Bk' * uk + dk ) ) &lt;= epsilon);
3014        ok = ok &amp; (max ( uk .* sk ) &lt;= epsilon );
3015end
3016if draw_plot
3017        figure(1);
3018        clf
3019        hold on
3020        plot(t', x_true(2,:)', 'r-' );
3021        plot(t', z(1,:)', 'ko' );
3022        plot(t', xOut(2,:)', 'b-' );
3023        plot(t', - ones(N,1), 'b-');
3024        plot(t', ones(N,1), 'b-');
3025        axis([h_min, h_max, v_min, v_max]);
3026        title('Constrained');
3027        hold off
3028        %
3029        % constrained estimate
3030        x_con = xOut;
3031end
3032%
3033% Unconstrained Case
3034b           = zeros(0, N);
3035db          = zeros(0, n, N);
3036% -------------------------------------------------------------------------
3037[xOut, uOut, info] = ...
3038        ckbs_affine(max_itr, epsilon, z, b, g, h, db, dg, dh, qinv, rinv);
3039% --------------------------------------------------------------------------
3040ok   = ok &amp; all( info(end, 1:3) &lt;= epsilon);
3041d    = ckbs_sumsq_grad(xOut, z, g, h, dg, dh, qinv, rinv);
3042for k = 1 : N
3043        xk = xOut(:, k);
3044        dk = d(:, k);
3045        %
3046        ok = ok &amp; (min(dk) &lt;= epsilon);
3047end
3048if draw_plot
3049        figure(2);
3050        clf
3051        hold on
3052        plot(t', x_true(2,:)', 'r-' );
3053        plot(t', z(1,:)', 'ko' );
3054        plot(t', xOut(2,:)', 'b-' );
3055        plot(t', - ones(N,1), 'b-');
3056        plot(t', ones(N,1), 'b-');
3057        axis([h_min, h_max, v_min, v_max]);
3058        title('Unconstrained');
3059        hold off
3060        %
3061        % unconstrained estimate
3062        x_free = xOut;
3063        %
3064        % write out constrained and unconstrained results
3065        [fid, msg] = fopen('affine_ok_box.out', 'wt');
3066        if size(msg, 2) &gt; 0
3067                disp(['affine_ok: ', msg]);
3068        end
3069        %                      123456789012345678901234'
3070        heading =             '       t';
3071        heading = [ heading , ' x2_true  x2_con x2_free' ];
3072        heading = [ heading , '      z1\n'               ];
3073        fprintf(fid, heading);
3074        for k = 1 : N
3075                fprintf(fid,'%8.3f%8.3f%8.3f%8.3f%8.3f\n', ...
3076                        t(k), ...
3077                        x_true(2,k), x_con(2,k), x_free(2,k), ...
3078                        z(1,k) ...
3079                );
3080        end
3081        fclose(fid);
3082end
3083return
3084end
3085</pre></font></code>
3086 
3087
3088<hr>Input File: ../test/affine_ok_box.m
3089
3090<hr>
3091
3092
3093
3094<center><b><big><big><a name="5" id="5">5: ckbs Utility Functions</a>
3095</big></big></b></center>
3096<br>
3097<b><big><a name="5.a" id="5.a">5.a: Contents</a></big></b>
3098<br>
3099<table>
3100<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>
3101<hr>Input File: ../omh/utility.omh
3102
3103<hr>
3104<center><b><big><big><a name="5.1" id="5.1">5.1: Packed Block Diagonal Matrix Times a Vector</a>
3105</big></big></b></center>
3106<br>
3107<b><big><a name="5.1.a" id="5.1.a">5.1.a: Syntax</a></big></b>
3108
3109<br>
3110<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>
3111
3112<br>
3113<br>
3114<b><big><a name="5.1.b" id="5.1.b">5.1.b: Purpose</a></big></b>
3115<br>
3116This routine enables one to used the packed form of a block diagonal matrix
3117and returns the matrix times a vector; i.e.,
3118<code>
3119<span style='white-space: nowrap'>&nbsp;\[<br>
3120&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;=&nbsp;B&nbsp;*&nbsp;v<br>
3121\]&nbsp;</span></code>
3122
3123
3124<br>
3125<br>
3126<b><big><a name="5.1.c" id="5.1.c">5.1.c: Bdia</a></big></b>
3127<br>
3128The argument <i>Bdia</i> is an <code>
3129<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3130 array.
3131For <code>
3132<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3133 we define <code>
3134<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
3135 by
3136<code>
3137<span style='white-space: nowrap'>&nbsp;\[<br>
3138&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
3139\]&nbsp;</span></code>
3140
3141
3142<br>
3143<br>
3144<b><big><a name="5.1.d" id="5.1.d">5.1.d: B</a></big></b>
3145<br>
3146The matrix <code>
3147<span style='white-space: nowrap'>&nbsp;B</span></code>
3148 is defined by
3149<code>
3150<span style='white-space: nowrap'>&nbsp;\[<br>
3151B&nbsp;<br>
3152=<br>
3153\left(&nbsp;\begin{array}{cccc}<br>
3154&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>
3155&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>
3156&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>
3157&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>
3158\end{array}&nbsp;\right)<br>
3159\]&nbsp;</span></code>
3160
3161
3162<br>
3163<br>
3164<b><big><a name="5.1.e" id="5.1.e">5.1.e: v</a></big></b>
3165<br>
3166The argument <i>v</i> is a column vector of length <code>
3167<span style='white-space: nowrap'>&nbsp;n&nbsp;*&nbsp;N</span></code>
3168.
3169
3170<br>
3171<br>
3172<b><big><a name="5.1.f" id="5.1.f">5.1.f: w</a></big></b>
3173<br>
3174The result <i>w</i> is a column vector of length <code>
3175<span style='white-space: nowrap'>&nbsp;m&nbsp;*&nbsp;N</span></code>
3176.
3177
3178
3179
3180
3181<br>
3182<br>
3183<b><big><a name="5.1.g" id="5.1.g">5.1.g: Example</a></big></b>
3184<br>
3185The file <a href="#5.1.1">5.1.1: <span style='white-space: nowrap'>blkdiag_mul_ok.m</span></a>
3186 contains an example and test of
3187<code><font color="blue">ckbs_blkdiag_mul</font></code>.
3188It returns true if <code><font color="blue">ckbs_blkdiag_mul</font></code> passes the test
3189and false otherwise.
3190
3191
3192<hr>Input File: ../src/ckbs_blkdiag_mul.m
3193
3194<hr>
3195 
3196
3197
3198<center><b><big><big><a name="5.1.1" id="5.1.1">5.1.1: blkdiag_mul Example and Test</a>
3199</big></big></b></center>
3200<br>
3201<b><big><a name="5.1.1.a" id="5.1.1.a">5.1.1.a: Source Code</a></big></b>
3202
3203 <code><font color='blue'><pre style='display:inline'> 
3204function [ok] = blkdiag_mul_ok()
3205ok = true;
3206% -------------------------------------------------------------
3207% You can change these parameters
3208m    = 2;
3209n    = 3;
3210N    = 2;
3211% -------------------------------------------------------------
3212% Define the problem
3213rand('seed', 123);
3214v     = rand(n * N, 1);
3215Bdiag = zeros(m, n, N);
3216B     = zeros(m * N , n * N);
3217blk_m = 1 : m;
3218blk_n = 1 : n;
3219for k = 1 : N
3220        Bdiag(:, :, k)  = rand(m, n);
3221        B(blk_m, blk_n) = Bdiag(:, :, k);
3222        blk_m           = blk_m + m;
3223        blk_n           = blk_n + n;
3224end
3225% -------------------------------------
3226w     = ckbs_blkdiag_mul(Bdiag, v);
3227% -------------------------------------
3228check = B * v;
3229ok    = ok &amp; ( max(abs(w - check)) &lt; 1e-10 );
3230return
3231end
3232</pre></font></code>
3233 
3234
3235<hr>Input File: ../test/blkdiag_mul_ok.m
3236
3237<hr>
3238 
3239
3240
3241<center><b><big><big><a name="5.2" id="5.2">5.2: Transpose of Packed Block Diagonal Matrix Times a Vector</a>
3242</big></big></b></center>
3243<br>
3244<b><big><a name="5.2.a" id="5.2.a">5.2.a: Syntax</a></big></b>
3245
3246<br>
3247<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>
3248
3249<br>
3250<br>
3251<b><big><a name="5.2.b" id="5.2.b">5.2.b: Purpose</a></big></b>
3252<br>
3253This routine enables one to used the packed form of a block diagonal matrix
3254and returns the transpose of the matrix times a vector; i.e.,
3255<code>
3256<span style='white-space: nowrap'>&nbsp;\[<br>
3257&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;=&nbsp;B^\T&nbsp;*&nbsp;v<br>
3258\]&nbsp;</span></code>
3259
3260
3261<br>
3262<br>
3263<b><big><a name="5.2.c" id="5.2.c">5.2.c: Bdia</a></big></b>
3264<br>
3265The argument <i>Bdia</i> is an <code>
3266<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3267 array.
3268For <code>
3269<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3270 we define <code>
3271<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
3272 by
3273<code>
3274<span style='white-space: nowrap'>&nbsp;\[<br>
3275&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
3276\]&nbsp;</span></code>
3277
3278
3279<br>
3280<br>
3281<b><big><a name="5.2.d" id="5.2.d">5.2.d: B</a></big></b>
3282<br>
3283The matrix <code>
3284<span style='white-space: nowrap'>&nbsp;B</span></code>
3285 is defined by
3286<code>
3287<span style='white-space: nowrap'>&nbsp;\[<br>
3288B&nbsp;<br>
3289=<br>
3290\left(&nbsp;\begin{array}{cccc}<br>
3291&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>
3292&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>
3293&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>
3294&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>
3295\end{array}&nbsp;\right)<br>
3296\]&nbsp;</span></code>
3297
3298
3299<br>
3300<br>
3301<b><big><a name="5.2.e" id="5.2.e">5.2.e: v</a></big></b>
3302<br>
3303The argument <i>v</i> is a column vector of length <code>
3304<span style='white-space: nowrap'>&nbsp;m&nbsp;*&nbsp;N</span></code>
3305.
3306
3307<br>
3308<br>
3309<b><big><a name="5.2.f" id="5.2.f">5.2.f: w</a></big></b>
3310<br>
3311The result <i>w</i> is a column vector of length <code>
3312<span style='white-space: nowrap'>&nbsp;n&nbsp;*&nbsp;N</span></code>
3313.
3314
3315
3316
3317<br>
3318<br>
3319<b><big><a name="5.2.g" id="5.2.g">5.2.g: Example</a></big></b>
3320<br>
3321The file <a href="#5.2.1">5.2.1: <span style='white-space: nowrap'>blkdiag_mul_t_ok.m</span></a>
3322 contains an example and test of
3323<code><font color="blue">ckbs_blkdiag_mul_t</font></code>.
3324It returns true if <code><font color="blue">ckbs_blkdiag_mul_t</font></code> passes the test
3325and false otherwise.
3326
3327
3328<hr>Input File: ../src/ckbs_blkdiag_mul_t.m
3329
3330<hr>
3331 
3332
3333
3334<center><b><big><big><a name="5.2.1" id="5.2.1">5.2.1: blkdiag_mul_t Example and Test</a>
3335</big></big></b></center>
3336<br>
3337<b><big><a name="5.2.1.a" id="5.2.1.a">5.2.1.a: Source Code</a></big></b>
3338
3339 <code><font color='blue'><pre style='display:inline'> 
3340function [ok] = blkdiag_mul_t_ok()
3341ok = true;
3342% -------------------------------------------------------------
3343% You can change these parameters
3344m    = 2;
3345n    = 3;
3346N    = 2;
3347% -------------------------------------------------------------
3348% Define the problem
3349rand('seed', 123);
3350v     = rand(m * N, 1);
3351Bdiag = zeros(m, n, N);
3352B     = zeros(m * N , n * N);
3353blk_m = 1 : m;
3354blk_n = 1 : n;
3355for k = 1 : N
3356        Bdiag(:, :, k)  = rand(m, n);
3357        B(blk_m, blk_n) = Bdiag(:, :, k);
3358        blk_m           = blk_m + m;
3359        blk_n           = blk_n + n;
3360end
3361% -------------------------------------
3362w     = ckbs_blkdiag_mul_t(Bdiag, v);
3363% -------------------------------------
3364check = B' * v;
3365ok    = ok &amp; ( max(abs(w - check)) &lt; 1e-10 );
3366return
3367end
3368</pre></font></code>
3369 
3370
3371<hr>Input File: ../test/blkdiag_mul_t_ok.m
3372
3373<hr>
3374 
3375
3376
3377<center><b><big><big><a name="5.3" id="5.3">5.3: Affine Residual Sum of Squares Objective</a>
3378</big></big></b></center>
3379<br>
3380<b><big><a name="5.3.a" id="5.3.a">5.3.a: Syntax</a></big></b>
3381
3382<br>
3383<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>
3384
3385<br>
3386<br>
3387<b><big><a name="5.3.b" id="5.3.b">5.3.b: Purpose</a></big></b>
3388<br>
3389This routine computes the value of the
3390affine Kalman-Bucy smoother residual sum of squares objective function.
3391
3392<br>
3393<br>
3394<b><big><a name="5.3.c" id="5.3.c">5.3.c: Notation</a></big></b>
3395<br>
3396The affine Kalman-Bucy smoother residual sum of squares is defined by
3397<code>
3398<span style='white-space: nowrap'>&nbsp;\[<br>
3399\begin{array}{rcl}<br>
3400S&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>
3401S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
3402\frac{1}{2}&nbsp;<br>
3403(&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>
3404\\<br>
3405&amp;&nbsp;+&nbsp;&amp;<br>
3406\frac{1}{2}&nbsp;<br>
3407(&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>
3408\\<br>
3409\end{array}<br>
3410\]&nbsp;</span></code>
3411
3412where the matrices <code>
3413<span style='white-space: nowrap'>&nbsp;R_k</span></code>
3414 and <code>
3415<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
3416 are
3417symmetric positive definite and
3418<code>
3419<span style='white-space: nowrap'>&nbsp;x_0</span></code>
3420 is the constant zero.
3421
3422<br>
3423<br>
3424<b><big><a name="5.3.d" id="5.3.d">5.3.d: x</a></big></b>
3425<br>
3426The argument <i>x</i> is a two dimensional array,
3427for <code>
3428<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3429
3430<code>
3431<span style='white-space: nowrap'>&nbsp;\[<br>
3432&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x_k&nbsp;=&nbsp;x(:,&nbsp;k)<br>
3433\]</span></code>
3434
3435and <i>x</i> has size <code>
3436<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3437.
3438
3439<br>
3440<br>
3441<b><big><a name="5.3.e" id="5.3.e">5.3.e: z</a></big></b>
3442<br>
3443The argument <i>z</i> is a two dimensional array,
3444for <code>
3445<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3446
3447<code>
3448<span style='white-space: nowrap'>&nbsp;\[<br>
3449&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z_k&nbsp;=&nbsp;z(:,&nbsp;k)<br>
3450\]</span></code>
3451
3452and <i>z</i> has size <code>
3453<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3454.
3455
3456<br>
3457<br>
3458<b><big><a name="5.3.f" id="5.3.f">5.3.f: g</a></big></b>
3459<br>
3460The argument <i>g</i> is a two dimensional array,
3461for <code>
3462<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3463
3464<code>
3465<span style='white-space: nowrap'>&nbsp;\[<br>
3466&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_k&nbsp;=&nbsp;g(:,&nbsp;k)<br>
3467\]</span></code>
3468
3469and <i>g</i> has size <code>
3470<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3471.
3472
3473<br>
3474<br>
3475<b><big><a name="5.3.g" id="5.3.g">5.3.g: h</a></big></b>
3476<br>
3477The argument <i>h</i> is a two dimensional array,
3478for <code>
3479<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3480
3481<code>
3482<span style='white-space: nowrap'>&nbsp;\[<br>
3483&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h_k&nbsp;=&nbsp;h(:,&nbsp;k)<br>
3484\]</span></code>
3485
3486and <i>h</i> has size <code>
3487<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3488.
3489
3490<br>
3491<br>
3492<b><big><a name="5.3.h" id="5.3.h">5.3.h: dg</a></big></b>
3493<br>
3494The argument <i>dg</i> is a three dimensional array,
3495for <code>
3496<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3497
3498<code>
3499<span style='white-space: nowrap'>&nbsp;\[<br>
3500&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
3501\]</span></code>
3502
3503and <i>dg</i> has size <code>
3504<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3505.
3506
3507<br>
3508<br>
3509<b><big><a name="5.3.i" id="5.3.i">5.3.i: dh</a></big></b>
3510<br>
3511The argument <i>dh</i> is a three dimensional array,
3512for <code>
3513<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3514
3515<code>
3516<span style='white-space: nowrap'>&nbsp;\[<br>
3517&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
3518\]</span></code>
3519
3520and <i>dh</i> has size <code>
3521<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3522.
3523
3524<br>
3525<br>
3526<b><big><a name="5.3.j" id="5.3.j">5.3.j: qinv</a></big></b>
3527<br>
3528The argument <i>qinv</i> is a three dimensional array,
3529for <code>
3530<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3531
3532<code>
3533<span style='white-space: nowrap'>&nbsp;\[<br>
3534&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,&nbsp;k)<br>
3535\]</span></code>
3536
3537and <i>qinv</i> has size <code>
3538<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3539.
3540
3541<br>
3542<br>
3543<b><big><a name="5.3.k" id="5.3.k">5.3.k: rinv</a></big></b>
3544<br>
3545The argument <i>rinv</i> is a three dimensional array,
3546for <code>
3547<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3548
3549<code>
3550<span style='white-space: nowrap'>&nbsp;\[<br>
3551&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,&nbsp;k)<br>
3552\]</span></code>
3553
3554and <i>rinv</i> has size <code>
3555<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
3556.
3557
3558<br>
3559<br>
3560<b><big><a name="5.3.l" id="5.3.l">5.3.l: obj</a></big></b>
3561<br>
3562The result <i>obj</i> is a scalar given by
3563<code>
3564<span style='white-space: nowrap'>&nbsp;\[<br>
3565&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj&nbsp;=&nbsp;S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)<br>
3566\]&nbsp;</span></code>
3567
3568
3569
3570
3571<br>
3572<br>
3573<b><big><a name="5.3.m" id="5.3.m">5.3.m: Example</a></big></b>
3574<br>
3575The file <a href="#5.3.1">5.3.1: <span style='white-space: nowrap'>sumsq_obj_ok.m</span></a>
3576 contains an example and test of
3577<code><font color="blue">ckbs_sumsq_obj</font></code>.
3578It returns true if <code><font color="blue">ckbs_sumsq_obj</font></code> passes the test
3579and false otherwise.
3580
3581
3582<hr>Input File: ../src/ckbs_sumsq_obj.m
3583
3584<hr>
3585 
3586
3587
3588<center><b><big><big><a name="5.3.1" id="5.3.1">5.3.1: ckbs_sumsq_obj Example and Test</a>
3589</big></big></b></center>
3590<br>
3591<b><big><a name="5.3.1.a" id="5.3.1.a">5.3.1.a: Source Code</a></big></b>
3592
3593 <code><font color='blue'><pre style='display:inline'> 
3594function [ok] = sumsq_obj_ok()
3595ok = true;
3596% --------------------------------------------------------
3597% You can change these parameters
3598m    = 1;   % number of measurements per time point
3599n    = 2;   % number of state vector components per time point
3600N    = 3;   % number of time points
3601% ---------------------------------------------------------
3602%  Define the problem
3603rand('seed', 123);
3604x    = rand(n, N);
3605z    = rand(m, N);
3606h    = rand(m, N);
3607g    = rand(n, N);
3608dh   = zeros(m, n, N);
3609dg   = zeros(n, n, N);
3610qinv = zeros(n, n, N);
3611rinv = zeros(m, m, N);
3612for k = 1 : N
3613        dh(:, :, k)   = rand(m, n);
3614        dg(:, :, k)   = rand(n, n);
3615        tmp           = rand(m, m);
3616        rinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(m);
3617        tmp           = rand(n, n);
3618        qinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(n);
3619end
3620% ---------------------------------------------------------
3621% Compute the Objective using ckbs_sumsq_obj
3622obj  = ckbs_sumsq_obj(x, z, g, h, dg, dh, qinv, rinv);
3623% ---------------------------------------------------------
3624sumsq = 0;
3625xk    = zeros(n, 1);
3626for k = 1 : N
3627        xkm   = xk;
3628        xk    = x(:, k);
3629        xres  = xk      - g(:, k) - dg(:,:, k) * xkm;
3630        zres  = z(:, k) - h(:, k) - dh(:,:, k) * xk;
3631        sumsq = sumsq + xres' * qinv(:,:, k) * xres;
3632        sumsq = sumsq + zres' * rinv(:,:, k) * zres;
3633end
3634ok = ok &amp; ( abs(obj - sumsq/2) &lt; 1e-10 );
3635return
3636end
3637</pre></font></code>
3638 
3639
3640<hr>Input File: ../test/sumsq_obj_ok.m
3641
3642<hr>
3643 
3644
3645
3646<center><b><big><big><a name="5.4" id="5.4">5.4: Affine Residual Sum of Squares Gradient</a>
3647</big></big></b></center>
3648<br>
3649<b><big><a name="5.4.a" id="5.4.a">5.4.a: Syntax</a></big></b>
3650
3651<br>
3652<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>
3653
3654<br>
3655<br>
3656<b><big><a name="5.4.b" id="5.4.b">5.4.b: Purpose</a></big></b>
3657<br>
3658This computes the gradient of the
3659of the affine Kalman-Bucy smoother residual sum of squares.
3660
3661<br>
3662<br>
3663<b><big><a name="5.4.c" id="5.4.c">5.4.c: Notation</a></big></b>
3664<br>
3665The affine Kalman-Bucy smoother residual sum of squares is defined by
3666<code>
3667<span style='white-space: nowrap'>&nbsp;\[<br>
3668\begin{array}{rcl}<br>
3669S&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>
3670S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
3671\frac{1}{2}&nbsp;<br>
3672(&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>
3673\\<br>
3674&amp;&nbsp;+&nbsp;&amp;<br>
3675\frac{1}{2}&nbsp;<br>
3676(&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>
3677\end{array}<br>
3678\]&nbsp;</span></code>
3679
3680where the matrices <code>
3681<span style='white-space: nowrap'>&nbsp;R_k</span></code>
3682 and <code>
3683<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
3684 are
3685symmetric positive definite and
3686<code>
3687<span style='white-space: nowrap'>&nbsp;x_0</span></code>
3688 is the constant zero.
3689
3690<br>
3691<br>
3692<b><big><a name="5.4.d" id="5.4.d">5.4.d: Gradient</a></big></b>
3693<br>
3694We define <code>
3695<span style='white-space: nowrap'>&nbsp;Q_{N+1}</span></code>
3696 to be the <code>
3697<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
3698 identity
3699matrix and <code>
3700<span style='white-space: nowrap'>&nbsp;G_{N+1}</span></code>
3701 to be zero,
3702<code>
3703<span style='white-space: nowrap'>&nbsp;\[<br>
3704\begin{array}{rcl}<br>
3705\nabla_k&nbsp;S_k^{(1)}&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;<br>
3706&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>
3707&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>
3708\\<br>
3709\nabla_k&nbsp;S_{k+1}^{(1)}&nbsp;(&nbsp;x_{k+1}&nbsp;,&nbsp;x_k&nbsp;)&nbsp;<br>
3710&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>
3711\end{array}<br>
3712\]&nbsp;</span></code>
3713
3714It follows that the gradient of the
3715affine Kalman-Bucy smoother residual sum of squares is
3716<code>
3717<span style='white-space: nowrap'>&nbsp;\[<br>
3718\begin{array}{rcl}<br>
3719\nabla&nbsp;S&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;<br>
3720&amp;&nbsp;=&nbsp;&amp;<br>
3721\left(&nbsp;\begin{array}{c}<br>
3722&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d_1&nbsp;\\&nbsp;\vdots&nbsp;\\&nbsp;d_N<br>
3723\end{array}&nbsp;\right)<br>
3724\\<br>
3725d_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>
3726&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>
3727\end{array}<br>
3728\]&nbsp;</span></code>
3729
3730where <code>
3731<span style='white-space: nowrap'>&nbsp;S_{N+1}&nbsp;(&nbsp;x_{N+1}&nbsp;,&nbsp;x_N&nbsp;)</span></code>
3732 is defined as
3733identically zero.
3734
3735<br>
3736<br>
3737<b><big><a name="5.4.e" id="5.4.e">5.4.e: x</a></big></b>
3738<br>
3739The argument <i>x</i> is a two dimensional array,
3740for <code>
3741<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3742
3743<code>
3744<span style='white-space: nowrap'>&nbsp;\[<br>
3745&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x_k&nbsp;=&nbsp;x(:,&nbsp;k)<br>
3746\]</span></code>
3747
3748and <i>x</i> has size <code>
3749<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3750.
3751
3752<br>
3753<br>
3754<b><big><a name="5.4.f" id="5.4.f">5.4.f: z</a></big></b>
3755<br>
3756The argument <i>z</i> is a two dimensional array,
3757for <code>
3758<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3759
3760<code>
3761<span style='white-space: nowrap'>&nbsp;\[<br>
3762&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z_k&nbsp;=&nbsp;z(:,&nbsp;k)<br>
3763\]</span></code>
3764
3765and <i>z</i> has size <code>
3766<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3767.
3768
3769<br>
3770<br>
3771<b><big><a name="5.4.g" id="5.4.g">5.4.g: g</a></big></b>
3772<br>
3773The argument <i>g</i> is a two dimensional array,
3774for <code>
3775<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3776
3777<code>
3778<span style='white-space: nowrap'>&nbsp;\[<br>
3779&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;g_k&nbsp;=&nbsp;g(:,&nbsp;k)<br>
3780\]</span></code>
3781
3782and <i>g</i> has size <code>
3783<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3784.
3785
3786<br>
3787<br>
3788<b><big><a name="5.4.h" id="5.4.h">5.4.h: h</a></big></b>
3789<br>
3790The argument <i>h</i> is a two dimensional array,
3791for <code>
3792<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3793
3794<code>
3795<span style='white-space: nowrap'>&nbsp;\[<br>
3796&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h_k&nbsp;=&nbsp;h(:,&nbsp;k)<br>
3797\]</span></code>
3798
3799and <i>h</i> has size <code>
3800<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;N</span></code>
3801.
3802
3803<br>
3804<br>
3805<b><big><a name="5.4.i" id="5.4.i">5.4.i: dg</a></big></b>
3806<br>
3807The argument <i>dg</i> is a three dimensional array,
3808for <code>
3809<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3810
3811<code>
3812<span style='white-space: nowrap'>&nbsp;\[<br>
3813&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
3814\]</span></code>
3815
3816and <i>dg</i> has size <code>
3817<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3818.
3819
3820<br>
3821<br>
3822<b><big><a name="5.4.j" id="5.4.j">5.4.j: dh</a></big></b>
3823<br>
3824The argument <i>dh</i> is a three dimensional array,
3825for <code>
3826<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3827
3828<code>
3829<span style='white-space: nowrap'>&nbsp;\[<br>
3830&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
3831\]</span></code>
3832
3833and <i>dh</i> has size <code>
3834<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3835.
3836
3837<br>
3838<br>
3839<b><big><a name="5.4.k" id="5.4.k">5.4.k: qinv</a></big></b>
3840<br>
3841The argument <i>qinv</i> is a three dimensional array,
3842for <code>
3843<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3844
3845<code>
3846<span style='white-space: nowrap'>&nbsp;\[<br>
3847&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,k)<br>
3848\]</span></code>
3849
3850and <i>qinv</i> has size <code>
3851<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
3852.
3853
3854<br>
3855<br>
3856<b><big><a name="5.4.l" id="5.4.l">5.4.l: rinv</a></big></b>
3857<br>
3858The argument <i>rinv</i> is a three dimensional array,
3859for <code>
3860<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3861
3862<code>
3863<span style='white-space: nowrap'>&nbsp;\[<br>
3864&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,k)<br>
3865\]</span></code>
3866
3867and <i>rinv</i> has size <code>
3868<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
3869.
3870
3871<br>
3872<br>
3873<b><big><a name="5.4.m" id="5.4.m">5.4.m: grad</a></big></b>
3874<br>
3875The result <i>grad</i> is a two dimensional array,
3876for <code>
3877<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
3878
3879<code>
3880<span style='white-space: nowrap'>&nbsp;\[<br>
3881&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d_k&nbsp;=&nbsp;grad(:,&nbsp;k)<br>
3882\]</span></code>
3883
3884and <i>grad</i> has size <code>
3885<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;N</span></code>
3886.
3887
3888
3889
3890<br>
3891<br>
3892<b><big><a name="5.4.n" id="5.4.n">5.4.n: Example</a></big></b>
3893<br>
3894The file <a href="#5.4.1">5.4.1: <span style='white-space: nowrap'>sumsq_grad_ok.m</span></a>
3895 contains an example and test of
3896<code><font color="blue">ckbs_sumsq_grad</font></code>.
3897It returns true if <code><font color="blue">ckbs_sumsq_grad</font></code> passes the test
3898and false otherwise.
3899
3900
3901<hr>Input File: ../src/ckbs_sumsq_grad.m
3902
3903<hr>
3904 
3905
3906
3907<center><b><big><big><a name="5.4.1" id="5.4.1">5.4.1: ckbs_sumsq_grad Example and Test</a>
3908</big></big></b></center>
3909<br>
3910<b><big><a name="5.4.1.a" id="5.4.1.a">5.4.1.a: Source Code</a></big></b>
3911
3912 <code><font color='blue'><pre style='display:inline'> 
3913function [ok] = sumsq_grad_ok()
3914ok = true;
3915% --------------------------------------------------------
3916% You can change these parameters
3917m    = 1;   % number of measurements per time point
3918n    = 2;   % number of state vector components per time point
3919N    = 3;   % number of time points
3920% ---------------------------------------------------------
3921%  Define the problem
3922rand('seed', 123);
3923x    = rand(n, N);
3924z    = rand(m, N);
3925h    = rand(m, N);
3926g    = rand(n, N);
3927dg   = zeros(n, n, N);
3928dh   = zeros(m, n, N);
3929qinv = zeros(n, n, N);
3930rinv = zeros(m, m, N);
3931for k = 1 : N
3932        dh(:, :, k)   = rand(m, n);
3933        dg(:, :, k)   = rand(n, n);
3934        tmp           = rand(m, m);
3935        rinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(m);
3936        tmp           = rand(n, n);
3937        qinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(n);
3938end
3939% ---------------------------------------------------------
3940% Compute the gradient using ckbs_sumsq_grad
3941grad = ckbs_sumsq_grad(x, z, g, h, dg, dh, qinv, rinv);
3942% ---------------------------------------------------------
3943% Use finite differences to check gradient
3944step   = 1;
3945for k  = 1 : N
3946for i  = 1 : n
3947        % Check second partial w.r.t x(i,k)
3948        xm        = x;
3949        xm(i, k)  = xm(i, k) - step;
3950        Sm        = ckbs_sumsq_obj(xm, z, g, h, dg, dh, qinv, rinv);
3951        %
3952        xp        = x;
3953        xp(i, k)  = xp(i, k) + step;
3954        Sp        = ckbs_sumsq_obj(xp, z, g, h, dg, dh, qinv, rinv);
3955        %
3956        check  = (Sp - Sm) / ( 2 * step);
3957        diff   = grad(i, k) - check;
3958        ok     = ok &amp; ( abs(diff) &lt; 1e-10 );
3959end
3960end
3961return
3962end
3963</pre></font></code>
3964 
3965
3966<hr>Input File: ../test/sumsq_grad_ok.m
3967
3968<hr>
3969 
3970
3971
3972<center><b><big><big><a name="5.5" id="5.5">5.5: Affine Residual Sum of Squares Hessian</a>
3973</big></big></b></center>
3974<br>
3975<b><big><a name="5.5.a" id="5.5.a">5.5.a: Syntax</a></big></b>
3976
3977<br>
3978<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>
3979
3980<br>
3981<br>
3982<b><big><a name="5.5.b" id="5.5.b">5.5.b: Purpose</a></big></b>
3983<br>
3984This routine returns the diagonal and off diagonal blocks corresponding to
3985the Hessian of the affine Kalman-Bucy smoother residual sum of squares.
3986
3987<br>
3988<br>
3989<b><big><a name="5.5.c" id="5.5.c">5.5.c: Notation</a></big></b>
3990<br>
3991The affine Kalman-Bucy smoother residual sum of squares is defined by
3992<code>
3993<span style='white-space: nowrap'>&nbsp;\[<br>
3994\begin{array}{rcl}<br>
3995S&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>
3996S_k&nbsp;(&nbsp;x_k&nbsp;,&nbsp;x_{k-1}&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
3997\frac{1}{2}&nbsp;<br>
3998(&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>
3999\\<br>
4000&amp;&nbsp;+&nbsp;&amp;<br>
4001\frac{1}{2}&nbsp;<br>
4002(&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>
4003\end{array}<br>
4004\]&nbsp;</span></code>
4005
4006where the matrices <code>
4007<span style='white-space: nowrap'>&nbsp;R_k</span></code>
4008 and <code>
4009<span style='white-space: nowrap'>&nbsp;Q_k</span></code>
4010 are
4011symmetric positive definite and
4012<code>
4013<span style='white-space: nowrap'>&nbsp;x_0</span></code>
4014 is the constant zero.
4015
4016<br>
4017<br>
4018<b><big><a name="5.5.d" id="5.5.d">5.5.d: Hessian</a></big></b>
4019<br>
4020If we define <code>
4021<span style='white-space: nowrap'>&nbsp;Q_{N+1}</span></code>
4022 to be the <code>
4023<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
4024 identity
4025matrix and <code>
4026<span style='white-space: nowrap'>&nbsp;G_{N+1}</span></code>
4027 to be zero,
4028the Hessian of the
4029affine Kalman-Bucy smoother residual sum of squares is
4030<code>
4031<span style='white-space: nowrap'>&nbsp;\[<br>
4032\begin{array}{rcl}<br>
4033S^{(2)}&nbsp;(&nbsp;x_1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;x_N&nbsp;)&nbsp;&amp;&nbsp;=&nbsp;&amp;<br>
4034\left(&nbsp;\begin{array}{cccc}<br>
4035D_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>
4036A_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>
40370&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4038&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>
4039\end{array}&nbsp;\right)<br>
4040\\<br>
4041D_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>
4042&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;G_{k+1}^\T&nbsp;*&nbsp;Q_{k+1}^{-1}&nbsp;*&nbsp;G_{k+1}&nbsp;<br>
4043\\<br>
4044A_k&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;-&nbsp;Q_k^{-1}&nbsp;*&nbsp;G_k<br>
4045\end{array}<br>
4046\]&nbsp;</span></code>
4047
4048
4049<br>
4050<br>
4051<b><big><a name="5.5.e" id="5.5.e">5.5.e: dg</a></big></b>
4052<br>
4053The argument <i>dg</i> is a three dimensional array,
4054for <code>
4055<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4056
4057<code>
4058<span style='white-space: nowrap'>&nbsp;\[<br>
4059&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;G_k&nbsp;=&nbsp;dg(:,:,k)<br>
4060\]</span></code>
4061
4062and <i>dg</i> has size <code>
4063<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4064.
4065
4066<br>
4067<br>
4068<b><big><a name="5.5.f" id="5.5.f">5.5.f: dh</a></big></b>
4069<br>
4070The argument <i>dh</i> is a three dimensional array,
4071for <code>
4072<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4073
4074<code>
4075<span style='white-space: nowrap'>&nbsp;\[<br>
4076&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;dh(:,:,k)<br>
4077\]</span></code>
4078
4079and <i>dh</i> has size <code>
4080<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4081.
4082
4083<br>
4084<br>
4085<b><big><a name="5.5.g" id="5.5.g">5.5.g: qinv</a></big></b>
4086<br>
4087The argument <i>qinv</i> is a three dimensional array,
4088for <code>
4089<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4090
4091<code>
4092<span style='white-space: nowrap'>&nbsp;\[<br>
4093&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Q_k^{-1}&nbsp;=&nbsp;qinv(:,:,k)<br>
4094\]</span></code>
4095
4096and <i>qinv</i> has size <code>
4097<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4098.
4099
4100<br>
4101<br>
4102<b><big><a name="5.5.h" id="5.5.h">5.5.h: rinv</a></big></b>
4103<br>
4104The argument <i>rinv</i> is a three dimensional array,
4105for <code>
4106<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4107
4108<code>
4109<span style='white-space: nowrap'>&nbsp;\[<br>
4110&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R_k^{-1}&nbsp;=&nbsp;rinv(:,:,k)<br>
4111\]</span></code>
4112
4113and <i>rinv</i> has size <code>
4114<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;m&nbsp;\times&nbsp;N</span></code>
4115.
4116
4117<br>
4118<br>
4119<b><big><a name="5.5.i" id="5.5.i">5.5.i: D</a></big></b>
4120<br>
4121The result <i>D</i> is a three dimensional array,
4122for <code>
4123<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4124
4125<code>
4126<span style='white-space: nowrap'>&nbsp;\[<br>
4127&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D_k&nbsp;=&nbsp;D(:,:,k)<br>
4128\]</span></code>
4129
4130and <i>D</i> has size <code>
4131<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4132.
4133
4134<br>
4135<br>
4136<b><big><a name="5.5.j" id="5.5.j">5.5.j: A</a></big></b>
4137<br>
4138The result <i>A</i> is a three dimensional array,
4139for <code>
4140<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;2&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4141
4142<code>
4143<span style='white-space: nowrap'>&nbsp;\[<br>
4144&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A_k&nbsp;=&nbsp;A(:,:,k)<br>
4145\]</span></code>
4146
4147and <i>A</i> has size <code>
4148<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4149.
4150
4151
4152
4153
4154<br>
4155<br>
4156<b><big><a name="5.5.k" id="5.5.k">5.5.k: Example</a></big></b>
4157<br>
4158The file <a href="#5.5.1">5.5.1: <span style='white-space: nowrap'>sumsq_hes_ok.m</span></a>
4159 contains an example and test of
4160<code><font color="blue">ckbs_sumsq_hes</font></code>.
4161It returns true if <code><font color="blue">ckbs_sumsq_hes</font></code> passes the test
4162and false otherwise.
4163
4164
4165<hr>Input File: ../src/ckbs_sumsq_hes.m
4166
4167<hr>
4168 
4169
4170
4171<center><b><big><big><a name="5.5.1" id="5.5.1">5.5.1: ckbs_sumsq_hes Example and Test</a>
4172</big></big></b></center>
4173<br>
4174<b><big><a name="5.5.1.a" id="5.5.1.a">5.5.1.a: Source Code</a></big></b>
4175
4176 <code><font color='blue'><pre style='display:inline'> 
4177function [ok] = sumsq_hes_ok()
4178ok = true;
4179% --------------------------------------------------------
4180% You can change these parameters
4181m    = 1;   % number of measurements per time point
4182n    = 2;   % number of state vector components per time point
4183N    = 3;   % number of time points
4184% ---------------------------------------------------------
4185%  Define the problem
4186rand('seed', 123);
4187dg   = zeros(n, n, N);
4188dh   = zeros(m, n, N);
4189qinv = zeros(n, n, N);
4190rinv = zeros(m, m, N);
4191for k = 1 : N
4192        dh(:, :, k)   = rand(m, n);
4193        dg(:, :, k)   = rand(n, n);
4194        tmp           = rand(m, m);
4195        rinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(m);
4196        tmp           = rand(n, n);
4197        qinv(:, :, k) = (tmp + tmp') / 2 + 2 * eye(n);
4198end
4199% ---------------------------------------------------------
4200% Compute the Hessian using ckbs_sumsq_hes
4201[D, A] = ckbs_sumsq_hes(dg, dh, qinv, rinv);
4202% ---------------------------------------------------------
4203H    = zeros(n * N , n * N );
4204for k = 1 : N
4205        index           = (k - 1) * n + (1 : n);
4206        H(index, index) = D(:, :, k);
4207        if k &gt; 1
4208                H(index - n, index) = A(:, :, k)';
4209                H(index, index - n) = A(:, :, k);
4210        end
4211end
4212%
4213% Use finite differences to check Hessian
4214x    = rand(n, N);
4215z    = rand(m, N);
4216h    = rand(m, N);
4217g    = rand(n, N);
4218%
4219step   = 1;
4220for k = 1 : N
4221        for i = 1 : n
4222                % Check second partial w.r.t x(i, k)
4223                xm       = x;
4224                xm(i, k) = xm(i, k) - step;
4225                gradm = ckbs_sumsq_grad(xm, z, g, h, dg, dh, qinv, rinv);
4226                %
4227                xp       = x;
4228                xp(i, k) = xp(i, k) + step;
4229                gradp = ckbs_sumsq_grad(xp, z, g, h, dg, dh, qinv, rinv);
4230                %
4231                check  = (gradp - gradm) / ( 2 * step );
4232                for k1 = 1 : N
4233                        for i1 = 1 : n
4234                                value = H(i + (k-1)*n, i1 + (k1-1)*n);
4235                                diff  = check(i1, k1) - value;
4236                                ok     = ok &amp; ( abs(diff) &lt; 1e-10 );
4237                        end
4238                end
4239        end
4240end
4241return
4242end
4243</pre></font></code>
4244 
4245
4246<hr>Input File: ../test/sumsq_hes_ok.m
4247
4248<hr>
4249 
4250
4251
4252<center><b><big><big><a name="5.6" id="5.6">5.6: Symmetric Block Tridiagonal Algorithm</a>
4253</big></big></b></center>
4254<br>
4255<b><big><a name="5.6.a" id="5.6.a">5.6.a: Syntax</a></big></b>
4256
4257<br>
4258
4259<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>
4260
4261
4262<br>
4263<br>
4264<b><big><a name="5.6.b" id="5.6.b">5.6.b: Purpose</a></big></b>
4265<br>
4266This routine solves the following linear system of equations for
4267<code>
4268<span style='white-space: nowrap'>&nbsp;e</span></code>
4269:
4270<code>
4271<span style='white-space: nowrap'>&nbsp;\[<br>
4272&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;*&nbsp;e&nbsp;=&nbsp;r<br>
4273\]&nbsp;</span></code>
4274
4275where the symmetric block tridiagonal matrix <code>
4276<span style='white-space: nowrap'>&nbsp;A</span></code>
4277 is defined by
4278<code>
4279<span style='white-space: nowrap'>&nbsp;\[<br>
4280A&nbsp;=<br>
4281\left(&nbsp;\begin{array}{ccccc}<br>
4282b_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>
4283c_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>
4284\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>
42850&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>
4286\end{array}&nbsp;\right)<br>
4287\]&nbsp;</span></code>
4288
4289
4290<br>
4291<br>
4292<b><big><a name="5.6.c" id="5.6.c">5.6.c: b</a></big></b>
4293<br>
4294The argument
4295<code><i><font color="black"><span style='white-space: nowrap'>b</span></font></i></code>
4296 is a three dimensional array,
4297for <code>
4298<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4299
4300<code>
4301<span style='white-space: nowrap'>&nbsp;\[<br>
4302&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b_k&nbsp;=&nbsp;b(:,:,k)<br>
4303\]</span></code>
4304
4305and
4306<code><i><font color="black"><span style='white-space: nowrap'>b</span></font></i></code>
4307 has size <code>
4308<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4309.
4310
4311<br>
4312<br>
4313<b><big><a name="5.6.d" id="5.6.d">5.6.d: c</a></big></b>
4314<br>
4315The argument
4316<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i></code>
4317 is a three dimensional array,
4318for <code>
4319<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;2&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4320
4321<code>
4322<span style='white-space: nowrap'>&nbsp;\[<br>
4323&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c_k&nbsp;=&nbsp;c(:,:,k)<br>
4324\]</span></code>
4325
4326and
4327<code><i><font color="black"><span style='white-space: nowrap'>c</span></font></i></code>
4328 has size <code>
4329<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4330.
4331
4332<br>
4333<br>
4334<b><big><a name="5.6.e" id="5.6.e">5.6.e: r</a></big></b>
4335<br>
4336The argument
4337<code><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
4338 is an <code>
4339<span style='white-space: nowrap'>&nbsp;(n&nbsp;*&nbsp;N)&nbsp;\times&nbsp;m</span></code>
4340 matrix.
4341
4342<br>
4343<br>
4344<b><big><a name="5.6.f" id="5.6.f">5.6.f: e</a></big></b>
4345<br>
4346The result
4347<code><i><font color="black"><span style='white-space: nowrap'>e</span></font></i></code>
4348 is an <code>
4349<span style='white-space: nowrap'>&nbsp;(n&nbsp;*&nbsp;N)&nbsp;\times&nbsp;m</span></code>
4350 matrix.
4351
4352<br>
4353<br>
4354<b><big><a name="5.6.g" id="5.6.g">5.6.g: lambda</a></big></b>
4355<br>
4356The result
4357<code><i><font color="black"><span style='white-space: nowrap'>lambda</span></font></i></code>
4358 is a scalar equal to the
4359logarithm of the determinant of <code>
4360<span style='white-space: nowrap'>&nbsp;A</span></code>
4361.
4362
4363<br>
4364<br>
4365<b><big><a name="5.6.h" id="5.6.h">5.6.h: Reference</a></big></b>
4366
4367<i><br>
4368The marginal likelihood for parameters in a discrete
4369Gauss Markov process</i>,
4370Bradley M. Bell,
4371IEEE Transactions on Signal Processing,
4372Vol. 48,
4373No. 3,
4374March 2000.
4375
4376<br>
4377<br>
4378<b><big><a name="5.6.i" id="5.6.i">5.6.i: Lemma</a></big></b>
4379<br>
4380The following result is proven as Lemma 6 of the reference above:
4381Suppose that for <code>
4382<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4383
4384<code>
4385<span style='white-space: nowrap'>&nbsp;\[<br>
4386\begin{array}{rcl}<br>
4387&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>
4388&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c_k&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;q_{k-1}^{-1}&nbsp;*&nbsp;a_k^\T<br>
4389\end{array}<br>
4390\]&nbsp;</span></code>
4391
4392where <code>
4393<span style='white-space: nowrap'>&nbsp;u_k</span></code>
4394 is symmetric positive semi-definite and
4395<code>
4396<span style='white-space: nowrap'>&nbsp;q_k</span></code>
4397 is symmetric positive definite.
4398It follows that the algorithm used by <code><font color="blue">ckbs_tridiag_solve</font></code>
4399is well conditioned and will not try to invert singular matrices.
4400
4401
4402
4403<br>
4404<br>
4405<b><big><a name="5.6.j" id="5.6.j">5.6.j: Example</a></big></b>
4406<br>
4407The file <a href="#5.6.1">5.6.1: <span style='white-space: nowrap'>tridiag_solve_ok.m</span></a>
4408 contains an example and test of
4409<code><font color="blue">ckbs_tridiag_solve</font></code>.
4410It returns true if <code><font color="blue">ckbs_tridiag_solve</font></code> passes the test
4411and false otherwise.
4412
4413
4414<hr>Input File: ../src/ckbs_tridiag_solve.m
4415
4416<hr>
4417 
4418
4419
4420<center><b><big><big><a name="5.6.1" id="5.6.1">5.6.1: ckbs_tridiag_solve Example and Test</a>
4421</big></big></b></center>
4422<br>
4423<b><big><a name="5.6.1.a" id="5.6.1.a">5.6.1.a: Source Code</a></big></b>
4424
4425 <code><font color='blue'><pre style='display:inline'> 
4426function [ok] = tridiag_solve_ok()
4427ok = true;
4428m  = 2;
4429n  = 3;
4430N  = 4;
4431% case where uk = 0, qk = I, and ak is random
4432rand('seed', 123);
4433a = rand(n, n, N);
4434r = rand(n * N, m);
4435c = zeros(n, n, N);
4436for k = 1 : N
4437        ak         = a(:, :, k);
4438        b(:, :, k) = 2 * eye(n) + ak * ak';
4439        c(:, :, k) = ak';
4440end 
4441% ----------------------------------------
4442[e, lambda] = ckbs_tridiag_solve(b, c, r);
4443% ----------------------------------------
4444%
4445% check equation corresponding to first row
4446blk_n = 1 : n;
4447lhs   = b(:, :, 1) * e(blk_n, :) + c(:, :, 2)' * e(blk_n + n, :);
4448ok    = ok &amp; ( max( max( abs( lhs - r(blk_n, :) ) ) ) &lt; 1e-10 );
4449%
4450% check equation corresponding to last row
4451blk_n = (N-1) * n + (1 : n);
4452lhs   = c(:, :, N) * e(blk_n - n, :) + b(:, :, N) * e(blk_n, :);
4453ok    = ok &amp; ( max( max( abs( lhs - r(blk_n, :) ) ) ) &lt; 1e-10 );
4454%
4455% check other rows
4456blk_n = 1 : n;
4457for k = 2 : N-1
4458        blk_n = blk_n + n;
4459        lhs   = c(:, :, k)    * e(blk_n - n, :)  ...
4460              + b(:, :, k)    * e(blk_n, :)    ...
4461              + c(:, :, k+1)' * e(blk_n + n, :);
4462        ok    = ok &amp; ( max( max( abs( lhs - r(blk_n, :) ) ) ) &lt; 1e-10 );
4463end
4464return
4465end
4466</pre></font></code>
4467 
4468
4469<hr>Input File: ../test/tridiag_solve_ok.m
4470
4471<hr>
4472 
4473
4474
4475<center><b><big><big><a name="5.7" id="5.7">5.7: Affine Constrained Kalman Bucy Smoother Newton Step</a>
4476</big></big></b></center>
4477<br>
4478<b><big><a name="5.7.a" id="5.7.a">5.7.a: Syntax</a></big></b>
4479
4480<br>
4481<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>
4482
4483<br>
4484<br>
4485<b><big><a name="5.7.b" id="5.7.b">5.7.b: Purpose</a></big></b>
4486<br>
4487This routine computes one step of Newton's method for solving
4488the non-linear Kuhn-Tucker conditions for
4489the <code>
4490<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4491-relaxed affine constrained Kalman-Bucy smoother problem.
4492
4493
4494<br>
4495<br>
4496<b><big><a name="5.7.c" id="5.7.c">5.7.c: Problem</a></big></b>
4497<br>
4498Given
4499<code>
4500<span style='white-space: nowrap'>&nbsp;\mu&nbsp;\in&nbsp;\R_+</span></code>
4501,
4502<code>
4503<span style='white-space: nowrap'>&nbsp;H&nbsp;\in&nbsp;\R^{p&nbsp;\times&nbsp;p}</span></code>
4504,
4505<code>
4506<span style='white-space: nowrap'>&nbsp;d&nbsp;\in&nbsp;\R^p</span></code>
4507,
4508<code>
4509<span style='white-space: nowrap'>&nbsp;b&nbsp;\in&nbsp;\R^r</span></code>
4510, and
4511<code>
4512<span style='white-space: nowrap'>&nbsp;B&nbsp;\in&nbsp;\R^{r&nbsp;\times&nbsp;p}</span></code>
4513,
4514the <code>
4515<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4516-relaxed affine constrained Kalman-Bucy smoother problem is:
4517<code>
4518<span style='white-space: nowrap'>&nbsp;\[<br>
4519\begin{array}{rl}<br>
4520{\rm&nbsp;minimize}&nbsp;&amp;&nbsp;\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
4521-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
4522\;&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>
4523\\<br>
4524{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;&amp;&nbsp;s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;=&nbsp;0&nbsp;<br>
4525\end{array}<br>
4526\]&nbsp;</span></code>
4527
4528In addition, <code>
4529<span style='white-space: nowrap'>&nbsp;H</span></code>
4530 is symmetric block tri-diagonal with each block of
4531size <code>
4532<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
4533 and
4534<code>
4535<span style='white-space: nowrap'>&nbsp;B</span></code>
4536 is block diagonal with each block of size <code>
4537<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n</span></code>
4538
4539(there is an integer <code>
4540<span style='white-space: nowrap'>&nbsp;N</span></code>
4541 such that
4542<code>
4543<span style='white-space: nowrap'>&nbsp;p&nbsp;=&nbsp;n&nbsp;*&nbsp;N</span></code>
4544 and <code>
4545<span style='white-space: nowrap'>&nbsp;r&nbsp;=&nbsp;m&nbsp;*&nbsp;N</span></code>
4546).
4547
4548
4549<br>
4550<br>
4551<b><a name="5.7.c.a" id="5.7.c.a">5.7.c.a: Lagrangian</a></b>
4552<br>
4553We use <code>
4554<span style='white-space: nowrap'>&nbsp;u&nbsp;\in&nbsp;\R^r</span></code>
4555
4556to denote the Lagrange multipliers corresponding to the constraint equation.
4557The corresponding Lagrangian is
4558<code>
4559<span style='white-space: nowrap'>&nbsp;\[<br>
4560L(y,&nbsp;s,&nbsp;u)&nbsp;&nbsp;=<br>
4561\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
4562-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
4563+&nbsp;u^\T&nbsp;(s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y)<br>
4564\]&nbsp;</span></code>
4565
4566The partial gradients of the Lagrangian are given by
4567<code>
4568<span style='white-space: nowrap'>&nbsp;\[<br>
4569\begin{array}{rcl}<br>
4570\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>
4571\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>
4572\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>
4573\end{array}<br>
4574\]&nbsp;</span></code>
4575
4576where <code>
4577<span style='white-space: nowrap'>&nbsp;\mu&nbsp;/&nbsp;s&nbsp;</span></code>
4578 is the component by component division of
4579<code>
4580<span style='white-space: nowrap'>&nbsp;\mu&nbsp;</span></code>
4581 by the components of the <code>
4582<span style='white-space: nowrap'>&nbsp;s</span></code>
4583.
4584Note, from the second equation, that we only need consider
4585<code>
4586<span style='white-space: nowrap'>&nbsp;u&nbsp;\geq&nbsp;0</span></code>
4587 because <code>
4588<span style='white-space: nowrap'>&nbsp;s&nbsp;\geq&nbsp;0</span></code>
4589.
4590
4591<br>
4592<br>
4593<b><a name="5.7.c.b" id="5.7.c.b">5.7.c.b: Kuhn-Tucker Conditions</a></b>
4594<br>
4595We use <code>
4596<span style='white-space: nowrap'>&nbsp;D(s)</span></code>
4597 
4598to denote the diagonal matrix with <code>
4599<span style='white-space: nowrap'>&nbsp;s</span></code>
4600
4601along its diagonal and <code>
4602<span style='white-space: nowrap'>&nbsp;1_r</span></code>
4603 
4604to denote the vector, of length <code>
4605<span style='white-space: nowrap'>&nbsp;r</span></code>
4606 with all its components
4607equal to one.
4608We define
4609<code>
4610<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>
4611
4612by
4613<code>
4614<span style='white-space: nowrap'>&nbsp;\[<br>
4615F(s,&nbsp;y,&nbsp;u)<br>
4616=<br>
4617\left(<br>
4618\begin{array}{c}<br>
4619s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4620H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
4621D(s)&nbsp;D(u)&nbsp;1_r&nbsp;-&nbsp;\mu&nbsp;1_r<br>
4622\end{array}<br>
4623\right)<br>
4624\]&nbsp;</span></code>
4625
4626The Kuhn-Tucker conditions for a solution of the
4627<code>
4628<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4629-relaxed constrained affine Kalman-Bucy smoother problem is
4630<code>
4631<span style='white-space: nowrap'>&nbsp;F(s,&nbsp;y,&nbsp;u)&nbsp;=&nbsp;0&nbsp;</span></code>
4632.
4633
4634<br>
4635<br>
4636<b><a name="5.7.c.c" id="5.7.c.c">5.7.c.c: Newton Step</a></b>
4637<br>
4638Given a value for <code>
4639<span style='white-space: nowrap'>&nbsp;(s,&nbsp;y,&nbsp;u)</span></code>
4640, the Newton step
4641<code>
4642<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>
4643 solves the problem:
4644<code>
4645<span style='white-space: nowrap'>&nbsp;\[<br>
4646F^{(1)}&nbsp;(s,&nbsp;y,&nbsp;u)&nbsp;<br>
4647\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>
4648=<br>
4649-&nbsp;F(s,&nbsp;y,&nbsp;u)<br>
4650\]&nbsp;</span></code>
4651
4652
4653<br>
4654<br>
4655<b><big><a name="5.7.d" id="5.7.d">5.7.d: mu</a></big></b>
4656<br>
4657The argument <i>mu</i> is a positive scalar specifying the
4658relaxation parameter <code>
4659<span style='white-space: nowrap'>&nbsp;\mu</span></code>
4660.
4661
4662<br>
4663<br>
4664<b><big><a name="5.7.e" id="5.7.e">5.7.e: s</a></big></b>
4665<br>
4666The argument <i>s</i> is a column vector of length <code>
4667<span style='white-space: nowrap'>&nbsp;r</span></code>
4668.
4669All the elements of <i>s</i> are greater than zero.
4670
4671<br>
4672<br>
4673<b><big><a name="5.7.f" id="5.7.f">5.7.f: y</a></big></b>
4674<br>
4675The argument <i>y</i> is a column vector of length <code>
4676<span style='white-space: nowrap'>&nbsp;p</span></code>
4677
4678
4679<br>
4680<br>
4681<b><big><a name="5.7.g" id="5.7.g">5.7.g: u</a></big></b>
4682<br>
4683The argument <i>u</i> is a column vector of length <code>
4684<span style='white-space: nowrap'>&nbsp;r</span></code>
4685.
4686All the elements of <i>s</i> are greater than zero.
4687
4688<br>
4689<br>
4690<b><big><a name="5.7.h" id="5.7.h">5.7.h: b</a></big></b>
4691<br>
4692The argument <i>b</i> is a column vector of length <code>
4693<span style='white-space: nowrap'>&nbsp;r</span></code>
4694.
4695
4696<br>
4697<br>
4698<b><big><a name="5.7.i" id="5.7.i">5.7.i: d</a></big></b>
4699<br>
4700The argument <i>d</i> is a column vector of length <code>
4701<span style='white-space: nowrap'>&nbsp;p</span></code>
4702
4703
4704<br>
4705<br>
4706<b><big><a name="5.7.j" id="5.7.j">5.7.j: Bdia</a></big></b>
4707<br>
4708The argument <i>Bdia</i> is an <code>
4709<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4710 array.
4711For <code>
4712<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4713 we define <code>
4714<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
4715 by
4716<code>
4717<span style='white-space: nowrap'>&nbsp;\[<br>
4718&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
4719\]&nbsp;</span></code>
4720
4721
4722<br>
4723<br>
4724<b><big><a name="5.7.k" id="5.7.k">5.7.k: B</a></big></b>
4725<br>
4726The matrix <code>
4727<span style='white-space: nowrap'>&nbsp;B</span></code>
4728 is defined by
4729<code>
4730<span style='white-space: nowrap'>&nbsp;\[<br>
4731B&nbsp;<br>
4732=<br>
4733\left(&nbsp;\begin{array}{cccc}<br>
4734B_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>
47350&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>
47360&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>
4737&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>
4738\end{array}&nbsp;\right)<br>
4739\]&nbsp;</span></code>
4740
4741
4742<br>
4743<br>
4744<b><big><a name="5.7.l" id="5.7.l">5.7.l: Hdia</a></big></b>
4745<br>
4746The argument <i>Hdia</i> is an <code>
4747<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4748 array.
4749For <code>
4750<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4751 we define <code>
4752<span style='white-space: nowrap'>&nbsp;H_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
4753 by
4754<code>
4755<span style='white-space: nowrap'>&nbsp;\[<br>
4756&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;Hdia(:,&nbsp;:,&nbsp;k)<br>
4757\]&nbsp;</span></code>
4758
4759
4760
4761<br>
4762<br>
4763<b><big><a name="5.7.m" id="5.7.m">5.7.m: Hlow</a></big></b>
4764<br>
4765The argument <i>Hlow</i> is an <code>
4766<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
4767 array.
4768For <code>
4769<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
4770 we define <code>
4771<span style='white-space: nowrap'>&nbsp;L_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
4772 by
4773<code>
4774<span style='white-space: nowrap'>&nbsp;\[<br>
4775&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L_k&nbsp;=&nbsp;Hlow(:,&nbsp;:,&nbsp;k)<br>
4776\]&nbsp;</span></code>
4777
4778
4779<br>
4780<br>
4781<b><big><a name="5.7.n" id="5.7.n">5.7.n: H</a></big></b>
4782<br>
4783The matrix <code>
4784<span style='white-space: nowrap'>&nbsp;H</span></code>
4785 is defined by
4786<code>
4787<span style='white-space: nowrap'>&nbsp;\[<br>
4788H&nbsp;<br>
4789=<br>
4790\left(&nbsp;\begin{array}{cccc}<br>
4791H_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>
4792L_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>
47930&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4794&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>
4795\end{array}&nbsp;\right)<br>
4796\]&nbsp;</span></code>
4797
4798
4799<br>
4800<br>
4801<b><big><a name="5.7.o" id="5.7.o">5.7.o: ds</a></big></b>
4802<br>
4803The result <i>ds</i> is a column vector of length <code>
4804<span style='white-space: nowrap'>&nbsp;r</span></code>
4805 
4806equal to the <code>
4807<span style='white-space: nowrap'>&nbsp;\Delta&nbsp;s</span></code>
4808 components of the Newton step.
4809
4810<br>
4811<br>
4812<b><big><a name="5.7.p" id="5.7.p">5.7.p: dy</a></big></b>
4813<br>
4814The result <i>dy</i> is a column vector of length <code>
4815<span style='white-space: nowrap'>&nbsp;p</span></code>
4816 
4817equal to the <code>
4818<span style='white-space: nowrap'>&nbsp;\Delta&nbsp;y</span></code>
4819 components of the Newton step.
4820
4821<br>
4822<br>
4823<b><big><a name="5.7.q" id="5.7.q">5.7.q: du</a></big></b>
4824<br>
4825The result <i>du</i> is a column vector of length <code>
4826<span style='white-space: nowrap'>&nbsp;r</span></code>
4827 
4828equal to the <code>
4829<span style='white-space: nowrap'>&nbsp;\Delta&nbsp;u</span></code>
4830 components of the Newton step.
4831
4832
4833
4834<br>
4835<br>
4836<b><big><a name="5.7.r" id="5.7.r">5.7.r: Example</a></big></b>
4837<br>
4838The file <a href="#5.7.1">5.7.1: <span style='white-space: nowrap'>newton_step_ok.m</span></a>
4839 contains an example and test of
4840<code><font color="blue">ckbs_newton_step</font></code>.
4841It returns true if <code><font color="blue">ckbs_newton_step</font></code> passes the test
4842and false otherwise.
4843
4844<br>
4845<br>
4846<b><big><a name="5.7.s" id="5.7.s">5.7.s: Method</a></big></b>
4847<br>
4848The derivative of <code>
4849<span style='white-space: nowrap'>&nbsp;F</span></code>
4850 is given by
4851<code>
4852<span style='white-space: nowrap'>&nbsp;\[<br>
4853F^{(1)}&nbsp;(s,&nbsp;y,&nbsp;u)&nbsp;=<br>
4854\left(<br>
4855\begin{array}{ccccc}<br>
4856D(&nbsp;1_r&nbsp;)&nbsp;&amp;&nbsp;B&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
48570&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H&nbsp;&nbsp;&nbsp;&amp;&nbsp;B^\T&nbsp;&nbsp;\\<br>
4858D(&nbsp;u&nbsp;)&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;D(s)<br>
4859\end{array}<br>
4860\right)<br>
4861\]&nbsp;</span></code>
4862
4863It follows that
4864<code>
4865<span style='white-space: nowrap'>&nbsp;\[<br>
4866\left(&nbsp;\begin{array}{ccc}<br>
4867D(&nbsp;1_r&nbsp;)&nbsp;&amp;&nbsp;B&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
48680&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H&nbsp;&nbsp;&nbsp;&amp;&nbsp;B^\T&nbsp;&nbsp;\\<br>
4869D(&nbsp;u&nbsp;)&nbsp;&nbsp;&nbsp;&amp;&nbsp;0&nbsp;&nbsp;&nbsp;&amp;&nbsp;D(s)<br>
4870\end{array}&nbsp;\right)<br>
4871\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>
4872=<br>
4873-<br>
4874\left(&nbsp;\begin{array}{c}<br>
4875s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
4876H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
4877D(s)&nbsp;D(u)&nbsp;1_r&nbsp;-&nbsp;\mu&nbsp;1_r<br>
4878\end{array}&nbsp;\right)<br>
4879\]&nbsp;</span></code>
4880
4881Replacing the bottom row by the bottom row minus
4882<code>
4883<span style='white-space: nowrap'>&nbsp;D(u)</span></code>
4884 times the top row,
4885we obtain the reduced set of equations
4886<code>
4887<span style='white-space: nowrap'>&nbsp;\[<br>
4888\left(&nbsp;\begin{array}{cc}<br>
4889&nbsp;H&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;B^\T&nbsp;&nbsp;\\<br>
4890-D(u)&nbsp;B&nbsp;&amp;&nbsp;D(s)&nbsp;<br>
4891\end{array}&nbsp;\right)&nbsp;<br>
4892\left(&nbsp;\begin{array}{c}&nbsp;\Delta&nbsp;y&nbsp;\\&nbsp;\Delta&nbsp;u&nbsp;\end{array}&nbsp;\right)<br>
4893=<br>
4894\left(&nbsp;\begin{array}{c}<br>
4895-&nbsp;H&nbsp;y&nbsp;-&nbsp;B^\T&nbsp;u&nbsp;-&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
4896\mu&nbsp;1_r&nbsp;+&nbsp;D(u)&nbsp;(&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;)<br>
4897\end{array}&nbsp;\right)<br>
4898\]&nbsp;</span></code>
4899
4900Replacing the top row by <code>
4901<span style='white-space: nowrap'>&nbsp;H^{-1}</span></code>
4902 times the top row we obtain
4903<code>
4904<span style='white-space: nowrap'>&nbsp;\[<br>
4905\left(&nbsp;\begin{array}{cc}<br>
4906&nbsp;D(&nbsp;1_p&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;H^{-1}&nbsp;B^\T&nbsp;&nbsp;\\<br>
4907-D(u)&nbsp;B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;D(s)&nbsp;<br>
4908\end{array}&nbsp;\right)&nbsp;<br>
4909\left(&nbsp;\begin{array}{c}&nbsp;\Delta&nbsp;y&nbsp;\\&nbsp;\Delta&nbsp;u&nbsp;\end{array}&nbsp;\right)<br>
4910=<br>
4911\left(&nbsp;\begin{array}{c}<br>
4912-&nbsp;y&nbsp;-&nbsp;H^{-1}(&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;)&nbsp;&nbsp;&nbsp;\\<br>
4913\mu&nbsp;1_r&nbsp;+&nbsp;D(u)&nbsp;(&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;)<br>
4914\end{array}&nbsp;\right)<br>
4915\]&nbsp;</span></code>
4916
4917Replacing the bottom row by
4918the <code>
4919<span style='white-space: nowrap'>&nbsp;D(u)^{-1}</span></code>
4920 times the bottom row
4921plus <code>
4922<span style='white-space: nowrap'>&nbsp;B</span></code>
4923 times the top row,
4924we obtain the reduced equation
4925<code>
4926<span style='white-space: nowrap'>&nbsp;\[<br>
4927\begin{array}{rcl}<br>
4928[&nbsp;B&nbsp;H^{-1}&nbsp;B^\T&nbsp;+&nbsp;D(s&nbsp;/&nbsp;u)&nbsp;]&nbsp;\Delta&nbsp;u&nbsp;<br>
4929&amp;&nbsp;=&nbsp;&amp;<br>
4930\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>
4931\end{array}<br>
4932\]&nbsp;</span></code>
4933
4934Thus we obtain the following solution for the Newton step:
4935<code>
4936<span style='white-space: nowrap'>&nbsp;\[<br>
4937\begin{array}{rcl}<br>
4938\Delta&nbsp;u&nbsp;&amp;&nbsp;=&nbsp;&amp;&nbsp;<br>
4939&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[&nbsp;B&nbsp;H^{-1}&nbsp;B^\T&nbsp;+&nbsp;D(s&nbsp;/&nbsp;u)&nbsp;]^{-1}&nbsp;<br>
4940&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>
4941\\<br>
4942\Delta&nbsp;y&nbsp;&amp;&nbsp;=&nbsp;&amp;<br>
4943-&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>
4944\\<br>
4945\Delta&nbsp;s&nbsp;&amp;&nbsp;=&nbsp;&amp;<br>
4946-&nbsp;s&nbsp;-&nbsp;b&nbsp;-&nbsp;B&nbsp;(&nbsp;y&nbsp;+&nbsp;\Delta&nbsp;y&nbsp;)<br>
4947\end{array}<br>
4948\]&nbsp;</span></code>
4949
4950It follows from the matrix inversion lemma that
4951<code>
4952<span style='white-space: nowrap'>&nbsp;\[<br>
4953[&nbsp;B&nbsp;H^{-1}&nbsp;B^\T&nbsp;+&nbsp;D(s&nbsp;/&nbsp;u)&nbsp;]^{-1}&nbsp;<br>
4954=&nbsp;<br>
4955D(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>
4956\]&nbsp;</span></code>
4957
4958
4959
4960<hr>Input File: ../src/ckbs_newton_step.m
4961
4962<hr>
4963 
4964
4965
4966<center><b><big><big><a name="5.7.1" id="5.7.1">5.7.1: ckbs_newton_step Example and Test</a>
4967</big></big></b></center>
4968<br>
4969<b><big><a name="5.7.1.a" id="5.7.1.a">5.7.1.a: Source Code</a></big></b>
4970
4971 <code><font color='blue'><pre style='display:inline'> 
4972function [ok] = newton_step_ok()
4973ok = true;
4974% --------------------------------------------------------
4975% You can change these parameters
4976m    = 2;   % number of measurements per time point
4977n    = 3;   % number of state vector components per time point
4978N    = 4;   % number of time points
4979% ---------------------------------------------------------
4980%  Define the problem
4981rand('seed', 123);
4982mu    = .5;
4983r     = m * N;
4984p     = n * N;
4985s     = rand(r, 1) + 1;
4986y     = rand(p, 1);
4987u     = rand(r, 1) + 1;
4988b     = rand(r, 1);
4989d     = rand(p, 1);
4990H     = zeros(p, p);
4991B     = zeros(r, r);
4992Hdia  = zeros(n, n, N);
4993Hlow  = zeros(n, n, N);
4994Bdia  = zeros(m, n, N);
4995blk_m = m * N + (1 : m);
4996blk_n = n * N + (1 : n);
4997for k = N : -1 : 1
4998        blk_n = blk_n - n;
4999        blk_m = blk_m - m;
5000        %
5001        Bdia(:,:, k)    = rand(m, n);
5002        tmp             = rand(n, n);
5003        Hlow(:,:, k)    = tmp;
5004        Hdia(:,:, k)   = (tmp * tmp') + 4 * eye(n);
5005        %
5006        B(blk_m, blk_n) = Bdia(:,:, k);
5007        H(blk_n, blk_n) = Hdia(:,:, k);
5008        if k &gt; 1
5009                H(blk_n, blk_n - n) = Hlow(:,:, k);
5010        end
5011        if k &lt; N
5012                H(blk_n, blk_n + n) = Hlow(:,:, k + 1)';
5013        end
5014end
5015% -------------------------------------------------------------------
5016[ds, dy, du] = ckbs_newton_step(mu, s, y, u, b, d, Bdia, Hdia, Hlow);
5017% -------------------------------------------------------------------
5018F      = [ ...
5019        s + b + B * y
5020        H * y + B' * u + d
5021        s .* u - mu ...
5022];
5023dF     = [ ...
5024        eye(r)      , B           , zeros(r, r)
5025        zeros(p, r) , H           , B'
5026        diag(u)     , zeros(r, p) , diag(s) ...
5027];
5028delta        = [ ds ; dy ; du ];
5029ok           = ok &amp; ( max( abs( F + dF * delta ) ) &lt;= 1e-10 );
5030return
5031end
5032</pre></font></code>
5033 
5034
5035<hr>Input File: ../test/newton_step_ok.m
5036
5037<hr>
5038 
5039
5040
5041<center><b><big><big><a name="5.8" id="5.8">5.8: Compute Residual in Kuhn-Tucker Conditions</a>
5042</big></big></b></center>
5043<br>
5044<b><big><a name="5.8.a" id="5.8.a">5.8.a: Syntax</a></big></b>
5045
5046<br>
5047<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>
5048
5049<br>
5050<br>
5051<b><big><a name="5.8.b" id="5.8.b">5.8.b: Purpose</a></big></b>
5052<br>
5053This routine computes the residual in the Kuhn-Tucker conditions for
5054the <code>
5055<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5056-relaxed affine constrained Kalman-Bucy smoother problem.
5057
5058<br>
5059<br>
5060<b><big><a name="5.8.c" id="5.8.c">5.8.c: Problem</a></big></b>
5061<br>
5062Given
5063<code>
5064<span style='white-space: nowrap'>&nbsp;\mu&nbsp;\in&nbsp;\R_+</span></code>
5065,
5066<code>
5067<span style='white-space: nowrap'>&nbsp;H&nbsp;\in&nbsp;\R^{p&nbsp;\times&nbsp;p}</span></code>
5068,
5069<code>
5070<span style='white-space: nowrap'>&nbsp;d&nbsp;\in&nbsp;\R^p</span></code>
5071,
5072<code>
5073<span style='white-space: nowrap'>&nbsp;b&nbsp;\in&nbsp;\R^r</span></code>
5074, and
5075<code>
5076<span style='white-space: nowrap'>&nbsp;B&nbsp;\in&nbsp;\R^{r&nbsp;\times&nbsp;p}</span></code>
5077,
5078the <code>
5079<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5080-relaxed affine constrained Kalman-Bucy smoother problem is:
5081<code>
5082<span style='white-space: nowrap'>&nbsp;\[<br>
5083\begin{array}{rl}<br>
5084{\rm&nbsp;minimize}&nbsp;&amp;&nbsp;\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
5085-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
5086\;&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>
5087\\<br>
5088{\rm&nbsp;subject&nbsp;\;&nbsp;to}&nbsp;&amp;&nbsp;s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;=&nbsp;0&nbsp;<br>
5089\end{array}<br>
5090\]&nbsp;</span></code>
5091
5092In addition, <code>
5093<span style='white-space: nowrap'>&nbsp;H</span></code>
5094 is symmetric block tri-diagonal with each block of
5095size <code>
5096<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n</span></code>
5097 and
5098<code>
5099<span style='white-space: nowrap'>&nbsp;B</span></code>
5100 is block diagonal with each block of size <code>
5101<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n</span></code>
5102
5103(there is an integer <code>
5104<span style='white-space: nowrap'>&nbsp;N</span></code>
5105 such that
5106<code>
5107<span style='white-space: nowrap'>&nbsp;p&nbsp;=&nbsp;n&nbsp;*&nbsp;N</span></code>
5108 and <code>
5109<span style='white-space: nowrap'>&nbsp;r&nbsp;=&nbsp;m&nbsp;*&nbsp;N</span></code>
5110).
5111
5112
5113<br>
5114<br>
5115<b><big><a name="5.8.d" id="5.8.d">5.8.d: Lagrangian</a></big></b>
5116<br>
5117We use <code>
5118<span style='white-space: nowrap'>&nbsp;u&nbsp;\in&nbsp;\R^r</span></code>
5119
5120to denote the Lagrange multipliers corresponding to the constraint equation.
5121The corresponding Lagrangian is
5122<code>
5123<span style='white-space: nowrap'>&nbsp;\[<br>
5124L(y,&nbsp;s,&nbsp;u)&nbsp;&nbsp;=<br>
5125\frac{1}{2}&nbsp;y^\T&nbsp;H&nbsp;y&nbsp;+&nbsp;d^\T&nbsp;y<br>
5126-&nbsp;\mu&nbsp;\sum_{i=1}^r&nbsp;\log(s_i)<br>
5127+&nbsp;u^\T&nbsp;(s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y)<br>
5128\]&nbsp;</span></code>
5129
5130The partial gradients of the Lagrangian are given by
5131<code>
5132<span style='white-space: nowrap'>&nbsp;\[<br>
5133\begin{array}{rcl}<br>
5134\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>
5135\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>
5136\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>
5137\end{array}<br>
5138\]&nbsp;</span></code>
5139
5140where <code>
5141<span style='white-space: nowrap'>&nbsp;\mu&nbsp;/&nbsp;s&nbsp;</span></code>
5142 is the component by component division of
5143<code>
5144<span style='white-space: nowrap'>&nbsp;\mu&nbsp;</span></code>
5145 by the components of the <code>
5146<span style='white-space: nowrap'>&nbsp;s</span></code>
5147.
5148Note, from the second equation, that we only need consider
5149<code>
5150<span style='white-space: nowrap'>&nbsp;u&nbsp;\geq&nbsp;0</span></code>
5151 because <code>
5152<span style='white-space: nowrap'>&nbsp;s&nbsp;\geq&nbsp;0</span></code>
5153.
5154
5155<br>
5156<br>
5157<b><big><a name="5.8.e" id="5.8.e">5.8.e: Kuhn-Tucker Residual</a></big></b>
5158<br>
5159We use <code>
5160<span style='white-space: nowrap'>&nbsp;D(s)</span></code>
5161 
5162to denote the diagonal matrix with <code>
5163<span style='white-space: nowrap'>&nbsp;s</span></code>
5164
5165along its diagonal and <code>
5166<span style='white-space: nowrap'>&nbsp;1_r</span></code>
5167 
5168to denote the vector, of length <code>
5169<span style='white-space: nowrap'>&nbsp;r</span></code>
5170 with all its components
5171equal to one.
5172The Kuhn-Tucker Residual function
5173<code>
5174<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>
5175
5176is defined by
5177<code>
5178<span style='white-space: nowrap'>&nbsp;\[<br>
5179F(s,&nbsp;y,&nbsp;u)<br>
5180=<br>
5181\left(<br>
5182\begin{array}{c}<br>
5183s&nbsp;+&nbsp;b&nbsp;+&nbsp;B&nbsp;y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
5184H&nbsp;y&nbsp;+&nbsp;B^\T&nbsp;u&nbsp;+&nbsp;d&nbsp;&nbsp;&nbsp;\\<br>
5185D(s)&nbsp;D(u)&nbsp;1_r&nbsp;-&nbsp;\mu&nbsp;1_r<br>
5186\end{array}<br>
5187\right)<br>
5188\]&nbsp;</span></code>
5189
5190The Kuhn-Tucker conditions for a solution of the
5191<code>
5192<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5193-relaxed constrained affine Kalman-Bucy smoother problem is
5194<code>
5195<span style='white-space: nowrap'>&nbsp;F(s,&nbsp;y,&nbsp;u)&nbsp;=&nbsp;0&nbsp;</span></code>
5196.
5197
5198<br>
5199<br>
5200<b><big><a name="5.8.f" id="5.8.f">5.8.f: mu</a></big></b>
5201<br>
5202The argument <i>mu</i> is a positive scalar specifying the
5203relaxation parameter <code>
5204<span style='white-space: nowrap'>&nbsp;\mu</span></code>
5205.
5206
5207<br>
5208<br>
5209<b><big><a name="5.8.g" id="5.8.g">5.8.g: s</a></big></b>
5210<br>
5211The argument <i>s</i> is a column vector of length <code>
5212<span style='white-space: nowrap'>&nbsp;r</span></code>
5213.
5214All the elements of <i>s</i> are greater than zero.
5215
5216<br>
5217<br>
5218<b><big><a name="5.8.h" id="5.8.h">5.8.h: y</a></big></b>
5219<br>
5220The argument <i>y</i> is a column vector of length <code>
5221<span style='white-space: nowrap'>&nbsp;p</span></code>
5222
5223
5224<br>
5225<br>
5226<b><big><a name="5.8.i" id="5.8.i">5.8.i: u</a></big></b>
5227<br>
5228The argument <i>u</i> is a column vector of length <code>
5229<span style='white-space: nowrap'>&nbsp;r</span></code>
5230.
5231All the elements of <i>s</i> are greater than zero.
5232
5233<br>
5234<br>
5235<b><big><a name="5.8.j" id="5.8.j">5.8.j: b</a></big></b>
5236<br>
5237The argument <i>b</i> is a column vector of length <code>
5238<span style='white-space: nowrap'>&nbsp;r</span></code>
5239.
5240
5241<br>
5242<br>
5243<b><big><a name="5.8.k" id="5.8.k">5.8.k: d</a></big></b>
5244<br>
5245The argument <i>d</i> is a column vector of length <code>
5246<span style='white-space: nowrap'>&nbsp;p</span></code>
5247
5248
5249<br>
5250<br>
5251<b><big><a name="5.8.l" id="5.8.l">5.8.l: Bdia</a></big></b>
5252<br>
5253The argument <i>Bdia</i> is an <code>
5254<span style='white-space: nowrap'>&nbsp;m&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
5255 array.
5256For <code>
5257<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
5258 we define <code>
5259<span style='white-space: nowrap'>&nbsp;B_k&nbsp;\in&nbsp;\R^{m&nbsp;\times&nbsp;n}</span></code>
5260 by
5261<code>
5262<span style='white-space: nowrap'>&nbsp;\[<br>
5263&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B_k&nbsp;=&nbsp;Bdia(:,&nbsp;:,&nbsp;k)<br>
5264\]&nbsp;</span></code>
5265
5266
5267<br>
5268<br>
5269<b><big><a name="5.8.m" id="5.8.m">5.8.m: B</a></big></b>
5270<br>
5271The matrix <code>
5272<span style='white-space: nowrap'>&nbsp;B</span></code>
5273 is defined by
5274<code>
5275<span style='white-space: nowrap'>&nbsp;\[<br>
5276B&nbsp;<br>
5277=<br>
5278\left(&nbsp;\begin{array}{cccc}<br>
5279B_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>
52800&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>
52810&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>
5282&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>
5283\end{array}&nbsp;\right)<br>
5284\]&nbsp;</span></code>
5285
5286
5287<br>
5288<br>
5289<b><big><a name="5.8.n" id="5.8.n">5.8.n: Hdia</a></big></b>
5290<br>
5291The argument <i>Hdia</i> is an <code>
5292<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
5293 array.
5294For <code>
5295<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
5296 we define <code>
5297<span style='white-space: nowrap'>&nbsp;H_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
5298 by
5299<code>
5300<span style='white-space: nowrap'>&nbsp;\[<br>
5301&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H_k&nbsp;=&nbsp;Hdia(:,&nbsp;:,&nbsp;k)<br>
5302\]&nbsp;</span></code>
5303
5304
5305
5306<br>
5307<br>
5308<b><big><a name="5.8.o" id="5.8.o">5.8.o: Hlow</a></big></b>
5309<br>
5310The argument <i>Hlow</i> is an <code>
5311<span style='white-space: nowrap'>&nbsp;n&nbsp;\times&nbsp;n&nbsp;\times&nbsp;N</span></code>
5312 array.
5313For <code>
5314<span style='white-space: nowrap'>&nbsp;k&nbsp;=&nbsp;1&nbsp;,&nbsp;\ldots&nbsp;,&nbsp;N</span></code>
5315 we define <code>
5316<span style='white-space: nowrap'>&nbsp;L_k&nbsp;\in&nbsp;\R^{n&nbsp;\times&nbsp;n}</span></code>
5317 by
5318<code>
5319<span style='white-space: nowrap'>&nbsp;\[<br>
5320&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L_k&nbsp;=&nbsp;Hlow(:,&nbsp;:,&nbsp;k)<br>
5321\]&nbsp;</span></code>
5322
5323
5324<br>
5325<br>
5326<b><big><a name="5.8.p" id="5.8.p">5.8.p: H</a></big></b>
5327<br>
5328The matrix <code>
5329<span style='white-space: nowrap'>&nbsp;H</span></code>
5330 is defined by
5331<code>
5332<span style='white-space: nowrap'>&nbsp;\[<br>
5333H&nbsp;<br>
5334=<br>
5335\left(&nbsp;\begin{array}{cccc}<br>
5336H_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>
5337L_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>
53380&nbsp;&nbsp;&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&amp;&nbsp;\ddots&nbsp;&nbsp;&nbsp;&nbsp;\\<br>
5339&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>
5340\end{array}&nbsp;\right)<br>
5341\]&nbsp;</span></code>
5342
5343
5344<br>
5345<br>
5346<b><big><a name="5.8.q" id="5.8.q">5.8.q: F</a></big></b>
5347<br>
5348The result <i>F</i> is a column vector of length <code>
5349<span style='white-space: nowrap'>&nbsp;r&nbsp;+&nbsp;p&nbsp;+&nbsp;r</span></code>
5350
5351containing the value of the
5352<a href="#5.8.e">5.8.e: <span style='white-space: nowrap'>Kuhn-Tucker&nbsp;residual</span></a>
5353; i.e.,
5354<code>
5355<span style='white-space: nowrap'>&nbsp;F(s,&nbsp;y,&nbsp;u)</span></code>
5356.
5357
5358
5359
5360<br>
5361<br>
5362<b><big><a name="5.8.r" id="5.8.r">5.8.r: Example</a></big></b>
5363<br>
5364The file <a href="#5.8.1">5.8.1: <span style='white-space: nowrap'>kuhn_tucker_ok.m</span></a>
5365 contains an example and test of
5366<code><font color="blue">ckbs_kuhn_tucker</font></code>.
5367It returns true if <code><font color="blue">ckbs_kuhn_tucker</font></code> passes the test
5368and false otherwise.
5369
5370
5371<hr>Input File: ../src/ckbs_kuhn_tucker.m
5372
5373<hr>
5374 
5375
5376
5377<center><b><big><big><a name="5.8.1" id="5.8.1">5.8.1: ckbs_kuhn_tucker Example and Test</a>
5378</big></big></b></center>
5379<br>
5380<b><big><a name="5.8.1.a" id="5.8.1.a">5.8.1.a: Source Code</a></big></b>
5381
5382 <code><font color='blue'><pre style='display:inline'> 
5383function [ok] = kuhn_tucker_ok()
5384ok = true;
5385% -------------------------------------------------------------
5386% You can change these parameters
5387m    = 5;
5388n    = 4;
5389N    = 3;
5390% -------------------------------------------------------------
5391rand('seed', 123);
5392p     = n * N;
5393r     = m * N;
5394mu    = 1.5;
5395s     = rand(r, 1);
5396y     = rand(p, 1);
5397u     = rand(r, 1);
5398b     = rand(r, 1);
5399d     = rand(p, 1);
5400Bdia  = rand(m, n, N);
5401Hdia  = rand(n, n, N);
5402Hlow  = rand(n, n, N);
5403B     = zeros(r, p);
5404H     = zeros(p, p);
5405blk_n = 1 : n;
5406blk_m = 1 : m;
5407for k = 1 : N
5408        B(blk_m, blk_n) = Bdia(:,:, k);
5409        H(blk_n, blk_n) = Hdia(:,:, k);
5410        blk_n           = blk_n + n;
5411        blk_m           = blk_m + m;
5412end
5413blk_n = 1 : n;
5414for k = 2 : N;
5415        blk_minus           = blk_n;
5416        blk_n               = blk_n + n;
5417        H(blk_n, blk_minus) = Hlow(:,:, k);
5418        H(blk_minus, blk_n) = Hlow(:,:, k)';
5419end
5420% -------------------------------------
5421F = ckbs_kuhn_tucker(mu, s, y, u, b, d, Bdia, Hdia, Hlow);
5422% -------------------------------------
5423check = [ ...
5424        s + b + B * y; ...
5425        H * y + B' * u + d; ...
5426        s .* u - mu ...
5427];
5428ok    = ok &amp; ( max(abs(F - check)) &lt; 1e-10 );
5429return
5430end
5431</pre></font></code>
5432 
5433
5434<hr>Input File: ../test/kuhn_tucker_ok.m
5435
5436<hr>
5437 
5438
5439
5440<center><b><big><big><a name="6" id="6">6: Run All Correctness Tests</a>
5441</big></big></b></center>
5442<br>
5443<b><big><a name="6.a" id="6.a">6.a: Syntax</a></big></b>
5444
5445<br>
5446<code><font color="blue"><span style='white-space: nowrap'>all_ok<br>
5447all_ok(</span></font></code><i><span style='white-space: nowrap'>quick</span></i><code><font color="blue"><span style='white-space: nowrap'>)</span></font></code>
5448
5449<br>
5450<br>
5451<b><big><a name="6.b" id="6.b">6.b: quick</a></big></b>
5452<br>
5453If <i>quick</i> is true (or not present), only the quick tests are run,
5454otherwise all the tests are run.
5455
5456
5457<br>
5458<br>
5459<b><big><a name="6.c"