function montecarlo()
% Example Monte Carlo Simulation in Matlab
% Function: y = x2^2/x1
%
clear all;
close all;
clc;

n = 100000;	% The number of function evaluations

%   Generate n samples from a normal distribution
      ri = ( randn(n,1) * 1 ) + 0.1;
      ra = ( randn(n,1) * 2 ) + 0.25;
      
%     r = ( randn(n,1) * sd ) + mu
%     mu : mean
%     sd : standard deviation
%
%   Generate n samples from a uniform distribution
%    r = 10 + rand(n,1) * (11-10);
%    r = a + rand(n,1) * (b-a)
%    a : 0; %minimum
%    b : 1; %maximum



% --- Generate vectors of random inputs
% x1 ~ Normal distribution N(mean=10,sd=0.03)
% x2 ~ Uniform distribution U(a=10,b=0.03)

% x1 = ( randn(n,1) * 0.03 ) + 10;
% x2 = rand(n,1).*rand(n,2) + rand(n,1) * ( 10 - 0.03 );

%x1 = ( randn(n,1) * 0.03 ) + 10;    %entspricht Ri
%x2 =   rand(n,1) * ( 10 - 0.03 ); %entspricht Ra

% --- Run the simulation
% Note the use of element-wise multiplication

y = (ra-ri);

% --- Create a histogram & other plots
figure(1)
subplot(2,1,1)
hist(ra,1000);
xlabel('Wert');
ylabel('Anzahl');

grid on;
subplot(2,1,2)
hist(ri,1000);
xlabel('Wert');
ylabel('Anzahl');

grid on;

figure(2)
plot(ri,ra,'k+');

grid on;
xlabel('ri');
ylabel('ra');

figure(3)
plot(y,'ko')

% --- Calculate summary statistics
y_mean = mean(y)
y_std = std(y)
y_median = median(y)

ra_mean = mean(ra)
ra_std = std(ra)
ra_median = median(ra)

ri_mean = mean(ri)
ri_std = std(ri)
ri_median = median(ri)