Difference between array(n) and array(n TO n)

Discussions related to mathematics, numerical methods, graph plotting etc.
Richard Russell
Posts: 325
Joined: Tue 18 Jun 2024, 09:32

Difference between array(n) and array(n TO n)

Post by Richard Russell »

Given a one-dimensional array, array(n) and array(n TO n) represent the same thing (the n'th element of the array, counting from zero) but whereas array(n) is a scalar value array(n TO n) is a single-element array containing that value.

This difference is of particular importance when working with the dot product (scalar product). Mathematically, if one computes the dot-product of two vectors the result is a scalar value, but because of the syntax requirements of BBC BASIC you cannot do this:

Code: Select all

      array(n) = vector1() . vector2() : REM doesn't work
but you can do this:

Code: Select all

      array(n TO n) = vector1() . vector2()