<< Click to Display Table of Contents >> Navigation: ThinBASIC Modules > STAT (Statistical module) > Stat_Sum |
Description
Returns the sum of all ArrayVariable items.
Syntax
n = STAT_Sum(ArrayVariable)
Returns
Number. The sum of all values inside array.
Parameters
Name |
Type |
Optional |
Meaning |
ArrayVariable |
Numeric Array |
No |
The array containing data |
Remarks
This function will expect the name of a predefined array with all the necessary data already loaded.
Restrictions
See also
Examples
'---Instruct thinBasic to use STAT module
USES "STAT"
%ELEMENTS = 1000000
Dim aData(%ELEMENTS) As Ext
Dim sMsg As String
Dim lSum, lMin, lMax As Ext
Dim lMaxPos, lMinPos As Long
'---Fill the array with first %ELEMENTS natural numbers
Stat_FillArray(aData, %Stat_Fill_Natural)
'---Or if you prefer to fill with random data from 1 to %ELEMENTS
'Stat_Random(aData, 1, %ELEMENTS)
'---Now some basic stats: Sum, Min, Max
lSum = Stat_Sum(aData)
lMin = Stat_Min(aData, lMinPos)
lMax = Stat_Max(aData, lMaxPos)
sMsg = "Some very simple statistical functions" & $crlf
sMsg += "Sum: " & $Tab & lSum & $crlf
sMsg += "Min: " & $Tab & lMin & " ---> Min value is located at position " & lMinPos & " inside the array." & $crlf
sMsg += "Max: " & $Tab & lMax & " ---> Max value is located at position " & lMaxPos & " inside the array." & $crlf
msgbox 0, sMsg, 0, "Total Elements considered: " & %ELEMENTS