Let's assume that we've two arrays (vectors) of single numbers X and Y

of the dimension n. The dot product or scalar product is defined as:

<X,Y> = X(1)*Y(1) + X(2)*Y(2) + ... + X(n)*Y(n)

Let's further assume that both vectors are stored in consecutive

memory locations. A typical BASIC solution would be:

This function should work with every PB compiler, including PB/DOS.

Is that the fastest inner loop pattern?

Philipp

of the dimension n. The dot product or scalar product is defined as:

<X,Y> = X(1)*Y(1) + X(2)*Y(2) + ... + X(n)*Y(n)

Let's further assume that both vectors are stored in consecutive

memory locations. A typical BASIC solution would be:

Code:

FUNCTION DotProduct(X() AS SINGLE, Y() AS SINGLE,n AS INTEGER) AS SINGLE DIM sum AS SINGLE DIM i AS INTEGER sum = 0 FOR i = 1 TO n sum = sum + X(i)*Y(i) NEXT i DotProduct = sum END FUNCTION

Is that the fastest inner loop pattern?

Philipp

## Comment