forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgammaVariate.m
More file actions
39 lines (34 loc) · 1.05 KB
/
gammaVariate.m
File metadata and controls
39 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function out = gammaVariate( dValues, alpha, beta, A0, t0, varargin )
% out = gammaVariate( dValues, alpha, beta, A0, t0 [, deriv ] )
%
% Standard parameterization of the gamma variate function
%
% Inputs:
% dValues - domain values specifying where to evaluate the function
%
% Optional Inputs:
% deriv - if true, then evaluate the derivative
%
% Ouputs:
% out - values of gamma variate function at sample times
%
% Written by Nicholas Dwork, 2019
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
p = inputParser;
p.addOptional( 'deriv', 0 );
p.parse( varargin{:} );
deriv = p.Results.deriv;
dts = dValues - t0;
if deriv == 0
out = A0 * dts.^alpha .* exp( -dts / beta );
else
% calculate the first derivative
out = A0 * dts.^(alpha-1) .* exp( -dts / beta ) .* ( alpha - dts / beta );
end
out( dts <= 0 ) = 0;
out = out(:);
end