Advertisement
makispaiktis

Tutorial - 4 Gaussian plots

Aug 11th, 2021 (edited)
1,487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.89 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % MAIN FUNCTION
  5. meanList = [0, 0, 0, -2];
  6. sigma_squared_List = [0.2, 1, 5, 1];
  7. x_min = -5;
  8. x_max = 5;
  9. N = 1001;
  10. for i = 1:length(meanList)
  11.     mean = meanList(i);
  12.     sigma_squared = sigma_squared_List(i);
  13.     [X, Y] = full_gaussian(mean, sigma_squared, x_min, x_max, N);
  14.     hold on
  15. end
  16. title('4 Gaussian functions');
  17. xlabel('x');
  18. ylabel('y = f(x | μ,σ)');
  19. legend('μ = 0, σ^2 = 0.2', 'μ = 0, σ^2 = 1', 'μ = 0, σ^2 = 5', 'μ = -2, σ^2 = 1');
  20.  
  21. % FUNCTION 1
  22. function y = my_gaussian(x, mean, sigma_squared)
  23.     y = (1/sqrt(2*pi*sigma_squared)) * exp(-(x-mean)^2 / (2*sigma_squared));
  24. end
  25.  
  26. % FUNCTION 2
  27. function [X, Y] = full_gaussian(mean, sigma_squared, x_min, x_max, N)
  28.     X = linspace(x_min, x_max, N);
  29.     Y = zeros(N, 1);
  30.     for i = 1:N
  31.         x = X(i);
  32.         y = my_gaussian(x, mean, sigma_squared);
  33.         Y(i) = y;
  34.     end
  35.     plot(X, Y);
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement