The function 'gaussian_2d()' generates and visualizes a 2D Gaussian distribution by defining its parameters, creating a grid of coordinates, and calculating the probability density function (PDF). It assumes a correlation coefficient of zero for simplicity, resulting in an axis-aligned Gaussian distribution. The output is a contour plot displaying the distribution with specified contour levels and labels.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views1 page
Oscil
The function 'gaussian_2d()' generates and visualizes a 2D Gaussian distribution by defining its parameters, creating a grid of coordinates, and calculating the probability density function (PDF). It assumes a correlation coefficient of zero for simplicity, resulting in an axis-aligned Gaussian distribution. The output is a contour plot displaying the distribution with specified contour levels and labels.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
function gaussian_2d() % gaussian_2d() generates and plots a 2D Gaussian distribution.
% % What it does: This function
defines the parameters (mean and standard % deviation) for a 2D Gaussian distribution. It then creates a grid of x and % y coordinates and calculates the probability density function (PDF) of the % Gaussian at each point on the grid. Finally, it visualizes the distribution % using a contour plot. % % Theory: The probability density function (PDF) of a 2D Gaussian (or % bivariate normal) distribution is given by: % % f(x, y) = (1 / (2pisigma_xsigma_ysqrt(1-rho^2))) * % exp(-1 / (2*(1-rho^2)) * % [((x-mu_x)/sigma_x)^2 - 2rho((x-mu_x)/sigma_x)((y-mu_y)/sigma_y) + ((y-mu_y)/sigma_y)^2]) % % where: % mu_x and mu_y are the means in the x and y directions, respectively. % sigma_x and sigma_y are the standard deviations in the x and y directions, respectively. % rho is the correlation coefficient between x and y (here, we assume rho=0 for simplicity, % making the distribution axis-aligned). % % For an axis-aligned Gaussian (rho = 0), the formula simplifies to: % % f(x, y) = (1 / (2pisigma_xsigma_y)) * exp(-((x-mu_x)^2 / (2sigma_x^2) + (y-mu_y)^2 / (2sigma_y^2)))
% Define the parameters of the 2D Gaussian distribution
mu_x = 0; % Mean in the x-direction mu_y = 0; % Mean in the y-direction sigma_x = 2; % Standard deviation in the x-direction sigma_y = 1; % Standard deviation in the y-direction
% Create a grid of x and y values
x = linspace(-5, 5, 100); y = linspace(-5, 5, 100); [X, Y] = meshgrid(x, y);