Interactive PowerBasic Forum

IT-Consultant: Charles Pegge => OxygenBasic Examples => Topic started by: Charles Pegge on February 16, 2025, 06:53:43 AM

Title: Mean and Variance (Standard Deviation) Macros
Post by: Charles Pegge on February 16, 2025, 06:53:43 AM

macro mean as float(r,a)
========================
scope
  int i,l,u
  l=lbound(a)
  u=ubound(a)
  float t=0
  for i=l to u
    t+=a[i]
  next
  r=t/(u-l+1)
end scope
end macro

macro variance as float(r,a)
============================
scope
  int i,l,u
  float m,d
  m=mean(a)
  l=lbound(a)
  u=ubound(a)
  float t=0
  for i=l to u
    d=a[i]-m
    d*=d
    t+=d
  next
  r=t/(u-l+1)
end scope
end macro

'TEST
'====
dim int a={1,2,3,4,5,6}
print mean(a)
'standard deviation
print sqr(variance(a))