SmallBASIC GuideThe language | Programming Tips | Commands | System | Graphics & Sound | Miscellaneous | File system | Mathematics | 2D Algebra | Strings | Console | Glossary |
Arrays and Matrices
Define a 3x2 matrix
A = [11, 12; 21, 22; 31, 32]
That creates the array
| 11 12 |
| 21 22 | = A
| 31 32 |
The comma used to separate column items; the semi-colon used to
separate rows. Values between columns can be omitted.
A = [ ; ; 1, 2 ; 3, 4, 5]
This creates the array
| 0 0 0 |
| 1 2 0 | = A
| 3 4 5 |
Supported operators:
Add/sub:
B = [1, 2; 3, 4]: C = [5, 6; 7, 8]
A = B + C
C = A - B
Equal:
bool=(A=B)
Unary:
A2 = -A
Multiplication:
A = [1, 2; 3, 4]: B = [5 ; 6]
C = A * B
D = 0.8 * A
Inverse:
A = [ 1, -1, 1; 2, -1, 2; 3, 2, -1]
? INVERSE(A)
Gauss-Jordan:
? "Solve this:"
? " 5x - 2y + 3z = -2"
? " -2x + 7y + 5z = 7"
? " 3x + 5y + 6z = 9"
?
A = [ 5, -2, 3; -2, 7, 5; 3, 5, 6]
B = [ -2; 7; 9]
C = LinEqn(A, B)
? "[x;y;z] = "; C
There is a problem with 1 dimension arrays, because 1-dim arrays does not specify how SmallBASIC must see them.
DIM A(3)
| 1 2 3 | = A
or
| 1 |
| 2 | = A
| 3 |
And because this is not the same thing. (ex. for multiplication)
So the default is columns
DIM A(3) ' or A(1,3)
| 1 2 3 | = A
For vertical arrays you must declare it as 2-dim arrays Nx1
DIM A(3,1)
| 1 |
| 2 | = A
| 3 |
[Prev] [Next]