% rangespace.m, illustration of range-space
% run this program several times - random data.
clear

% Generate a special matrix, what is special?
A=[1 0 0 ; 1 1 0 ; 0 1 0];
A(:,1)=randn(1)*A(:,1);
A(:,2)=randn(1)*A(:,2);
A(:,3)=randn(1)*A(:,1)+randn(1)*A(:,2);

% Generate 50 random vectors
x=randn(3,50);

% Exemplify the range-space of A by plotting the 'output'.
y=A*x;
figure(1), clf, hold on, axis equal, view(3)
plot3(y(1,:),y(2,:),y(3,:),'*')

% Plot a frame
n=ceil(max(max(abs(y))));
y(:,1)=[-n -2*n -n]';
y(:,2)=[-n 0 n]';
y(:,3)=[n 2*n n]';
y(:,4)=[n 0 -n]';
y(:,5)=[-n -2*n -n]';
plot3(y(1,1:5),y(2,1:5),y(3,1:5),'y')

% Plot the column vectors of A - you may need to remove the plotting of
% the 50 points to see what happens.
plot3([0 A(1,1)],[0 A(2,1)],[0 A(3,1)],'r')
plot3(A(1,1),A(2,1),A(3,1),'pr')
plot3([0 A(1,2)],[0 A(2,2)],[0 A(3,2)],'r')
plot3(A(1,2),A(2,2),A(3,2),'pr')
plot3([0 A(1,3)],[0 A(2,3)],[0 A(3,3)],'r')
plot3(A(1,3),A(2,3),A(3,3),'pr')

% try various viewpoints by specifying, for instance,
% view(-69.5,30)
% view(3) to return to default, see help view

