Averages/Mean angle: Difference between revisions

no edit summary
(added Scheme example)
No edit summary
Line 1,552:
IBM0683I ONCODE=1521 X or Y in ATAN(X,Y) or ATAND(X,Y) was invalid.
At offset +000009CC in procedure with entry AVERAGES
</pre>
 
=={{header|PowerShell}}==
<lang PowerShell>
function Get-MeanAngle ([double[]]$Angles)
{
$x = ($Angles | ForEach-Object {[Math]::Cos($_ * [Math]::PI / 180)} | Measure-Object -Average).Average
$y = ($Angles | ForEach-Object {[Math]::Sin($_ * [Math]::PI / 180)} | Measure-Object -Average).Average
 
[Math]::Atan2($y, $x) * 180 / [Math]::PI
}
</lang>
 
<lang PowerShell>
@(350, 10), @(90, 180, 270, 360), @(10, 20, 30) | ForEach-Object {Get-MeanAngle $_}
</lang>
 
{{Out}}
<pre>
-2.74517688449847E-14
-90
20
</pre>
 
308

edits