• Status: Solved
• Priority: Medium
• Security: Public
• Views: 191

# Math Functions In Large Numeric Arrays

I have some large arrays (between 1000 and 2000 spots) Anywho I was wondering is there any functions that can find me the sum, product, sort them (least int to largest int), also the natural log of the array. I know there probally is I just haven't searched much. I just hate these for/loops that I keep running to do val = val + array(x) now that isn't what I'm using they look more like

for x = 1 to iDataIndex
array(0) = array(0) + val(0,x)
array(1) = array(1) + val(1,x)
array(2) = array(2) + val(2,x)
array(3) = array(3) + val(3,x)
next x

but any functions can help even better for/loops (especially for the product part) anywho thanks in advance,
MoDrop
0
MoDrop
• 2
2 Solutions

Commented:
to sort an array, this is a very basic method

For inJ = 1 to X-1
for inI = 1 to X-1

if myarray(inI) > myarray(inI+1) then
inTemp = myarray(inI)
myarray(inI) = myarray(inI+1)
myarray (inI+1) = inTemp
end if

Next inI
Next inJ

This will compare two array members that are adjacent to each other.  Which ever one is greater, it will move to the bottom of the array.  So after one pass through(or one inJ), you will have the largest element in your array as the last value.  After 2 passes, you will have the largest 2, and ect, until after X-1 passes you will have them sorted from smallest to largest.

I hope this helps.

Jacamar
0

Commented:
To get the natural log of a value, use

dim NatLog() as single

Redim NatLog(1 to X)

For inI = 1 to X

NatLog(inI) = Log(myarray(inI)

Next inI

Jacamar
0

Commented:
MoDrop: