LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Normal.m
1classdef Normal < ContinuousDistribution
2 % Normal Normal (Gaussian) distribution
3 %
4 % Normal represents a normal (Gaussian) distribution with mean mu and
5 % standard deviation sigma. This distribution is widely used in modeling
6 % continuous phenomena due to the central limit theorem.
7 %
8 % @brief Normal distribution with specified mean and standard deviation
9 %
10 % Key characteristics:
11 % - Two parameters: mean (mu) and standard deviation (sigma)
12 % - Variance = sigma^2
13 % - SCV = sigma^2 / mu^2
14 % - Support: (-Inf, Inf)
15 % - Symmetric with zero skewness
16 %
17 % Note: For queueing applications, a truncated or shifted version may
18 % be needed since normal distributions can take negative values.
19 %
20 % Example:
21 % @code
22 % dist = Normal(5.0, 1.0); % Mean=5, StdDev=1
23 % samples = dist.sample(1000);
24 % @endcode
25 %
26 % Copyright (c) 2012-2026, Imperial College London
27 % All rights reserved.
28
29 methods
30 function self = Normal(mu, sigma)
31 % NORMAL Create a Normal distribution instance
32 %
33 % @brief Creates a Normal distribution with specified mean and std dev
34 % @param mu Mean of the distribution
35 % @param sigma Standard deviation of the distribution (must be positive)
36 % @return self Normal distribution instance
37 self@ContinuousDistribution('Normal', 2, [-Inf, Inf]);
38 if sigma < 0
39 line_error(mfilename, 'sigma parameter must be >= 0.0');
40 end
41 setParam(self, 1, 'mu', mu);
42 setParam(self, 2, 'sigma', sigma);
43 end
44
45 function ex = getMean(self)
46 % EX = GETMEAN()
47
48 % Get distribution mean
49 ex = self.getParam(1).paramValue;
50 end
51
52 function SCV = getSCV(self)
53 % SCV = GETSCV()
54
55 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
56 mu = self.getParam(1).paramValue;
57 sigma = self.getParam(2).paramValue;
58 if abs(mu) < GlobalConstants.FineTol
59 SCV = Inf;
60 else
61 SCV = (sigma * sigma) / (mu * mu);
62 end
63 end
64
65 function VAR = getVar(self)
66 % VAR = GETVAR()
67
68 % Get distribution variance
69 sigma = self.getParam(2).paramValue;
70 VAR = sigma * sigma;
71 end
72
73 function STD = getStd(self)
74 % STD = GETSTD()
75
76 % Get distribution standard deviation
77 STD = self.getParam(2).paramValue;
78 end
79
80 function SKEW = getSkewness(self)
81 % SKEW = GETSKEWNESS()
82
83 % Get distribution skewness (always 0 for normal)
84 SKEW = 0.0;
85 end
86
87 function Ft = evalCDF(self, t)
88 % FT = EVALCDF(SELF,T)
89
90 % Evaluate the cumulative distribution function at t
91 mu = self.getParam(1).paramValue;
92 sigma = self.getParam(2).paramValue;
93 Ft = 0.5 * (1 + erf((t - mu) / (sigma * sqrt(2))));
94 end
95
96 function L = evalLST(self, s)
97 % L = EVALST(S)
98
99 % Evaluate the Laplace-Stieltjes transform of the distribution
100 % function at s: E[e^(-sX)] = exp(mu*s + 0.5*sigma^2*s^2)
101 % Note: this is the moment-generating function evaluated at -s
102 mu = self.getParam(1).paramValue;
103 sigma = self.getParam(2).paramValue;
104 L = exp(mu * s + 0.5 * sigma * sigma * s * s);
105 end
106
107 function X = sample(self, n)
108 % X = SAMPLE(N)
109
110 % Get n samples from the distribution
111 if nargin < 2
112 n = 1;
113 end
114 mu = self.getParam(1).paramValue;
115 sigma = self.getParam(2).paramValue;
116 X = mu + sigma * randn(n, 1);
117 end
118
119 function proc = getProcess(self)
120 % PROC = GETPROCESS()
121
122 % Get process representation with actual distribution parameters
123 % Returns {mu, sigma} for normal distribution
124 proc = {self.getParam(1).paramValue, self.getParam(2).paramValue};
125 end
126 end
127
128 methods (Static)
129 function nm = fitMean(MEAN)
130 % NM = FITMEAN(MEAN)
131
132 % Fit distribution with given mean and unit standard deviation
133 nm = Normal(MEAN, 1.0);
134 end
135
136 function nm = fitMeanAndStd(MEAN, STD)
137 % NM = FITMEANANDSTD(MEAN, STD)
138
139 % Fit distribution with given mean and standard deviation
140 nm = Normal(MEAN, max(GlobalConstants.FineTol, STD));
141 end
142
143 function nm = fitMeanAndVar(MEAN, VAR)
144 % NM = FITMEANANDVAR(MEAN, VAR)
145
146 % Fit distribution with given mean and variance
147 nm = Normal(MEAN, max(GlobalConstants.FineTol, sqrt(VAR)));
148 end
149
150 function nm = fitMeanAndSCV(MEAN, SCV)
151 % NM = FITMEANANDSCV(MEAN, SCV)
152
153 % Fit distribution with given mean and squared coefficient of
154 % variation (SCV = variance / mean^2)
155 VAR = SCV * MEAN^2;
156 nm = Normal(MEAN, max(GlobalConstants.FineTol, sqrt(VAR)));
157 end
158 end
159
160end