Averages/Simple moving average: Difference between revisions

(→‎{{header|NetRexx}}: Correct typo)
Line 906:
 
Erlang has closures, but immutable variables. A solution then is to use processes and a simple message passing based API.
 
=={{header|Euler Math Toolbox}}==
 
Matrix languages have routines to compute the gliding avarages for a given sequence of items.
 
<lang Euler Math Toolbox>
>n=1000; m=100; x=random(1,n);
>x10=fold(x,ones(1,m)/m);
>x10=fftfold(x,ones(1,m)/m)[m:n]; // more efficient
</lang>
 
It is less efficient to loop as in the following commands.
 
<lang Euler Math Toolbox>
>function store (x:number, v:vector, n:index) ...
$if cols(v)<n then return v|x;
$else
$ v=rotleft(v); v[-1]=x;
$ return v;
$endif;
$endfunction
>v=zeros(1,0); for k=1:20; v=store(k,v,10); mean(v), end;
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6.5
7.5
8.5
9.5
10.5
11.5
12.5
13.5
14.5
15.5
>v
[ 11 12 13 14 15 16 17 18 19 20 ]
</lang>
 
=={{header|F_Sharp|F#}}==
Anonymous user