#C13881. Exponential Moving Average Computation
Exponential Moving Average Computation
Exponential Moving Average Computation
You are given a series of numbers and a span. Your task is to compute the Exponential Moving Average (EMA) of the series using the formula:
\(EMA_0 = x_0\) and \(EMA_i = \alpha \cdot x_i + (1-\alpha) \cdot EMA_{i-1}\) for \(i \ge 1\), where \(\alpha = \frac{2}{span + 1}\).
Round each value to 7 decimal places and output the results in a single line separated by spaces.
The input is provided via standard input and the output must be written to standard output.
inputFormat
The first line contains an integer n
representing the number of elements in the series.
The second line contains n
real numbers separated by spaces.
The third line contains an integer span
used in the EMA calculation.
outputFormat
Output one line containing n
numbers which are the EMA values of the series. Each number should be rounded to 7 decimal places and separated by a single space.
10
1 2 3 4 5 6 7 8 9 10
2
1.0000000 1.6666667 2.5555556 3.5185185 4.5061728 5.5020577 6.5006862 7.5002287 8.5000762 9.5000254