Get-RootMeanSquare

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


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)))
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s