1function MAP = map_bernstein(f, n)
2% MAP = MAP_BERNSTEIN(F, N) - Convert distribution to MAP via Bernstein approximation
4% This function implements Bernstein polynomial approximation to convert any
5% continuous distribution (specified by its PDF) to a Markovian Arrival Process
9% f: PDF function handle @(x) - probability density function
10% n: Number of phases for the approximation (default: 20)
13% MAP: MAP representation {D0, D1}
14% Note: Caller must rescale to target mean using map_scale
17% % Convert a gamma distribution with shape=2, scale=1
18% pdf_func = @(x) gampdf(x, 2, 1);
19% MAP = map_bernstein(pdf_func, 20);
20% MAP = map_scale(MAP, targetMean); % Rescale to desired mean
23% Bernstein polynomial approximation
for phase-type distributions
25% Copyright (c) 2012-2026, Imperial College London
32% Bernstein approximation of order n
37 if isfinite(fi) && fi > 0
42% Handle
case where normalizing constant
is invalid
43if c <= 0 || ~isfinite(c)
44 % Fallback to Erlang-n with unit mean (caller will rescale)
45 MAP = map_erlang(1, n);
50T = diag(-[1:n]) + diag([1:(n-1)], 1);
52% Build initial probability vector alpha
57 if isfinite(fi) && fi > 0
58 alpha(i) = fi / (i * c);
62% Normalize alpha to ensure it sums to 1
64 alpha = alpha / sum(alpha);
66 alpha(1) = 1; % Default to starting in first phase
70P = repmat(alpha, n, 1);