This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/linearalgebra/code/covarmatrix.m

29 lines
470 B
Matlab

% covariance in 2D:
x = 2.0*randn(1000, 1);
y = 0.5*x + 0.2*randn(1000, 1);
scatter(x, y)
var(x)
var(y)
cov( [x, y] )
pause(1.0)
% covariance of independent coordinates in 2D:
x = 2.0*randn(1000, 1);
y = 0.5*randn(1000, 1);
scatter(x, y)
var(x)
var(y)
cov( [x, y] )
pause(1.0)
% covariance in 3D:
x = 2.0*randn(1000, 1);
y = -0.5*x + 0.2*randn(1000, 1);
z = 2.0*x + 0.6*y + 2.0*randn(1000, 1);
scatter3(x, y, z, 'filled')
var(x)
var(y)
var(z)
cov( [x, y, z] )
pause()