1 clear all;
2 close all;
3 clc;
4
5 randn('seed',0);
6 mu1=[0 0];
7 S1=[0.3 0;0 0.35];
8 cls1_data=mvnrnd(mu1,S1,1000);
9 plot(cls1_data(:,1),cls1_data(:,2),'+');
10 hold on;
11
12 mu2=[4 0];
13 S2=[1.2 0;0 1.85];
14 cls2_data=mvnrnd(mu2,S2,1000);
15 plot(cls2_data(:,1),cls2_data(:,2),'r+');
16 axis([-8 8 -8 8]);
17
18 for i=-4:0.1:8
19 for j=-6:0.1:6
20 d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
21 d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
22 d=d1-d2;
23 if d<0.1
24 plot(i,j);
25 end
26
27 end
28 end
29 grid on;
30
31 figure;
32 mu1=[0 0];
33 S1=[0.1 0;0 0.75];
34 cls1_data=mvnrnd(mu1,S1,1000);
35 plot(cls1_data(:,1),cls1_data(:,2),'+');
36 hold on;
37
38 mu2=[3.2 0];
39 S2=[0.75 0;0 0.1];
40 cls2_data=mvnrnd(mu2,S2,1000);
41 plot(cls2_data(:,1),cls2_data(:,2),'r+');
42 axis([-8 8 -8 8]);
43
44 for i=-8:0.1:8
45 for j=-8:0.1:8
46 d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
47 d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
48 d=d1-d2;
49 if d<0.1
50 plot(i,j);
51 end
52
53 end
54 end
55 grid on;
56
57 figure;
58 mu1=[0 3];
59 S1=[0.3 0;0 0.35];
60 cls1_data=mvnrnd(mu1,S1,1000);
61 plot(cls1_data(:,1),cls1_data(:,2),'+');
62 hold on;
63
64 mu2=[4 0];
65 S2=[0.3 0;0 0.35];
66 cls2_data=mvnrnd(mu2,S2,1000);
67 plot(cls2_data(:,1),cls2_data(:,2),'r+');
68
69 axis([-8 8 -8 8]);
70
71 for i=-8:0.1:8
72 for j=-8:0.1:8
73 d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
74 d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
75 d=d1-d2;
76 if d<0.1
77 plot(i,j);
78 end
79
80 end
81 end
82 grid on;
83
84 figure;
85 mu1=[0 -3];
86 S1=[0.5 1;1 2.5];
87 cls1_data=mvnrnd(mu1,S1,1000);
88 plot(cls1_data(:,1),cls1_data(:,2),'+');
89 hold on;
90
91 mu2=[4 0];
92 S2=[0.5 1;1 2.5];
93 cls2_data=mvnrnd(mu2,S2,1000);
94 plot(cls2_data(:,1),cls2_data(:,2),'r+');
95
96 axis([-8 8 -8 8]);
97
98 for i=-8:0.1:8
99 for j=-8:0.1:8
100 d1=([i,j]-mu1)*inv(S1)*([i,j]-mu1)';
101 d2=([i,j]-mu2)*inv(S2)*([i,j]-mu2)';
102 d=d1-d2;
103 if d<0.1
104 plot(i,j);
105 end
106
107 end
108 end
109 grid on;
图片福利: