Southampton BASIC System: Difference between revisions

Content deleted Content added
Arrays: Added example
Arrays: Extended example
Line 127:
 
=== Arrays ===
Support for handling arrays of data was relatively strong, with <code>MAT</code> statements able to read an entire array from <code>DATA</code> statements, and perform useful [[matrix (mathematics)|matrix]] operations such as adding[[matrix oraddition]], multiplying two[[matrix matricessubtraction]], or[[matrix evenmultiplication]], and finding the [[multiplicative inverse matrix]] offor a [[square matrix]].
 
Example:
10 DATADIM 0A(3,0,1,0,1,0,1,0,03)
20 DIMMAT READ A(3,3)
30 DATA 1,1,2,1,0,2,0,2,1
30 MAT READ A
40 DATADIM 2,4B(3,3,-1,0,-2,1,-4,5)
50 DIMMAT READ B(3,3)
60 DATA 0,0,1,0,1,0,1,0,0
60 MAT READ B
70 DIM C(3,3),D(3,3)
80 MAT C = A * B
90 MAT PRINT D=INV(C,)
30100 MAT READPRINT AD,
A contains
 
<math>\begin{pmatrix}
{|
|<code>A</code> is read from the first <code>DATA</code> statement
|<math>\begin{pmatrix}
1 & -41 & 52 \\
21 & 40 & 32 \\
0 & 2 & 1
\end{pmatrix}</math>
|-
|<code>B</code> is read from the second <code>DATA</code> statement
|<math>\begin{pmatrix}
0 & 0 & 1 \\
0 & 1 & 0 \\
1 & 0 & 0
\end{pmatrix}</math>
|-
, B contains
|<code>C</code> is calculated by multiplying <code>A</code> and <code>B</code>
<math>\begin{pmatrix}
|<math>\begin{pmatrix}
2 & 4 & 3 \\
-12 & 01 & -21 \\
12 & -40 & 51 \\
1 & 2 & 0
\end{pmatrix}</math>
|-
, C contains
|<code>D</code> is calculated as the inverse of <code>C</code>
<math>\begin{pmatrix}
|<math>\begin{pmatrix}
1 & -4 & 5 \\
-12 & 02 & -21 \\
21 & 4-1 & 30 \\
4 & -3 & -2
\end{pmatrix}</math>
|}
 
The output would be
This is the output:
12 -4 5 2 1
-1 0 -21 0
24 4 -3 -2
 
== Debugging ==