Index-> contents reference index search external Previous Next Up-> ckbs ckbs_nonlinear nonlinear_utility box_f.m ckbs-> license ckbs_t_general ckbs_nonlinear ckbs_L1_nonlinear ckbs_affine ckbs_affine_singular ckbs_L1_affine utility all_ok.m whatsnew wishlist bib ckbs_nonlinear-> get_started_ok.m sine_wave_ok.m vanderpol_ok.m nonlinear_utility nonlinear_utility-> box_f.m direct_h.m distance_h.m no_f.m persist_g.m pos_vel_g.m sine_f.m box_f.m Headings-> Syntax Notation Purpose k xk index lower upper fk Fk Source Code

ckbs_nonlinear: Example of Box Constraints

Syntax
```[fk]     = box_f(k, xk, params) ``` ```[fk, Fk] = box_f(k, xk, params) ```
Notation
```       lower = params.box_f_lower       upper = params.box_f_upper       index = params.box_f_index       ell   = 2 * size(index, 1) ```
Purpose
Implements box constraints with upper and lower limits that are the same for all time indices `k` . To be specific, for `p = 1 , ... , ell / 2` , ```       lower(p) <= xk( index(p) ) <= upper(p) ```
k
is an integer scalar specifying the time index (not used).

xk
is a column vector with length `n` specifying a value for the state vector at the current time index.

index
is an integer column vector with `ell / 2` elements specifying the state vector indices for which there is a box constraints. Each such index must be between one and `n` .

lower
is a column vector with `ell / 2` elements specifying the lower limits for the box constraints.

upper
is a column vector with `ell / 2` elements specifying the upper limits for the box constraints.

fk
The return value `fk` is a column vector of length `ell` such that the condition `all( fk <= 0` is equivalent to the constraints in the purpose above.

Fk
The return value `Fk` is an `ell x n` matrix equal to the Jacobian of `fk` w.r.t `xk` .

Source Code ``` function [fk, Fk] = box_f(k, xk, params) index = params.box_f_index; lower = params.box_f_lower; upper = params.box_f_upper; ell = 2 * size(lower, 1); n = size(xk, 1); % if (size(lower, 2) ~= 1) | (size(upper, 2) ~= 1) | ... (size(xk, 2) ~= 1) size_lower_2 = size(lower, 2) size_upper_2 = size(upper, 2) size_index_2 = size(index, 2) size_xk_2 = size(xk, 2) error('box_f: either lower, upper, index or xk not a column vector') end if (2 * size(upper, 1) ~= ell) | (2 * size(index, 1) ~= ell) size_lower_1 = size(lower, 1) size_upper_1 = size(upper, 1) size_index_1 = size(index, 1) error('box_f: lower, upper, or index has a different size') end if (max(index) > n) | (min(index) < 1) max_index = max(index) min_index = min(index) error('box_f: max(index) > size(xk, 1) or min(index) < 1') end % fk = zeros(ell, 1); Fk = zeros(ell, n); for p = 1 : (ell / 2) j = index(p); fk(2 * p - 1, 1) = xk(j) - upper(p); Fk(2 * p - 1, j) = +1.; % fk(2 * p, 1) = lower(p) - xk(j); Fk(2 * p, j) = -1.; end return end ```
Input File: example/nonlinear/box_f.m