%
%                   |-------------------------------|
%                   |  Author: James C. Sutherland  |
%                   |           CHEN 1703           |
%                   |-------------------------------|
%
% This file illustrates dot products and elemental multiplication of two
% vectors.  The purpose is to demonstrate how you would implement these
% using loops, and how you use logic to control the flow of the program.
%

clear;
clc;

% create two vectors: a and b.
a = [1 5 3];
b = [2 4 6];

n = length(a);

% check to see if arrays are compatible.
if( n ~= length(b) )
   error('incompatible vectors.');
end

% set option:  1->dot 2->elemental
option = input('Select 1 for dot product; 2 for elemental multiplication');

if( option==1 )  % dot product
   c = 0;
   for( i=1:n )
      c = c + a(i)*b(i);
   end
   disp('dot product:');
   disp(c);

elseif( option == 2 ) % ELEMENTAL Multiplication
   c = zeros(n,1);
   for( i=1:n )
      c(i) = a(i)*b(i);
   end
   disp('elemental product');
   disp(c);
else
   error('bad choice - try again.')
end