Skip to content

Instantly share code, notes, and snippets.

@ozymandium
Created July 29, 2014 07:21
Show Gist options
  • Save ozymandium/b3e59dda97d7c9119418 to your computer and use it in GitHub Desktop.
Save ozymandium/b3e59dda97d7c9119418 to your computer and use it in GitHub Desktop.
clear all; close all; clc
x = randn(2,3);
PN = cov(x'); % covariance in the navigation frame
error_ellipse(PN,'style','b');
axis equal;
hold on;
grid on;
stdx = sqrt(PN(1,1));
stdy = sqrt(PN(2,2));
%rho = PN(1,2) / (stdx*stdy)
[E,D] = eig(PN);
alpha_x = atan2(E(2,2),E(1,2))
alpha_y = atan2(E(2,1),E(1,1))
Cx = rot2z(-alpha_x);
Cy = rot2z(-alpha_y);
PPx = Cx*PN*Cx';
PPy = Cy*PN*Cy';
error_ellipse(PPx,'style','g')
error_ellipse(PPy,'style','r')
legend('original','rotated x','rotated y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment