function max_val = array_max(array)
% 
% Find the maximum value in an array of numbers.
% 
% Arguments:
% 
%       array           (input)   1-D array of numbers
%
%       max_val         (output)  the maximum value
% 

  % Check the dimensions of the 'array' argument.
  %   We expect a simple 1-D array of numbers, in which case
  %      num_rows     should be 1
  %      num_cols     will be the number of values in the array
  %
  % If the given 'array' isn't a simple 1-D array, print an error
  %   message and quit.
  [num_rows, num_cols] = size(array);
  if (num_rows ~= 1) 
    error('array_max: array must be one-dimensional');
  end

  % Loop through the array to find the smallest element
  largest_so_far = array(1);
  for index = 2 : num_cols
    if (array(index) > largest_so_far) 
      largest_so_far = array(index);
    end
  end

  max_val = largest_so_far;

