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

Given a list {Subscript[a, 1],Subscript[a, 2],..,Subscript[a, n]}, its harmonic mean is defined as 

n 2k=12 1 

. 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.

n 2k=12 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Sure Ill provide the implementation for the three functions hmean1 hmean2 and hmean3 as described in ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!