Problem 2: The Harmonic Mean Given a list (a1, 92, .., an), its harmonic mean is defined as Now define three functions h
Posted: Mon Jun 06, 2022 11:00 am
Problem 2: The Harmonic Mean Given a list (a1, 92, .., an), 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 builtin 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: builtin-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.