function [X] = BM(N,M,D);
% 04.09.2015, Matlab library for INADILIC project (C) D. S. Grebenkov
% Generates Brownian motion
%   Input:  
%     N - number of points (steps)
%     M - number of trajectories (optional, by default, M=1)
%     D - diffusion coefficient (optional, by default, D=1)
%   Output:
%     X - matrix of size MxN, X(m,:) represents the m-th trajectory

if (nargin < 2)
  M = 1; 
end

if (nargin < 3)
  D = 1;
end

X = sqrt(2*D)*cumsum( randn(N,M))';