Averages/Root mean square: Difference between revisions

jq
(added Elixir)
(jq)
Line 560:
print( root_mean_square([1,2,3,4,5,6,7,8,9,10]) ); // ==> 6.2048368229954285</lang>
 
=={{header|jq}}==
The following filter returns ''null'' if given an empty array:
<lang jq>def rms: length as $length
| if $length == 0 then null
else map(. * .) | add | sqrt / $length
end ;</lang>With this definition, the following program would compute the rms of each array in a file or stream of numeric arrays:<lang jq>rms</lang>
=={{header|Julia}}==
There are a variety of ways to do this via built-in functions in Julia, given an array <code>A = [1:10]</code> of values. The formula can be implemented directly as:
Line 575 ⟶ 581:
</lang>
Potentially even better is to use the built-in <code>norm</code> function, which computes the square root of the sum of the squares of the entries of <code>A</code> in a way that avoids the possibility of spurious floating-point overflow (if the entries of <code>A</code> are so large that they may overflow if squared): <lang julia>norm(A) / sqrt(length(A))</lang>
 
 
=={{header|Lasso}}==
2,469

edits