%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Brownian Motion Simulator
%
%  This code simulates n trials of standard Brownian motion over
%  the interval [0,T]. The code then plots the realizations of the
%  Brownian motion on the real axis.
%
%  Inputs:
%  1. n=number of realization to plot
%  2. T=maximum time
%  3. N=number of points to take
%
%  Ouputs:
%   1. Plot of the realizations of the Brownian motion.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Inputs
n=20;
T=1;
N=1000;

%% Construction of Discretization
t=linspace(0,T,N);
dt=t(2)-t(1);

B=zeros(1,N);

%% Initilizing Plot
figure('units','normalized','outerposition',[0 0 1 1]);
hold on;
xlabel('$$t$$','interpreter','latex')
ylabel('$$B_t$$','interpreter','latex')
ax=gca;
ax.FontSize = 40;
for j=1:n
    for i=1:N-1
        B(i+1)=B(i)+sqrt(dt)*randn;
    end
    plot(t,B,'linewidth',2);
end


