3.1. Matrix

3.1.1. Matrix creation

3.1.1.1. Matrix from arguments

matrix(width, height, ...)

Create a matrix given a size and a list of arguments

Parameters:
  • width – number of columns in the matrix
  • height – number of lines in the matrix
$ eq eval "matrix( 2, 2, a, b, c, d )"
|¯   ¯| 
| a b | 
|     | 
| c d | 
|_   _|
The matrix() matrix function take at least 3 arguments :
  1. The width of the matrix
  2. The height of the matrix
  3. At least one element.

The number of argument must be equal to width * height. You can define column and row matrices

$ eq eval "matrix( 1, 4, a, b, c, d )"
|¯ ¯| 
| a | 
|   | 
| b | 
|   | 
| c | 
|   | 
| d | 
|_ _|
$ eq eval "matrix( 4, 1, a, b, c, d )"
|¯       ¯| 
| a b c d | 
|_       _|

3.1.1.2. Matrix from list

matrix(lists)
Create a matrix given a list of lists

You also can build matrices directly from lists (which can be dynamically generated)

$ eq eval "matrix( [1, 4, a, b, c, d ] )"
|¯           ¯| 
| 1 4 a b c d | 
|_           _|
$ eq eval "matrix( [[1, 0], [0, 1]])"
|¯   ¯| 
| 1 0 | 
|     | 
| 0 1 | 
|_   _|

3.1.2. Supported operators

Matrices support only a subset of all the operators, between them only addition and multiplication are supported (if they size match for the operation that is).

$ eq eval "matrix( 2, 2, a, b, c, d ) + matrix( 2, 2, e, f, g, h )"
|¯           ¯| 
| a + e b + f | 
|             | 
| c + g d + h | 
|_           _|
$ eq eval "matrix( 2, 2, a, b, c, d ) * matrix( 2, 2, e, f, g, h )"
|¯                   ¯| 
| a.e + b.g a.f + b.h | 
|                     | 
| c.e + d.g c.f + d.h | 
|_                   _|

Only two operators are allowed between matrices and scalars, multiplication and division.

$ eq eval "matrix( 1, 4, a, b, c, d ) * (x+y)"
|¯         ¯| 
| (y + x).a | 
|           | 
| (y + x).b | 
|           | 
| (y + x).c | 
|           | 
| (y + x).d | 
|_         _|
$ eq eval "matrix( 4, 1, a, b, c, d ) / x^2"
|¯                   ¯| 
|  a    b    c    d   | 
| ---- ---- ---- ---- | 
|   2    2    2    2  | 
|  x    x    x    x   | 
|_                   _|

Table Of Contents

Previous topic

3. Language

Next topic

3.2. Boolean

This Page