Question
Using OCaml: The standard deviation of a set of numbers x1,,xN is a measure of their distance from the mean. A high standard deviation means
Using OCaml:
The standard deviation of a set of numbers x1,,xN is a measure of their distance from the mean. A high standard deviation means that the numbers vary from the mean while a low standard deviation means they are close to the mean. The standard deviation is computed as:
where denotes the arithmetic mean of the numbers and the expression (xi)2 means, subtract the mean from each of the numbers and square the difference. This gives N squares. We take the mean of these squares and finally take the square root of that mean.
As an example, consider the numbers [2.5; 4.5; 28.2]. The mean is roughly 11.73. Subtracting the mean from each element of the list yields the list [-9.23; -7.23; 16.47], squaring each of these numbers yields [85.19; 52.27; 271.26], the mean of these numbers is 136.24 and the square root of this mean, i.e., the standard deviation of the numbers [2.5; 4.5; 28.2] is 11.67 (roughly).
Write a function standard : float list -> float such that a call (standard ns) computes the standard deviation of the numbers in ns.
This is the code given:
This is the code used to test the function:
(* standard: float list float ) 'a 'b let standard ns= failwith "Problem 3 of part 2 isn't implemented yet." (* Test standard deviation *) float list let n1s=[1.0;2.0;3.0;4.0;5.0] float list let n2s=n1s @ [50.0;100.0] unit -> bool let standardTest1 ()= Lib. closeEnough (standard n1s) 1.41421356237309515 unit -> bool let standardTest2 () = Lib.closeEnough (standard n2s) 35.1846441458979271 unit -> unit let standardTest () = Lib. run_test "standard test1" standardTest1; Lib. run_test "standard test2" standardTest2 (* standard: float list float ) 'a 'b let standard ns= failwith "Problem 3 of part 2 isn't implemented yet." (* Test standard deviation *) float list let n1s=[1.0;2.0;3.0;4.0;5.0] float list let n2s=n1s @ [50.0;100.0] unit -> bool let standardTest1 ()= Lib. closeEnough (standard n1s) 1.41421356237309515 unit -> bool let standardTest2 () = Lib.closeEnough (standard n2s) 35.1846441458979271 unit -> unit let standardTest () = Lib. run_test "standard test1" standardTest1; Lib. run_test "standard test2" standardTest2Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started