echo on
%%%%% ch00_vec.m %%%%%
% Run script and study the effects of each line.

echo off
disp(sprintf('**** Exercises for practicing MatLab ****'));
disp(sprintf('**** FORMATTING ****'));
echo on 		
			% The echo command controls the echoing of M-files during execution.

1.2*10^-8		% multiply 1.2 and 10^-8 and show result

a=1.2*10^-8		% define a variable and show result

a=1.2*10^-8;		% discard answer

format long		% show in 16 digits
a

format short		% show in 5 digits
a

format compact		% eliminate blank lines in output

echo off
disp(sprintf('**** VECTORS ****'))
echo on

a=[1,3,5,7]		% create a row vector of dimension 1 x 4 (1 row and 4 columns)

b=a'			% transpose row vector to column vector of dimension 4 x 1
			% (1 column and 4 rows)

r=rand(4,1)		% create n x 1 random vector

d=5.1*a			% A scalar can multiply a vector of any size.

d=d+a			% Vectors of same dimensions can be added or subtracted
			% d_ij = d_ij + a_ij for all i and j

d=d-a			% d_ij = d_ij - a_ij for all i and j

b=(1:2:7)'		% create a column vector; start 1, displacement 2 end 7

c=a*b			% Row and column vector multiplication (inner product), 
			% results in a scalar c=sum(a_i*b_j). The number of elements 
			% of a must equal the number of rows of b. 

C1=b*a			% The operation is not commutative! We get a matrix now.

e=C1(3,:)		% is the 3-th row of C1

e=C1(:,2)		% is the 2-nd column of C1

c=e.*b			% Column times column vector multiplication - array multiplication
			% is the element-by-element product of the arrays of the same 
			% size and shape (c_ij=e_ij*b_ij).
         
p=a.^2			% another variant of array multiplication

