1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
X(1:2,:)=randi(2,1000);
[coefs,scores,variances,t2] = princomp([X(2,:);X(1,:)]');
%% tracer l'ellipse verte.
phi = linspace(0,2*pi,50);
cosphi = cos(phi);
sinphi = sin(phi);
xbar = sum(X(2,:))/N;
ybar = sum(X(1,:))/N;
% j'ai choisi la taille moi meme
% normalement le grand axe= la valeur propre1
%le petit axe =la valeur propre 2.
a = 90/2;
b = 20/2;
theta = acosd(coefs(1));
R = [ cos(theta) sin(theta)
-sin(theta) cos(theta)];
xy = [a*cosphi; b*sinphi];
xy = R*xy;
x = xy(1,:) + xbar;
y = xy(2,:) + ybar;
plot(x,y,'y','LineWidth',2);
hold off
drawnow |
Partager