how to calculate normal distribution in matlab

To calculate the normal distribution in Matlab, you can use the normpdf or normcdf function.

normpdf(x,mu,sigma) returns the probability density function (PDF) at x of the normal distribution with mean mu and standard deviation sigma.

normcdf(x,mu,sigma) returns the cumulative distribution function (CDF) at x of the normal distribution with mean mu and standard deviation sigma.

Here's an example code snippet that calculates and plots the PDF and CDF of the normal distribution with mean 0 and standard deviation 1:

main.m
% Set up parameters
mu = 0; % mean
sigma = 1; % standard deviation

% x vector for evaluation
x = linspace(-5,5,1000);

% PDF and CDF calculation
pdf = normpdf(x,mu,sigma);
cdf = normcdf(x,mu,sigma);

% Plot a figure with both the PDF and CDF
figure;
subplot(1,2,1);
plot(x,pdf);
title('PDF of Normal Distribution');
ylabel('Probability Density');
xlabel('x');
subplot(1,2,2);
plot(x,cdf);
title('CDF of Normal Distribution');
ylabel('Cumulative Probability');
xlabel('x');
474 chars
24 lines

This code will produce a figure with two subplots, one showing the PDF and the other showing the CDF.

gistlibby LogSnag