function RealSystem(block)
    setup(block);
    
function setup(block)
    block.NumContStates  = 2;   % p, delta
    block.NumInputPorts  = 1;   % gamma
    block.NumOutputPorts = 2;   % p, delta
    block.NumDialogPrms  = 3;   % v, L, d
    block.SampleTimes=[0 0];
    
    block.InputPort(1).Dimensions   = 1;
    block.InputPort(1).SamplingMode = 0;
    block.InputPort(1).DirectFeedthrough = false;
    
    block.OutputPort(1).Dimensions   = 1;
    block.OutputPort(1).SamplingMode = 0;
    
    block.OutputPort(2).Dimensions   = 1;
    block.OutputPort(2).SamplingMode = 0;
    
    block.RegBlockMethod('InitializeConditions',@init);
    block.RegBlockMethod('Derivatives',@derivatives);
    block.RegBlockMethod('Outputs',@out);

function init(block)
    block.ContStates.Data=[0 0];
   
function derivatives(block)
%     % dp = v*tan(delta) - L/(L+d) * tan(gamma)
%     block.Derivatives.Data(1) = ...
%         block.DialogPrm(1).Data * tan( block.ContStates.Data(2) ) - ...
%         block.DialogPrm(2).Data / ( block.DialogPrm(2).Data + block.DialogPrm(3).Data ) * ...
%         tan( block.InputPort.Data );
%     % ddelta = -v/(L+d) * tan(gamma)
%     block.Derivatives.Data(2) = ...
%         - block.DialogPrm(1).Data / ( block.DialogPrm(2).Data + block.DialogPrm(3).Data ) * ...
%         tan( block.InputPort.Data );
    v = block.DialogPrm(1).Data;
    L = block.DialogPrm(2).Data;
    d = block.DialogPrm(3).Data;
    gamma = block.InputPort(1).Data;

    % p
    block.Derivatives.Data(1) = v*tan( block.ContStates.Data(2) ) - ...
    	v*L/(L+d)*tan(gamma) - ...
        v/(L+d)*( block.ContStates.Data(1) )*tan( block.ContStates.Data(2) )*tan(gamma);
    
    % delta
    block.Derivatives.Data(2) = -v/(L+d)*tan(gamma);

%     % p
%     block.Derivatives.Data(1) = v*tan( block.ContStates.Data(2) ) - ...
%     	v*tan(gamma) - ...
%         v/L*( block.ContStates.Data(1) )*tan( block.ContStates.Data(2) )*tan(gamma);
%     
%     % delta
%     block.Derivatives.Data(2) = -v/L*tan(gamma);
    
function out(block)
    % p (position of the line)
    block.OutputPort(1).Data = block.ContStates.Data(1);
    
    % delta (orientation error)
    block.OutputPort(2).Data = block.ContStates.Data(2);
    
    