Previous Next box_f.m

ckbs_nonlinear: Example of Box Constraints

Syntax
global box_f_info
[fk    = box_f(kxk)
[fkFk] = box_f(kxk)

Notation

     
lower = box_f_info.lower
     
upper = box_f_info.upper
     
index = box_f_info.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) <= xkindex(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)
	global box_f_info
	index = box_f_info.index;
	lower = box_f_info.lower;
	upper = box_f_info.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