In BASIC a vector will usually be represented by a one-dimensional array, and a matrix by a two-dimensional array. Therefore a simple use for the dot product when operating on two vectors might be as follows:
Code: Select all
DIM a(9), b(9), c(0)
a() = 1,2,3,4,5,6,7,8,9,0
b() = 9,8,7,6,5,4,3,2,1,0
c() = a() . b()
PRINT c(0)
The surprising thing is that this code, despite its simplicity, doesn't work in either Matrix Brandy BASIC or Sophie's ARM BASIC! In Matrix Brandy it runs but prints the incorrect value 405 (I've not the slightest idea why) and in ARM BASIC 5 it produces the error message 'Can't assign to array of this size' (unhelpfully it gives no clue of what size of array it could assign to!).
To make it produce the correct answer of 165 in Matrix Brandy and ARM BASIC it's necessary to modify the code as follows:
Code: Select all
DIM a(9), b(9,0), c(0)
a() = 1,2,3,4,5,6,7,8,9,0
b() = 9,8,7,6,5,4,3,2,1,0
c() = a() . b()
PRINT c(0)
But in fact it doesn't work at all if you make that change, ARM BASIC prints -6.46249256E-38 and Matrix Brandy reports the error ''Type mismatch: Arrays must have the same dimensions'!
I'm totally confused by all this. The dot product is one of the most valuable features of BBC BASIC but by my reckoning both ARM BASIC 5 and Matrix Brandy get it wrong - albeit that you can persuade them to produce the right result if you know what incantation to use.