tags:

views:

95

answers:

1

I am using a book with a function I would like to use. However I don't think I am getting the correct values from my function.

Here is the instruction from the book:

alt text

Here is the function as I have created it in MATLAB:

function [ shortProbability ] = pShort( zkt, zktStar, short)

if zkt > zktStar
    shortProbability = 0;
else
    normalizer = 1/(1-exp(-short*zktStar));
    shortProbability = normalizer * (short * exp(-short*zkt));
end

end

The values I am plugging in are:

zkt = 0:1:100
zktStar = 50;
short = 0.01;

However my graph doesn't behave like the one which I am supposed to end up with, which is this:

alt text

I am getting this from the graph, which looks correct, however I don't think it is being normalized properly:

alt text

Can anyone help me to correct this function?

+1  A: 

This is the exponential distribution. You can use EXPPDF and EXPCDF from the Statistics Toolbox:

normalizer = 1 ./ ( expcdf(zktStar,1/short) - expcdf(0,1/short) );
shortProbability = exppdf(zkt, 1/short) * normalizer;

and it should be equivalent to what you have...


This is what I get when I combine it with the graph from your previous question:

alt text

To confirm, we compute the area under each of the curves (close enough to 1):

>> trapz(zkt,hitProbabilty)
ans =
     1

>> trapz(zkt,shortProbability)
ans =
       1.0077
Amro
Thanks again Amro, your really helping me out! I've been able to convert these MATLAB functions to C# by using the MathsDotNet library, they contain a lot of useful methods for these statistic functions.
James