LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
Weibull.m
1classdef Weibull < ContinuousDistribution
2 % Weibull Distribution for reliability and failure time modeling
3 %
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.
8 %
9 % @brief Weibull distribution for reliability and failure time analysis
10 %
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
15 % - Support: (0, ∞)
16 % - Includes exponential (r=1) as special case
17 %
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)
22 %
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
29 %
30 % Example:
31 % @code
32 % failure_dist = Weibull(2.0, 1000); % Scale=1000, Shape=2 (wear-out)
33 % reliability_time = failure_dist.sample(100);
34 % @endcode
35 %
36 % Copyright (c) 2012-2026, Imperial College London
37 % All rights reserved.
38
39 methods
40 function self = Weibull(shape, scale)
41 % WEIBULL Create a Weibull distribution instance
42 %
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]);
48 if shape < 0
49 line_error(mfilename,'shape parameter must be >= 0.0');
50 end
51 setParam(self, 1, 'alpha', scale);
52 setParam(self, 2, 'r', shape);
53 end
54
55 function ex = getMean(self)
56 % EX = GETMEAN()
57
58 % Get distribution mean
59 alpha = self.getParam(1).paramValue;
60 r = self.getParam(2).paramValue;
61 ex = alpha * gamma(1+1/r);
62 end
63
64 function SCV = getSCV(self)
65 % SCV = GETSCV()
66
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);
72 SCV = VAR / ex^2;
73 end
74
75 function X = sample(self, n)
76 % X = SAMPLE(N)
77
78 % Get n samples from the distribution
79 if nargin<2 %~exist('n','var'),
80 n = 1;
81 end
82 alpha = self.getParam(1).paramValue;
83 r = self.getParam(2).paramValue;
84 X = wblrnd(alpha,r,n,1);
85 end
86
87 function Ft = evalCDF(self,t)
88 % FT = EVALCDF(SELF,T)
89
90 % Evaluate the cumulative distribution function at t
91 % AT T
92 alpha = self.getParam(1).paramValue;
93 r = self.getParam(2).paramValue;
94 Ft = wblcdf(t,alpha,r);
95 end
96
97 function L = evalLST(self, s)
98 % L = EVALST(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
103
104 alpha = self.getParam(1).paramValue; % scale parameter
105 r = self.getParam(2).paramValue; % shape parameter
106
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
110 n = 1000;
111 dx = upperBound / n;
112 L = 0.0;
113
114 for i = 1:n
115 x = i * dx;
116 if x > 0
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;
120 end
121 end
122
123 L = L * dx;
124 end
125
126 function proc = getProcess(self)
127 % PROC = GETPROCESS()
128
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};
132 end
133 end
134
135 methods (Static)
136 function pa = fitMeanAndSCV(MEAN, SCV)
137 % PA = FITMEANANDSCV(MEAN, SCV)
138
139 % Fit distribution with given mean and squared coefficient of variation (SCV=variance/mean^2)
140 c = sqrt(SCV);
141 r = c^(-1.086); % Justus approximation (1976)
142 alpha = MEAN / gamma(1+1/r);
143 pa = Weibull(r,alpha);
144 end
145 end
146
147end