Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all
- % MAIN FUNCTION
- meanList = [0, 0, 0, -2];
- sigma_squared_List = [0.2, 1, 5, 1];
- x_min = -5;
- x_max = 5;
- N = 1001;
- for i = 1:length(meanList)
- mean = meanList(i);
- sigma_squared = sigma_squared_List(i);
- [X, Y] = full_gaussian(mean, sigma_squared, x_min, x_max, N);
- hold on
- end
- title('4 Gaussian functions');
- xlabel('x');
- ylabel('y = f(x | μ,σ)');
- legend('μ = 0, σ^2 = 0.2', 'μ = 0, σ^2 = 1', 'μ = 0, σ^2 = 5', 'μ = -2, σ^2 = 1');
- % FUNCTION 1
- function y = my_gaussian(x, mean, sigma_squared)
- y = (1/sqrt(2*pi*sigma_squared)) * exp(-(x-mean)^2 / (2*sigma_squared));
- end
- % FUNCTION 2
- function [X, Y] = full_gaussian(mean, sigma_squared, x_min, x_max, N)
- X = linspace(x_min, x_max, N);
- Y = zeros(N, 1);
- for i = 1:N
- x = X(i);
- y = my_gaussian(x, mean, sigma_squared);
- Y(i) = y;
- end
- plot(X, Y);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement