calculating the probability in matlab

Matlab provides a variety of functions for calculating probability distributions, such as normpdf, normcdf, binopdf, poisspdf, etc. These functions take specific parameters such as mean, variance or lambda, depending on the distribution, and return the desired probability values.

For example, the following code calculates the probability that a normally distributed random variable with mean 0 and standard deviation 1 is less than 1:

main.m
>> normcdf(1, 0, 1)

ans =

    0.8413
39 chars
6 lines

This returns the value 0.8413, indicating that the probability of the random variable being less than 1 is 0.8413.

Similarly, the following code calculates the value of the probability density function of a binomial distribution with parameters n=10 and p=0.5, at the value k=3:

main.m
>> binopdf(3, 10, 0.5)

ans =

    0.1172
42 chars
6 lines

This returns the value 0.1172, indicating that the probability of k=3 successes in n=10 trials with probability of success p=0.5 is 0.1172.

In addition, Matlab also provides functions for generating random variables from specific distributions such as normrnd, binornd, poissrnd, etc.

For example, the following code generates a random variable from a normal distribution with mean 0 and standard deviation 1:

main.m
>> normrnd(0, 1)

ans =

   -1.6050
36 chars
6 lines

This returns a random value close to -1.6050.

Overall, Matlab provides a useful set of functions for working with probability distributions, enabling the user to perform a variety of probability computations and generate random variables from specified distributions.

related categories

gistlibby LogSnag