back

Solution to exercise 3.1.2

In order to normalize a vector we have to calculate its length. It can be using the function norm(). <sxh c>

  function y = normalize(x)
     L = norm(x);
     y = x/L; 
  endfunction

</sxh>

Variables x and y are vector variables. Please note how vector and scalar operands are handled for division operator on line 3.