- Arrays in Calc are just rows and/or columns of numbers,
so are matrices: neither Calc nor other systems of this
type (Octave, Matlab) understand geometry.
- The simplest way to input
an array is to type it in:
[1 2 3 4 5 6 7]
1: [1, 2, 3, 4, 5, 6, 7]
Calc adds the commas of its own initiative. A vector of
vectors is a matrix, e.g.,
[[0 1][1 0]]
1: [ [ 0, 1 ]
[ 1, 0 ] ]
- This matrix is its own inverse. You can see that if you
type
&, which is a key-binding for function inv:
&
1: [ [ 0, 1 ]
[ 1, 0 ] ]
- You can easily see that this is a correct answer because
'[[0, 1], [1, 0]] * [[0, 1], [1, 0]]
1: [ [ 1, 0 ]
[ 0, 1 ] ]
- There are various operations you can use to build
vectors and matrices, thus saving yourself some effort.
The simplest such operation, invoked by typing
|
concatenates two vectors:
[2 3][4 5]|
1: [2, 3, 4, 5]
Another useful operation is invoked by vd. This
operation converts a vector into a diagonal matrix:
[2 3 4 5]vd
1: [ [ 2, 0, 0, 0 ]
[ 0, 3, 0, 0 ]
[ 0, 0, 4, 0 ]
[ 0, 0, 0, 5 ] ]
A
matrix with a constant diagonal can be built
thusly:
1<ret>M-3vd
1: [ [ 1, 0, 0 ]
[ 0, 1, 0 ]
[ 0, 0, 1 ] ]
You can add a number to a matrix like that, in which case
the number becomes upgraded to a matching size matrix too.
Can you understand what happens here:
0<ret>M-3vd2+
1: [ [ 2, 2, 2 ]
[ 2, 2, 2 ]
[ 2, 2, 2 ] ]
- There is a special command for building an identity matrix.
The command is
vi:
M-4vi
1: [ [ 1, 0, 0, 0 ]
[ 0, 1, 0, 0 ]
[ 0, 0, 1, 0 ]
[ 0, 0, 0, 1 ] ]
The M-4 (meta-4) prefix is the parameter that
specifies the rank of the matrix. You can also use the
algebraic mode for these operations:
'idn(1,3)
1: [ [ 1, 0, 0 ]
[ 0, 1, 0 ]
[ 0, 0, 1 ] ]
'idn(3,2)
1: [ [ 3, 0 ]
[ 0, 3 ] ]
- To build a vector of consecutive integers from 1 to N,
use either
vx (in the stack mode), or index
in the algebraic mode. This function does not take
an argument from the stack, instead it asks for the N in the minibuffer:
vx
Size of vector = 7
1: [1, 2, 3, 4, 5, 6, 7]
'index(5)
1: [1, 2, 3, 4, 5]
But you can force this command to read data from the stack,
by typing C-u vx, in which case it reads 3 numbers:
10<ret>4<ret>2<ret>C-uvx
1: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
This is equivalent to
'index(10, 4, 2)
1: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
- Once you have a vector on the stack you can spread it into
a matrix by typing
vb (the function name is cvec):
1: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
vb
Size of vector = 4
1: [ [ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 ]
[ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 ]
[ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 ]
[ 4, 6, 8, 10, 12, 14, 16, 18, 20, 22 ] ]
- You can perform list-like operations on vectors, extracting
their
head (with vh) or tail
(with Ivh):
1: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
vh
1: 4
'head(index(10, 4, 2))
1: 4
'index(10, 4, 2)
1: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
Ivh
1: [6, 8, 10, 12, 14, 16, 18, 20, 22]
- There is also a
cons operation, invoked by vk:
4<ret>
1: 4
'index(9, 6, 2)
1: [6, 8, 10, 12, 14, 16, 18, 20, 22]
vk
1: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22]
- Operations
rhead (Hvh), rtail
(HIvh), and rcons (Hvk) do much
the same but from the other end, and not always in a way
that you expect: experiment and learn.