一.实验题目
二.算法分析
代码:
load('data.mat')
x=p;
disp(x);
u1=mean(x);
disp(u1);
a=size(x,2);
y=zeros(size(x));
for i=1:size(x,2)
y(i)=(x(i)-u1)^2;
end
disp(y);
u2=mean(y);
disp(u2);
load('data2.mat')
[m n]=size(p); %m行,n列
x=size(2,n);
for i=1:n
x(1,i)= p(1,i);
x(2,i)= p(2,i);
end
%disp(x);
u1=mean(x,2);
disp(u1);
y=zeros(size(x));
for j=1:2
for i=1:size(x,2)
y(j,i)=(x(j,i)-u1(j))^2;
end
end
%disp(y);
u2=mean(y,2);
disp(u2);
for i=1:n
x(1,i)= p(1,i);
x(2,i)= p(3,i);
end
%disp(x);
u1=mean(x,2);
disp(u1);
y=zeros(size(x));
for j=1:2
for i=1:size(x,2)
y(j,i)=(x(j,i)-u1(j))^2;
end
end
%disp(y);
u2=mean(y,2);
disp(u2);
for i=1:n
x(1,i)= p(2,i);
x(2,i)= p(3,i);
end
%disp(x);
u1=mean(x,2);
disp(u1);
y=zeros(size(x));
for j=1:2
for i=1:size(x,2)
y(j,i)=(x(j,i)-u1(j))^2;
end
end
%disp(y);
u2=mean(y,2);
disp(u2);
load('data2.mat')
%[m n]=size(p); %m行,n列
x=p;
disp(x);
u1=mean(x,2);
disp(u1);
y=zeros(size(x));
for j=1:3
for i=1:size(x,2)
y(j,i)=(x(j,i)-u1(j))^2;
end
end
disp(y);
u2=mean(y,2);
disp(u2);
load('data3.mat')
syms u1 u2 u3;
f=0; g=0; q=0;
[m n]=size(p); %m行,n列
x1=zeros(m,1);
x2=zeros(m,1);
x3=zeros(m,1);
for i=1:m
x1(i,1)= p(i,1);
x2(i,1)= p(i,2);
x3(i,1)= p(i,3);
end %disp(x1);%disp(x2);%disp(x3);
for i=1:m
for j=1:m
f=f+(x1(i,1)-u1)*(x2(j,1)-u2);
g=g+(x1(i,1)-u1)*(x3(j,1)-u3);
q=q+(x2(i,1)-u2)*(x3(j,1)-u3);
end
end
[u1,u2,u3]=solve(f,g,q,u1,u2,u3);
disp(u1);
disp(u2);
disp(u3);
for i=1:m
y1(i)=(x1(i,1)--0.1126)^2;
y2(i)=(x2(i,1)-0.4299)^2;
y3(i)=(x3(i,1)-0.0037)^2;
end
%disp(y1);
%disp(y2);
%disp(y3);
v1=mean(y1);
v2=mean(y2);
v3=mean(y3);
disp(v1);
disp(v2);
disp(v3);