% A demo program for drawing 3D vector subspaces spanned by any 3 given
% vector in R^3. To show a subspace spanned by two linearly independent
% vectors, enter one of the 3 inputs to be a zero vector.

% Prepared by Ben M. Chen, 1 August 2000

clc
clf
disp(' ')
disp(' ')
disp(' ')
disp(' ')
disp('    Demonstration on vector subspaces spanned by a set of vectors')
disp(' ')
disp(' ')
disp('    Enter three 3D vectors:')
disp(' ')
disp(' ')
v1=input('    Enter the 1st vector v1 = ');
plot3([0 v1(1)],[0 v1(2)],[0 v1(3)],'r')
axis([-10 10 -10 10 -10 10]); grid
hold;
xlabel('x')
ylabel('y')
zlabel('z')
disp(' ')
v2=input('    Enter the 2nd vector v2 = ');
plot3([0 v2(1)],[0 v2(2)],[0 v2(3)],'r')
disp(' ')
disp(' ')
v3=input('    Enter the 3rd vector v3 = ');
plot3([0 v3(1)],[0 v3(2)],[0 v3(3)],'r')
pause
for i=1:2000;
    c1=(rand-0.5)*20;
    c2=(rand-0.5)*20;
    c3=(rand-0.5)*20;
    v=c1*v1+c2*v2+c3*v3;
    clc
    disp(' ')
    disp(' ')
    disp('Calculate v = c1 * v1 + c2 * v2 + c3 * v3 with [ c1 c2 c3 ] =')
    disp(' ')
    c1c2c3=[c1 c2 c3]
    disp(' ')
    disp('These give a new vector ')
    disp(' ')
    v
    a=max(abs(v));
    v=v/a*10;
    plot3([0 v(1)],[0 v(2)],[0 v(3)],'b')
    if i/500==round(i/500); pause; end
    pause
end

% - T - H - E - - - E - N - D - - - - - - - - - - - - - - - - - - - - -
