Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

% Parameters for Gaussian distribution

mean_vector = [2, 1];


covariance_matrix = eye(2);

% Generate grid points for plotting


[x_grid, y_grid] = meshgrid(linspace(-1, 5, 100), linspace(-2, 4, 100));

% Create 2D Gaussian distribution using mvnpdf


pdf_values = mvnpdf([x_grid(:), y_grid(:)], mean_vector, covariance_matrix);
pdf_values = reshape(pdf_values, size(x_grid));

% Plot the 2D surface plot


figure;
subplot(1, 2, 1);
surf(x_grid, y_grid, pdf_values, 'EdgeColor', 'none');
title('Surface Plot');
xlabel('X');
ylabel('Y');
zlabel('PDF');

% Generate contour plot


subplot(1, 2, 2);
contour(x_grid, y_grid, pdf_values, 20, 'LineWidth', 1.5);
title('Contour Plot');
xlabel('X');
ylabel('Y');
colorbar;
set(gcf, 'position', [350, 200, 900, 400]);

You might also like