function V = gma(D,k,L)
%
% Supplementary Matlab files for the paper:
%
% " Deterministic Modelling and Stochastic Simulation of Pathways using Matlab"
% by M.Ullah, H.Schmidt, K-H.Cho and O.Wolkenhauer
%
% This function implements the generalized law of mass action
%
% We would appreciate a citation if these files are used by others.

if nargin < 3
    L = -D.*(D < 0);
    i2 = L > 1;
else
    i2 = L>0 & L~=1 ;
end
i0 = L==0;
M1s = ones(size(k));
V = @Vfn;
    function xd = Vfn(t,x)          
        X = x(:,M1s);
        X(i0) = 1;
        X(i2) = X(i2).^L(i2);        
        xd = D*(k.*prod(X)).';
    end
end