Change of basis, rotating an ellipse
Show older comments
I though I knew how to do this, apperently i did not. I'm supposted to draw a confidence ellips aroud a cluster of data centered aroud the mean of said cluster. I've figured how to draw the ellipse, now i need to rotate it. I would like to change the basis that I'm working with so that the mean of the cluster becomes my new basis, I'm thinking that would solve the rotational issue? Can anyone help?
data=[191 197 208 180 180 188 210 196 191 179 202 200 192 199 186 197 201 190 209 187 207 178 202 ...
205 190 189 211 216 189 173 194 198 180 190 191 196 207 209 179 186 174 181 189 189;
284 285 273 275 280 283 288 271 257 289 285 272 282 280 266 285 295 282 305 285 297 268 271 285 ...
280 277 310 305 274 271 280 300 272 292 286 285 286 303 261 262 245 250 262 258]';
x=mean(data)'; %% Mean, and what I would like my new basis to be
S=cov(data); lambda=svd(S); n=length(data); p=size(data,2); F=3.21;
major=2*sqrt(lambda(1))*sqrt(p*(n-1)*F/(n*(n-p))); %% Major axis
minor=2*sqrt(lambda(2))*sqrt(p*(n-1)*F/(n*(n-p))); %% Minor axis
th=linspace(0,2*pi);
X=[x(1)+major*cos(th); x(2)+minor*sin(th)];
angle=atan(x(1)/x(2)); %% rotational angle
R=[cos(angle) -sin(angle); sin(angle) cos(angle)]; %% Rotational matrix, should i muliply with new basis from left?
CE1=X; CE1=CE1'; %% Ellipse (blue), not rotated
CE2=R*X; CE2=CE2'; %% Ellipse (red), rotated, but not in a correct way
figure()
hold on
plot(CE1(:,1),CE1(:,2)), %axis equal
plot(CE2(:,1),CE2(:,2))
plot(data(:,1),data(:,2),'bo')

Accepted Answer
More Answers (0)
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
