Combining histograms and function plots

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Combining histograms and function plots

Sérgio Galdino
This post was updated on .
function y=rgauss()
  r2=2;
  while  r2 > 1
    v1=-1+2*rand();
    v2=-1+2*rand();
    r2=v1*v1+v2*v2;
  end
  % y=v1*sqrt(-2*log(r2)/r2);
  y=v2*sqrt(-2*log(r2)/r2);
endfunction
for i=1:100000
  Y(i)=rgauss();
endfor
hold on
hist(Y,50,'Color', "facecolor", "r", "edgecolor", "r")
[nn,xx]=hist(Y,50)
z=exp(-xx.^2/2)/sqrt(2*pi);
plot(xx,z*max(nn)/max(z),'LineWidth', 2, 'Color', 'b')
xlabel('Version'); ylabel('Left Y-Axis');
hold off

<http://octave.1599824.n4.nabble.com/file/t373155/Captura_de_Tela_2019-01-05_a%CC%80s_09.png



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html