Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

NDSU

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)

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 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

rev September 26, 2011

NDSU

Weibull Distribution

ECE 341

In SciLab, create a function (I called it 'cost2.sci' for lack of a better name).


function y = cost2(x) // y = cost(z) e = x*log(x) + x - 3; y = e*e; endfunction

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

The answer is close to 1.9. Or, you can use leastsqfn


-->[e,x] = leastsq(cost2,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:


kx f(x) = ae ax u(x) = k1

e (x/) u(x)
k

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):


function y = cost(z) // y = cost(z) // Weibull distribution curve fit // for 0 < x < 2
JSG 2 rev September 26, 2011

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

Main Calling Routine:


-->[e,x] = leastsq(cost,[2.28,10]) 2.5151695 10.607163 -->cost(x) 0.0546140 -->xlabel('x'); -->ylabel('f(x)') -->title('Erlang vs. Weibull Distribution')

Result:

Erlang (blue) vs. Weibull Approximation (green)

JSG

rev September 26, 2011

NDSU

Weibull Distribution

ECE 341

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
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));

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:
-->[e,x] = leastsq(cost,[2.28,10]) x = e 2.9585655 = 0.0000109 6.5479469

Result:

JSG

rev September 26, 2011

NDSU

Weibull Distribution

ECE 341

Poisson Distribution (blue) and a Weibull Approximation (green)

Matching a Made-Up pdf:


Come up with a Weibull approximation for

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

rev September 26, 2011

You might also like