Вы находитесь на странице: 1из 6

Weibull Distribution

See the Wikipedia page for more information.


This page gives a MATLAB example.
Weibull Distribution:
f(x;,k) =
k

k1
e
(x/)
k
u(x)
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
f unct i on [ 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
f mi nsear ch( ' cost ' , 4)
This routine will iterate until if finds the minimum: 1.414.
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 l n( 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 l n( x) + x - 3) 2
NDSU Weibull Distribution ECE 341
J SG 1 rev September 26, 2011
In SciLab, create a function (I called it 'cost2.sci' for lack of a better name).
f unct i on y = cost 2( x)
/ / y = cost ( z)
e = x*l og( x) + x - 3;
y = e*e;
endf unct i on
Execute and load this into SciLab. You can use trial and error to find x. Keep guessing until cost2 returns zero
- - >cost 2( 2)
0. 1492233
- - >cost 2( 3)
10. 862541
- - >cost 2( 2. 1)
0. 4330541
- - >cost 2( 1. 9)
0. 0142856
The answer is close to 1.9. Or, you can use leastsqfn
- - >[ e, x] = l east sq( cost 2, 1. 7)
x =
1. 8545507
e =
1. 458D- 31
The answer is 1.8545507.
Getting back to a Weibull distribution, find parameters and k so that a Weibull distribution approximates the
following pdf:
Matching an exponential distribution:
f(x) = ae
ax
u(x) =
k

k1
e
(x/)
k
u(x)
This is actually exact:
k=1
=
1
a
Matching Erlang distributions:
f
X
(x) =
a
n
x
n1
e
ax
(n1)!
SciLab Code for f(x):
f unct i on y = cost ( z)
/ / y = cost ( z)
/ / Wei bul l di st r i but i on cur ve f i t
/ / f or 0 < x < 2
NDSU Weibull Distribution ECE 341
J SG 2 rev September 26, 2011
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) ) / f act or i al ( n- 1) ;

W= ( k/ L) * ( ( x/ L) . ^ ( k- 1) ) . * exp( - ( ( x/ L) . ^ k ) ) ;

e = f - W;

pl ot ( x, f , x, W) ;
y = sum( e. ^2) ;

endf unct i on
Main Calling Routine:
- - >[ e, x] = l east sq( cost , [ 2. 28, 10] )
2. 5151695 10. 607163

- - >cost ( x)
0. 0546140

- - >xl abel ( ' x' ) ;
- - >yl abel ( ' f ( x) ' )
- - >t i t l e( ' Er l ang vs. Wei bul l Di st r i but i on' )
Result:
Erlang (blue) vs. Weibull Approximation (green)
NDSU Weibull Distribution ECE 341
J SG 3 rev September 26, 2011
Matching a Binomial / Pascal Distribution (Poisson):
n =500
p =0.01
np =1
Approximate this as a Poisson distribution:
f(k) =
1
k!

k
e

where = np = 5
f unct i on y = cost ( z)
/ / y = cost ( z)
/ / Wei bul l di st r i but i on cur ve f i t
k = z( 1) ;
L = z( 2) ;

x = [ 0. 1: 0. 1: 20] ' ;

np = 5;

f = 0. 2 * ( 1 . / ( gamma( x) ) ) . * ( np . ^ x) * ( exp( - np) ) ;



W= ( k/ L) * ( ( x/ L) . ^ ( k- 1) ) . * exp( - ( ( x/ L) . ^ k ) ) ;

e = f - W;

pl ot ( x, f , x, W) ;
y = sum( e. ^2) ;

endf unct i on
Calling Routine:
- - >[ e, x] = l east sq( cost , [ 2. 28, 10] )
x =

2. 9585655 6. 5479469
e =

0. 0000109
Result:
NDSU Weibull Distribution ECE 341
J SG 4 rev September 26, 2011
Poisson Distribution (blue) and a Weibull Approximation (green)
Matching a Made-Up pdf:
Come up with a Weibull approximation for
0 <x <2 f(x) = 0.75 x (2 x)
Cost Function:
f unct i on y = cost ( z)
/ / y = cost ( z)
/ / Wei bul l di st r i but i on cur ve f i t
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;

pl ot ( x, f , x, W) ;
y = sum( e. ^2) ;

endf unct i on
Calling Routine:
- 1- >[ e, x] = l east sq( cost , [ 2, 1] )
x =

NDSU Weibull Distribution ECE 341
J SG 5 rev September 26, 2011
2. 2862116 1. 1933199
e =

0. 8555193

- 1- >cost ( x)
ans =

0. 9249429

- 1- >xl abel ( ' x' ) ;

- 1- >yl abel ( ' f ( x) ' )
Result:
NDSU Weibull Distribution ECE 341
J SG 6 rev September 26, 2011

Вам также может понравиться