Given a list {Subscript[a, 1],Subscript[a, 2],..,Subscript[a, n]}, its harmonic mean is defined as . Now define
Question:
Given a list {Subscript[a, 1],Subscript[a, 2],..,Subscript[a, n]}, its harmonic mean is defined as
. Now define three functions hmean1, hmean2 and hmean3, all with the input as a given list and output the harmonic mean. The requirements are as follows:
1. hmean1 uses the combination of built-in Mathematica functions, and in the function you can only use Length, Total and division operator (/).
2. hmean2 uses functional programming, and in the function you can only use these elements: built-in functions of Length, Power, Times and Plus, operators of Map (/@) and Apply(@@), Pure Functions (#&), curly brackets {}, parenthesis (), and number -1.
3. hmean3 uses control flows, and you can pick Do/For/While as you like.
After defining the function, do the followings:
1. Test the correctness of all your functions with some small list, say {a,b,c,d}.
2. Compare the running times of different functions with a large list, for instance Range[10^5]. Also compare with running time the built-in Mathematica to calculate harmonic mean directly
(Hint: find function name with natural language input). Insert the text cell to write down your observations.
Elementary Statistics A step by step approach
ISBN: 978-0073386102
8th edition
Authors: Allan Bluman