Professional Documents
Culture Documents
13 Weibull Distribution
13 Weibull Distribution
Weibull Distribution
ECE 341
Weibull Distribution
See the Wikipedia page for more information. This page gives a MATLAB example.
Weibull Distribution:
f (x ; , k ) =
kx
k1
e (x/) u(x)
k
The Weibull distribution has no theroetical underpinnings. It is just a function which is able to approximate a large number of probability density functions fairly well - using only two degrees of freedom: and k. Here, we'll show how to find and k to approximate several functions in MATLAB. To do this, we'll use fminsearch() in MATLAB leastsq() in SciLab.
MATLAB: fminsearch()
A very useful function is fminsearch. This finds the minimum of a function. For example, find the square root of two. Create a function which is a minimum at the square root of two:
Cost.m function [y] = cost(z) e = z*z - 2; y = e*e;
This function computes the error between your guess, z, and the correct answer. To make the result a minimum when the error is zero, the function returns the square of the error. Now from MATLAB type
fminsearch('cost',4)
SciLab: leastsq():
SciLab's version is spelled 'leastsq()'. This is a nonlinear optimization routine that finds the minimum of a function. For example, suppose you wanted to find the solution to
x ln(x) + x = 3
First, create a function in SciLab which returns a minimum for x solving the above equation. One way to do this is compute the error and square it:
y = (x ln(x) + x - 3)2
JSG
NDSU
Weibull Distribution
ECE 341
Execute and load this into SciLab. You can use trial and error to find x. Keep guessing until cost2 returns zero
-->cost2(2) 0.1492233 -->cost2(3) 10.862541 -->cost2(2.1) 0.4330541 -->cost2(1.9) 0.0142856
Getting back to a Weibull distribution, find parameters and k so that a Weibull distribution approximates the following pdf:
e (x/) u(x)
k
1 a
f X (x) =
a n x n1 e ax (n1)!
NDSU
Weibull Distribution
ECE 341
k = z(1); L = z(2); x = [0:0.01:20]'; a = 0.5; n = 5; f = (a^n) * (x .^ (n-1)) .* (exp(-a*x) ) / factorial(n-1) ; W = (k/L) * ( (x/L) .^ (k-1) ) .* exp( -( (x/L) .^ k ) ); e = f - W; plot(x,f,x,W); y = sum(e.^2); endfunction
Result:
JSG
NDSU
Weibull Distribution
ECE 341
f ( k) =
1 k!
k e
where = np = 5
function y = cost(z) // y = cost(z) // Weibull distribution curve fit k = z(1); L = z(2); x = [0.1:0.1:20]'; np = 5; f = 0.2 * (1 ./ (gamma(x) ) ) .* (np .^ x) * (exp(-np));
Calling Routine:
-->[e,x] = leastsq(cost,[2.28,10]) x = e 2.9585655 = 0.0000109 6.5479469
Result:
JSG
NDSU
Weibull Distribution
ECE 341
f(x) = 0.75 x (2 x)
Cost Function:
0<x<2
function y = cost(z) // y = cost(z) // Weibull distribution curve fit k = z(1); L = z(2); x = [0:0.01:5]'; f = 0.75 * x .* (2-x) .* (x<2); W = (k/L) * ( (x/L) .^ (k-1) ) .* exp( -( (x/L) .^ k ) ); e = f - W; plot(x,f,x,W); y = sum(e.^2); endfunction
Calling Routine:
-1->[e,x] = leastsq(cost,[2,1]) x =
JSG 5 rev September 26, 2011
NDSU
2.2862116 = 0.8555193 -1->cost(x) ans = 0.9249429 -1->xlabel('x'); -1->ylabel('f(x)') 1.1933199
Weibull Distribution
ECE 341
Result:
JSG