Code covered by the BSD License  

Highlights from
Simulation of counting processes and piecewise constant functions

image thumbnail
stairintegr(jptimes, fval, startv)
function [ival] = stairintegr(jptimes, fval, startv)
%
% STAIRINTEGR Integrate piecewise constant (stair) functions. The results
% are piecewise linear functions. 
%   Both the piecewise constant and piecewise linear functions are stored
%   in two matrices containing the jump or break points and function
%   values at these points respectively. If they have different number of
%   jumps, each vector is padded with the last value to have the same
%   length. All functions are assumed to be right-continuous. 
%
% [ival] = stairintegr(jptimes, fval [, startv])
%
% Inputs:
%        jptimes - a matrix of the jump times stored columnwise
%        fval - a matrix of function values at the jump points stored
%          columnwise 
%        startv - optional; start value to add to the integral; 
%          a row vector with length equal to size(jptimes, 2). The
%          default value is zeros(1, size(jptimes, 2)).
%
% Outputs:
%        ival - a matrix of the values of the integral at the jump
%          points. The matrix of break points is equal to jptimes.
%
% See also STAIRCUT, STAIRSUM.

% Authors: R.Gaigalas, I.Kaj
% v2.0 17-Oct-05

  % start value is zero if omitted
  if (nargin==2) 
    startv = zeros(1, size(jptimes, 2));
  end

  % for the linear function F=Int(f) we have delta_F=f(x)*delta_x
  ival = cumsum([startv; fval(1:end-1, :).*diff(jptimes)]);

Contact us at files@mathworks.com