LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
rap_sample.m
1function sample = rap_sample(RAP, n, xs)
2% SAMPLE = RAP_SAMPLE(RAP, N, XS) - Generate random samples from RAP distribution
3%
4% Generate samples from a Rational Arrival Process (RAP) distribution.
5% The marginal distribution of RAP inter-arrival times is a Matrix
6% Exponential (ME) distribution, so this function delegates to me_sample.
7%
8% Input:
9% RAP: RAP distribution as either:
10% - RAP object
11% - Process cell array {H0, H1}
12% N: Number of samples to generate (default: 1)
13% XS: Optional pre-computed grid for CDF evaluation
14% If not provided, auto-generates grid based on mean and variance
15%
16% Output:
17% SAMPLE: Column vector of N samples from the RAP marginal distribution
18%
19% Note:
20% This function generates samples from the marginal distribution only.
21% It does not preserve the correlation structure of the RAP.
22% For full RAP simulation with correlations, use map_sample instead.
23%
24% Examples:
25% rap = RAP([-2, 1; 0.5, -1.5], [0.5, 0.5; 0.5, 0.5]);
26% samples = rap_sample(rap, 10000);
27%
28% % Or use process representation directly
29% RAP_proc = {[-2, 1; 0.5, -1.5], [0.5, 0.5; 0.5, 0.5]};
30% samples = rap_sample(RAP_proc, 10000);
31%
32% Copyright (c) 2012-2026, Imperial College London
33% All rights reserved.
34
35% Handle input arguments
36if nargin < 2
37 n = 1;
38end
39
40% Extract process representation
41if isa(RAP, 'RAP')
42 RAP_proc = RAP.getProcess();
43elseif iscell(RAP)
44 RAP_proc = RAP;
45else
46 error('RAP must be either a RAP object or a cell array {H0, H1}');
47end
48
49% Delegate to me_sample
50% The marginal distribution of RAP is ME with the same {H0, H1} representation
51if nargin < 3 || isempty(xs)
52 sample = me_sample(RAP_proc, n);
53else
54 sample = me_sample(RAP_proc, n, xs);
55end
56
57end