简单应用
clc;close all;clear all;
x=[2 2 2 4 5 6;
1 2 3 3 3 4];
plot(x(1,:),x(2,:),‘o‘)
axis([0 7 0 5])
hold on
xmean=mean(x,2);
for i=1:2
x(i,:)=x(i,:)-xmean(i);
end
sigma=x*x‘;
[a b]=svd(sigma);
v=a(1,:)‘;
w=[-v(2) v(1)]‘
x1=0:0.1:7;
b=-(w(1)*xmean(1)+w(2)*xmean(2));
y=-b-w(1)*x1;
y=y/w(2);
plot(x1,y,‘-‘)
hold on
p=x‘*v;
r=v*p‘;
for i=1:2
r(i,:)=r(i,:)+xmean(i);
end
plot(r(1,:),r(2,:),‘*‘)
hold on
plot(mean(1),mean(2),‘.‘)
时间: 2024-12-28 12:05:25