function sines = calculateSines(x, amplitudes, frequencies)
  % Function calculates sinewaves with all combinations of 
  % given amplitudes and frequencies.
  % Arguments:   x, a vector of radiants for which the sine should be
  %              computed.
  %              amplitudes, a vector of amplitudes.
  %              frequencies, a vector of frequencies.
  %
  % Returns:     a 3-D Matrix of sinewaves, 2nd dimension represents
  %              the amplitudes, 3rd the frequencies.
  
  sines = zeros(length(x), length(amplitudes), length(frequencies));

  for i = 1:length(amplitudes)
    sines(:,i,:) = sinesWithFrequencies(x, amplitudes(i), frequencies); 
  end
end


function sines = sinesWithFrequencies(x, amplitude, frequencies)
  sines = zeros(length(x), length(frequencies));
  for i = 1:length(frequencies)
    sines(:,i) = sinewave(x, amplitude, frequencies(i));
  end
end


function sine = sinewave(x, amplitude, frequency)
    sine = sin(2 .* pi .* x *frequency) .* amplitude; 
end
