Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
def max 1000
|
||||
|
||||
Class MovingAverage
|
||||
'==================
|
||||
|
||||
indexbase 1
|
||||
double average,invperiod,mdata[max]
|
||||
sys index,period
|
||||
|
||||
method Setup(double a,p)
|
||||
sys i
|
||||
Period=p
|
||||
invPeriod=1/p
|
||||
index=0
|
||||
average=a
|
||||
for i=1 to period
|
||||
mdata[i]=a
|
||||
next
|
||||
end method
|
||||
|
||||
method Data(double v) as double
|
||||
sys i
|
||||
index++
|
||||
if index>period then index=1 'recycle
|
||||
i=index+1 'for oldest data
|
||||
if i>period then i=1 'recycle
|
||||
mdata[index]=v
|
||||
average=average+invperiod*(v-mdata[i])
|
||||
end method
|
||||
|
||||
end class
|
||||
|
||||
'TEST
|
||||
'====
|
||||
|
||||
MovingAverage A
|
||||
|
||||
A.Setup 100,10 'initial value and period
|
||||
|
||||
A.data 50
|
||||
'...
|
||||
print A.average 'reult 95
|
||||
Loading…
Add table
Add a link
Reference in a new issue