Previous Next sine_f.m

ckbs_nonlinear: Example of Nonlinear Constraint

Syntax
[fk    = sine_f(kxkparams)
[fkFk] = sine_f(kxkparams)

Notation

      
index  = params.sine_f_index
      
offset = params.sine_f_offset

Purpose
Implements an upper limit that is an offset sine wave To be specific,
xkindex(2) ) <= sin( xkindex(1) + offset(1) ) ) + offset(2)

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 two elements specifying the state vector indices for the sine wave constraint (see purpose above). Each such index must be between one and n .

offset
is an integer column vector with two elements specifying the offsets for the sine wave (see purpose above).

fk
The return value fk is a scalar equal to
xkindex(2) ) - sin( xkindex(1) + offset(1) ) ) - offset(2)
so that the condition fk <= 0 is equivalent to the constraints in the purpose above.

Fk
The return value Fk is a row vector with n elements equal to the derivative of fk w.r.t xk .

Source Code
 
function [fk, Fk] = sine_f(k, xk, params)
    n      = size(xk, 1);
    index  = params.sine_f_index;
    offset = params.sine_f_offset;
    if (size(index, 1) ~= 2) | (size(index, 2) ~= 1)
        size_index_1 = size(index, 1)
        size_index_2 = size(index, 2)
        error('sine_f: index is not a column vector with two elements')
    end
    if (size(offset, 1) ~= 2) | (size(offset, 2) ~= 1)
        size_offset_1 = size(offset, 1)
        size_offset_2 = size(offset, 2)
        error('sine_f: offset is not a column vector with two elements')
    end
    if (max(index) > n) | (min(index) < 1)
        max_index = max(index)
        min_index = min(index)
        error('sine_f: max(index) > size(xk, 1) or min(index) < 1')
    end
    fk = xk( index(2) ) - sin( xk( index(1) + offset(1) ) ) - offset(2);
    Fk           = zeros(1, n);
    Fk(index(2)) = 1;
    Fk(index(1)) = Fk(index(1)) - cos( xk( index(1) + offset(1) ) );
    return
end

Input File: example/nonlinear/sine_f.m