Advertisement
makispaiktis

Tutorial Thomas - Gaussian Distributions

Jul 24th, 2021 (edited)
1,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.72 KB | None | 0 0
  1. clc
  2. clear all
  3.  
  4. % Main Function
  5. N = 1001;
  6. spots = 20;         % In histogram
  7. x = linspace(0, 10, N);
  8. times = [2, 5, 10, 20, 30, 50];
  9. counter = 0;
  10. for i = 1:length(times)
  11.     counter = counter + 1;
  12.     time = times(i);
  13.     y = produce(N, time);
  14.     subplot(3,2, counter);
  15.     hist(y, spots);
  16.     titleInPlot = strcat('Sum of: ', num2str(time), '  Gaussian distributions');
  17.     title(titleInPlot);
  18. end
  19.  
  20. % Auxiliary Function
  21. function y = produce(N, time)
  22.     y = [];
  23.     counter = 0;
  24.     for i = 1:N
  25.         counter = counter + 1;
  26.         value = 0;
  27.         for j = 1:time
  28.             value = value + randn();   % I add a sample with average = 0, std = 1
  29.         end
  30.         y(counter) = value;
  31.     end
  32.     y;
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement