% MATLAB script: vector operations in MATLAB
v = [1;2;3;4;5], % Initialize a column vector with five components
alpha = 0.5; alpha*v, % \textbf{Scalar multiplication}
w = [v(1:2:end);-v(2:2:end)], % Build another vector from $\Vv$. 
u = v + w; % \textbf{Addition} of vectors
z = alpha*v + (1-alpha)*w, % Scalar multiplication and vector addition

% Many MALAB functions can be applied to a vector and the result is the
% vector, whose components give the function evaluated for the components
% of the input vector
s = arrayfun(@(x) sin(x),v), % Compute $[\sin(1);\sin(2);\ldots;\sin(5)]$
s = sin(v), % the same for elementary mathematical functions
m = abs(w), % take the modulus of each component

sp = dot(v,w), % \textbf{Scalar product} 
cp = cross([1;2;3],[4;5;6]); % \textbf{vector product} = cross product
dot(cp,[1;2;3]), dot(cp,[4;5;6]),

% \textbf{Componentwise} operations, preceded by a dot:
p = v.*w, % p(k) = v(k)*w(k)
p = v./w, % p(k) = v(k)/w(k)
p = v.^w, % p(k) = v(k)\symbol{94}w(k): taking the \textbf{power} (ger.: Potenz)

% Special functions that operate on vectors
mx = max(w) % Maximum of components
mn = min(w) % Minimum of components
