1classdef Weibull < ContinuousDistribution
2 % Weibull Distribution
for reliability and failure time modeling
4 % Weibull represents the Weibull distribution with shape and scale parameters.
5 % This distribution
is widely used in reliability engineering and survival
6 % analysis
for modeling failure times, life distributions, and extreme value
7 % phenomena. It can model increasing, decreasing, or constant hazard rates.
9 % @brief Weibull distribution
for reliability and failure time analysis
11 % Key characteristics:
12 % - Two parameters: scale (alpha) and shape (r)
13 % - Mean = alpha * Γ(1 + 1/r) where Γ
is the gamma function
14 % - Flexible hazard rate behavior based on shape parameter
16 % - Includes exponential (r=1) as special
case
18 % Hazard rate behavior:
19 % - r < 1: Decreasing failure rate (infant mortality)
20 % - r = 1: Constant failure rate (exponential, random failures)
21 % - r > 1: Increasing failure rate (wear-out failures)
23 % The Weibull distribution
is used
for:
24 % - Reliability and survival analysis
25 % - Failure time modeling
26 % - Lifetime data analysis
27 % - Wind speed modeling
28 % - Service time distributions with varying hazard rates
32 % failure_dist = Weibull(2.0, 1000); % Scale=1000, Shape=2 (wear-out)
33 % reliability_time = failure_dist.sample(100);
36 % Copyright (c) 2012-2026, Imperial College London
37 % All rights reserved.
40 function self = Weibull(shape, scale)
41 % WEIBULL Create a Weibull distribution instance
43 % @brief Creates a Weibull distribution with specified shape and scale
44 % @param shape Shape parameter r (must be positive)
45 % @param scale Scale parameter alpha (must be positive)
46 % @return self Weibull distribution instance
47 self@ContinuousDistribution('Weibull',2,[0,Inf]);
49 line_error(mfilename,
'shape parameter must be >= 0.0');
51 setParam(self, 1,
'alpha', scale);
52 setParam(self, 2,
'r', shape);
55 function ex = getMean(self)
58 % Get distribution mean
59 alpha = self.getParam(1).paramValue;
60 r = self.getParam(2).paramValue;
61 ex = alpha * gamma(1+1/r);
64 function SCV = getSCV(self)
67 % Get distribution squared coefficient of variation (SCV = variance / mean^2)
68 alpha = self.getParam(1).paramValue;
69 r = self.getParam(2).paramValue;
70 VAR = alpha^2*(gamma(1+2/r)-(gamma(1+1/r))^2);
71 ex = alpha * gamma(1+1/r);
75 function X = sample(self, n)
78 % Get n samples from the distribution
79 if nargin<2 %~exist(
'n',
'var'),
82 alpha = self.getParam(1).paramValue;
83 r = self.getParam(2).paramValue;
84 X = wblrnd(alpha,r,n,1);
87 function Ft = evalCDF(self,t)
88 % FT = EVALCDF(SELF,T)
90 % Evaluate the cumulative distribution function at t
92 alpha = self.getParam(1).paramValue;
93 r = self.getParam(2).paramValue;
94 Ft = wblcdf(t,alpha,r);
97 function L = evalLST(self, s)
99 % Evaluate the Laplace-Stieltjes transform of the distribution function at s
100 % The LST of Weibull distribution doesn't have a simple closed form.
101 % We compute it numerically using the definition: E[e^(-sX)] = ∫₀^∞ e^(-sx) f(x) dx
102 % where f(x) is the Weibull PDF
104 alpha = self.getParam(1).paramValue; % scale parameter
105 r = self.getParam(2).paramValue; % shape parameter
107 % Use numerical integration
108 % For practical purposes, we integrate up to a reasonable upper bound
109 upperBound = alpha * (-log(1e-10))^(1/r); % covers most of the distribution
117 % Weibull PDF: (r/α)(x/α)^(r-1) * exp(-(x/α)^r)
118 pdf = (r / alpha) * (x / alpha)^(r - 1) * exp(-(x / alpha)^r);
119 L = L + exp(-s * x) * pdf;
126 function proc = getProcess(self)
127 % PROC = GETPROCESS()
129 % Get process representation with actual distribution parameters
130 % Returns {shape (r), scale (alpha)}
for Weibull distribution
131 proc = {self.getParam(2).paramValue, self.getParam(1).paramValue};
136 function pa = fitMeanAndSCV(MEAN, SCV)
137 % PA = FITMEANANDSCV(MEAN, SCV)
139 % Fit distribution with given mean and squared coefficient of variation (SCV=variance/mean^2)
141 r = c^(-1.086); % Justus approximation (1976)
142 alpha = MEAN / gamma(1+1/r);
143 pa = Weibull(r,alpha);