Moving Average
Plot a moving average graph which helps to understand how the results change over a specified period. The progress of sales and amounts of consumption and production can also be seen.
Calculation
Hi = | + ... + Xi + ... |
| ||||
| M |
|
|
| ||
|
|
|
|
|
| |
( I = 1 + | , 2 + | , ... , n + | ||||
|
| 2 | 2 |
| 2 |
Hi : moving average
M: number of divisions Xi : data
n : number of data
FLOWCHART |
| PROGRAMME LIST |
| Title : MVIN AVG |
Start
MAIN
Label MAIN
Print "Input DIVISION
Entry of number of divisions
Y
M>=n
N
Setting of calculation range
Calculation
Gosub count
Enter unit for calculating average.
Returns to entry of no. of divisions if the number of divisions more than no. of data.
Range for graph set.
I = 0, K = int (M/2)
First calculation. Jumps to subroutine.
Input D
D M
1_Stats L1
If M≥ n Goto MAIN
Rem RANGE
0 | Xmin | |
n | Xmax | |
1 | Xscl | |
xmin | Ymin | |
xmax | Ymax | |
0 | I |
|
|
| LOOP1 |
| |
|
|
| ||
| Gosub MOVINGSUM |
| Jumps to subroutine. | |
Y | Number of calculation times of moving sum judged. | |||
|
| M>=J | Repeated until calculation of no. of divisions performed. | |
|
| |||
|
|
|
| |
|
| N |
|
int (M/2) K |
Gosub COUNT |
Label LOOP1 |
Gosub MOVINGSUM |
If M≥ J Goto LOOP1 |
Gosub AVERAGE |
Gosub AVERAGE
LOOP2 | X = K, Y = H | ||
Substitution |
| ||
|
| ||
|
| Jumps to | |
|
| ||
Gosub COUNT |
| ||
| subroutine. | ||
LOOP3 | |||
Jumps to | |||
Gosub MOVINGSUM |
| ||
| subroutine. | ||
|
|
COUNT
I = I + 1, J = I, S = 0
Return
MOVINGSUM
Subroutine Setting of counter
Subroutine Calculation of
Label LOOP2 | |
K | X |
H | Y |
Gosub COUNT | |
Label LOOP3 | |
Gosub MOVINGSUM | |
If (I+M)>J Goto LOOP3 | |
Gosub AVERAGE | |
Line (X, Y, K, H) | |
If K≠ |
Y
(I+M)>J
N
Gosub AVERAGE
Display of line
YK≠
N
End
Jumps to subroutine.
Line displayed.
Judgment of end.
Calculation of moving sum
Return
AVERAGE
Calculation of moving average
Return
moving sum
Subroutine Calculation of average
Wait |
| |
End |
| |
Label COUNT | ||
I+1 | I | |
I | J |
|
0 | S | |
Return | ||
Label MOVINGSUM | ||
S+L1(J) S | ||
J+1 | J | |
Return | ||
Label AVERAGE | ||
S/M | H | |
K+1 | K | |
Return |
16