% % GAUSSIAN - calculates the probability density for an outcome % given gaussian/normal distribution % % function desnsity = gaussian(x, ev, sd) % % return density: the distribution density in the elements of x % param x: x is a scalar or a row vector of outcomes % param ev: expected value of gaussian distribution % param sd: standard deviation of gaussian distribution % % AUTHOR Ronnie Johansson % CREATED 2004-02-11 % ALTERED
0001 %% 0002 %% GAUSSIAN - calculates the probability density for an outcome 0003 %% given gaussian/normal distribution 0004 %% 0005 %% function desnsity = gaussian(x, ev, sd) 0006 %% 0007 %% return density: the distribution density in the elements of x 0008 %% param x: x is a scalar or a row vector of outcomes 0009 %% param ev: expected value of gaussian distribution 0010 %% param sd: standard deviation of gaussian distribution 0011 %% 0012 %% AUTHOR Ronnie Johansson 0013 %% CREATED 2004-02-11 0014 %% ALTERED 0015 0016 0017 function density = gaussian(x, ev, sd) 0018 [row, no_of_x] = size(x); 0019 % row should be equal to one 0020 0021 density = []; 0022 for i=1:no_of_x % calculate gaussian density for each element in x 0023 density = [density ... 0024 1/(sd * sqrt(2*pi)) * exp( -(x(i) - ev)^2/(2 * sd^2) )]; 0025 end