calculate the probability in the normal distrubution in matlab

MATLAB provides the normcdf function to calculate the cumulative distribution function (CDF) of the normal distribution. The CDF gives the probability of getting a value less than or equal to a given value (i.e., the area under the curve to the left of the given value).

Here's an example:

main.m
% Define the mean and standard deviation of the normal distribution
mu = 0;
sigma = 1;

% Calculate the probability of getting a value less than or equal to 1
p = normcdf(1, mu, sigma);

% Print the result
fprintf('P(x <= 1) = %f\n', p);
238 chars
10 lines

This will output:

main.m
P(x <= 1) = 0.841345
21 chars
2 lines

You can also use the normpdf function to calculate the probability density function (PDF) of the normal distribution. The PDF gives the probability of getting a specific value (i.e., the height of the curve at the given value).

Here's an example:

main.m
% Define the mean and standard deviation of the normal distribution
mu = 0;
sigma = 1;

% Calculate the probability density at x = 1
p = normpdf(1, mu, sigma);

% Print the result
fprintf('P(x = 1) = %f\n', p);
211 chars
10 lines

This will output:

main.m
P(x = 1) = 0.241971
20 chars
2 lines

Note that the probability of getting a specific value in a continuous distribution like the normal distribution is actually zero, so the PDF gives the probability density instead.

related categories

gistlibby LogSnag