Ever needed to get the Root Mean Square of a set before? Me neither, but I went ahead and created a small function for it anyway.
Enjoy. 🙂
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-Square { | |
param([double]$Number) | |
$n = [math]::Abs($Number) | |
Write-Output ($n * $n) | |
} | |
#https://en.wikipedia.org/wiki/Root_mean_square | |
function Get-RootMeanSquare { | |
param ([double[]]$NumberSet) | |
$squaredNumberSet = New-Object System.Collections.ArrayList | |
foreach ($number in $NumberSet) { | |
[void]$squaredNumberSet.Add((Get-Square $number)) | |
} | |
Write-Output ([math]::Sqrt((($squaredNumberSet | Measure-Object –Average).Average))) | |
} |