% esempi_random.m clear; clc; close all %{ prompt='Enter N: number of samples'; dlgtitle='Input'; definput={'500'}; dims=1; answer=inputdlg(prompt,dlgtitle,dims,definput); N=str2double(cell2mat(answer)); %} N=1000; %% v_rand=rand(N,1); v_randn=randn(N,1); %% figure P=get(gcf,'Position'); P(3)=2*P(3); set(gcf,'Position',P) subplot(1,2,1); histogram(v_rand) title([num2str(N) ' samples with rand(N,1) (Uniform Distribution)']) subplot(1,2,2); histogram(v_randn) title([num2str(N) ' samples with randn(N,1) (Normal Distribution)']) x=linspace(-4,4,201)'; figure P=get(gcf,'Position'); P(3)=2*P(3); set(gcf,'Position',P) y=pdf('Uniform',x,0,1); subplot(1,2,1); plot(x,y); title('Uniform Distribution in [0, 1]') y=pdf('Normal',x,0,1); subplot(1,2,2); plot(x,y); title('Normal Distribution with mean \mu=0, variance \sigma=1') %% fprintf('\nmin(v_rand), max(v_rand) =\n'); disp([min(v_rand), max(v_rand)]) fprintf('\nmin(v_randn), max(v_randn) =\n'); disp([min(v_randn), max(v_randn)]) %% Come generare i numeri random in un intervallo [a, b]?