Averages/Simple moving average: Difference between revisions
Content added Content deleted
(Added Oz.) |
(Mathematica) |
||
Line 666: | Line 666: | ||
print_newline (); |
print_newline (); |
||
) periodLst</lang> |
) periodLst</lang> |
||
=={{header|Mathematica}}== |
|||
This version uses a list entry so it can use the built-in function. |
|||
<lang Mathematica>MA[x_List, r_] := Join[Table[Mean[x[[1;;y]]],{y,r-1}], MovingAverage[x,r]]</lang> |
|||
This version is stateful instead. |
|||
<lang Mathematica>MAData = {{}, 0}; |
|||
MAS[x_, t_: Null] := |
|||
With[{r = If[t === Null, MAData[[2]], t]}, |
|||
Mean[MAData[[1]] = |
|||
If[Length[#] > (MAData[[2]] = r), #[[-r ;; -1]], #] &@ |
|||
Append[MAData[[1]], x]]]</lang> |
|||
=={{header|Oz}}== |
=={{header|Oz}}== |