Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

function [z]=comp_gauss_dens_val(m,S,x)

FUNCTION
[z]=comp_gauss_dens_val(m,S,x)
INPUT ARGUMENTS:
m: l-dimensional column vector corresponding to the mean vector of the
gaussian distribution.
S: lxl matrix that corresponds to the covariance matrix of the
gaussian distribution.
x: l-dimensional column vector where the value of the gaussian
distribution will be evaluated.
OUTPUT ARGUMENTS:
z: the value of the gaussian distribution at x.
[l,c]=size(m);
z=(1/( (2*pi)^(l/2)*det(S)^0.5) )*exp(-0.5*(x-m)'*inv(S)*(x-m));
Example 1.3.1
close('all');
clear;
m=[0 1]'; S=eye(2);
x1=[0.2 1.3]'; x2=[2.2 -1.3]';
pg1=comp_gauss_dens_val(m,S,x1)
pg2=comp_gauss_dens_val(m,S,x2)
Hasil :
pg1 =
0.1491
pg2 =
0.0010
Analisis :

Example 1.3.2
close('all');
clear;
P1=0.5;
P2=0.5;
m1=[1 1]';
m2=[3 3]';
S=eye(2);
x=[1.8 1.8]';
p1=P1*comp_gauss_dens_val(m1,S,x)
p2=P2*comp_gauss_dens_val(m2,S,x)
Hasil :
p1 =
0.0420
p2 =
0.0189
Analisis :

Example 1.3.2
close('all');
clear;
% Utilize function comp_gauss_dens_val
P1=0.1;
P2=0.8;
m1=[1 1]';
m2=[3 3]';
S=eye(2);
x=[1.8 1.8]';
p1=P1*comp_gauss_dens_val(m1,S,x)
p2=P2*comp_gauss_dens_val(m2,S,x)
Hasil :
p1 =
0.0084
p2 =
0.0302
Analisis :

Example 1.3.3
% Note: This example generates a total of eight figures.
close('all');
clear;
% Generate the first dataset (case #1)
randn('seed',0);
m=[0 0]';
S=[1 0;0 1];
N=500;
X = mvnrnd(m,S,N)';
% Plot the first dataset
figure(1), plot(X(1,:),X(2,:),'.');
figure(1), axis equal
figure(1), axis([-7 7 -7 7])
% Generate and plot the second dataset (case #2)
m=[0 0]';
S=[0.2 0;0 0.2];
N=500;
X = mvnrnd(m,S,N)';
figure(2), plot(X(1,:),X(2,:),'.');
figure(2), axis equal
figure(2), axis([-7 7 -7 7])
% Generate and plot the third dataset (case #3)
m=[0 0]';
S=[2 0;0 2];
N=500;
X = mvnrnd(m,S,N)';
figure(3), plot(X(1,:),X(2,:),'.');
figure(3), axis equal
figure(3), axis([-7 7 -7 7])
% Generate and plot the fourth dataset (case #4)
m=[0 0]';
S=[0.2 0;0 2];
N=500;
X = mvnrnd(m,S,N)';
figure(4), plot(X(1,:),X(2,:),'.');
figure(4), axis equal
figure(4), axis([-7 7 -7 7])
% Generate and plot the fifth dataset (case #5)
m=[0 0]';

S=[2 0;0 0.2];


N=500;
X = mvnrnd(m,S,N)';
figure(5), plot(X(1,:),X(2,:),'.');
figure(5), axis equal
figure(5), axis([-7 7 -7 7])
% Generate and plot the sixth dataset (case #6)
m=[0 0]';
S=[1 0.5;0.5 1];
N=500;
X = mvnrnd(m,S,N)';
figure(6), plot(X(1,:),X(2,:),'.');
figure(6), axis equal
figure(6), axis([-7 7 -7 7])
% Generate and plot the seventh dataset (case #7)
m=[0 0]';
S=[.3 0.5;0.5 2];
N=500;
X = mvnrnd(m,S,N)';
figure(7), plot(X(1,:),X(2,:),'.');
figure(7), axis equal
figure(7), axis([-7 7 -7 7])
% Generate and plot the eighth dataset (case #8)
m=[0 0]';
S=[.3 -0.5;-0.5 2];
N=500;
X = mvnrnd(m,S,N)';
figure(8), plot(X(1,:),X(2,:),'.');
figure(8), axis equal
figure(8), axis([-7 7 -7 7])

You might also like