matrix
Matrices (also callable as methods: m.get(r, c)).
#Functions
#matrix.add_colfunction
Inserts a column (at the end by default).
matrix.add_col(id: matrix<T>, { column?: int = na, array_id?: array<T> = na })| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
column | intdefault na | The column (0-based). |
array_id | array<T>default na | An array with the values (na: na values). |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.add_col(2, array.from(3.0, 4.0))Since ChartScript 1
#matrix.add_rowfunction
Inserts a row (at the end by default).
matrix.add_row(id: matrix<T>, { row?: int = na, array_id?: array<T> = na })| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
row | intdefault na | The row (0-based). |
array_id | array<T>default na | An array with the values (na: na values). |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.add_row(2, array.from(3.0, 4.0))Since ChartScript 1
#matrix.avgfunction
The average of the elements.
matrix.avg(id: matrix<num>): float| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns float.
Example
const m = matrix.new<float>(2, 2, 1.0)
const v = m.avg()Since ChartScript 1
#matrix.colfunction
A new array of one column.
matrix.col(id: matrix<T>, column: int): array<T>| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
column | int | The column (0-based). |
Returns array<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const c = m.col(0)Since ChartScript 1
#matrix.columnsfunction
The number of columns.
matrix.columns(id: matrix<T>): int| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The matrix. |
Returns int.
Example
const m = matrix.new<float>(2, 2, 1.0)
const n = m.columns()Since ChartScript 1
#matrix.concatfunction
Appends the rows of id2 to id1 and returns id1.
matrix.concat(id1: matrix<T>, id2: matrix<T>): matrix<T>| Parameter | Type | Description |
|---|---|---|
id1 | matrix<T> | The first matrix. |
id2 | matrix<T> | The second matrix (or a number). |
Returns matrix<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const m2 = matrix.new<float>(1, 2, 0.0)
m.concat(m2)Since ChartScript 1
#matrix.copyfunction
A copy.
matrix.copy(id: matrix<T>): matrix<T>| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The matrix. |
Returns matrix<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const m2 = m.copy()Since ChartScript 1
#matrix.detfunction
The determinant (square matrices).
matrix.det(id: matrix<num>): float| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns float.
Example
const m = matrix.new<float>(2, 2, 1.0)
const d = m.det()Since ChartScript 1
#matrix.difffunction
Element-wise difference with another matrix or a number.
matrix.diff(id1: matrix<num>, id2: matrix<num>): matrix<float>matrix.diff(id1: matrix<num>, id2: float): matrix<float>| Parameter | Type | Description |
|---|---|---|
id1 | matrix<num> | The first matrix. |
id2 | matrix<num> | The second matrix (or a number). |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const d = m.diff(1.0)Since ChartScript 1
#matrix.eigenvaluesfunction
The eigenvalues (square symmetric matrices in this version), largest first.
matrix.eigenvalues(id: matrix<num>): array<float>| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns array<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const e = m.eigenvalues()Since ChartScript 1
#matrix.eigenvectorsfunction
The eigenvectors as columns (square symmetric matrices in this version), in the order of eigenvalues.
matrix.eigenvectors(id: matrix<num>): matrix<float>| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const v = m.eigenvectors()Since ChartScript 1
#matrix.elements_countfunction
The number of elements.
matrix.elements_count(id: matrix<T>): int| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The matrix. |
Returns int.
Example
const m = matrix.new<float>(2, 2, 1.0)
const n = m.elements_count()Since ChartScript 1
#matrix.fillfunction
Sets a rectangle of elements to value.
matrix.fill(id: matrix<T>, value: T, { from_row?: int = 0, to_row?: int = na, from_column?: int = 0, to_column?: int = na })| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
value | T | The value. |
from_row | intdefault 0 | The first row (inclusive). |
to_row | intdefault na | The last row (exclusive). |
from_column | intdefault 0 | The first column (inclusive). |
to_column | intdefault na | The last column (exclusive). |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.fill(0.0)Since ChartScript 1
#matrix.getfunction
The element at row, column.
matrix.get(id: matrix<T>, row: int, column: int): T| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
row | int | The row (0-based). |
column | int | The column (0-based). |
Returns T.
Example
const m = matrix.new<float>(2, 2, 1.0)
const v = m.get(0, 1)Since ChartScript 1
#matrix.invfunction
The inverse (square matrices; na elements when it has none).
matrix.inv(id: matrix<num>): matrix<float>| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const i = m.inv()Since ChartScript 1
#matrix.is_antidiagonalfunction
true when the matrix is zero outside the anti-diagonal.
matrix.is_antidiagonal(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_antidiagonal()Since ChartScript 1
#matrix.is_antisymmetricfunction
true when the matrix is equal to minus its transpose.
matrix.is_antisymmetric(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_antisymmetric()Since ChartScript 1
#matrix.is_binaryfunction
true when the matrix is every element is 0 or 1.
matrix.is_binary(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_binary()Since ChartScript 1
#matrix.is_diagonalfunction
true when the matrix is zero outside the diagonal.
matrix.is_diagonal(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_diagonal()Since ChartScript 1
#matrix.is_identityfunction
true when the matrix is an identity matrix.
matrix.is_identity(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_identity()Since ChartScript 1
#matrix.is_squarefunction
true when the matrix is as many rows as columns.
matrix.is_square(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_square()Since ChartScript 1
#matrix.is_stochasticfunction
true when the matrix is every row is 0 or more and sums to 1.
matrix.is_stochastic(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_stochastic()Since ChartScript 1
#matrix.is_symmetricfunction
true when the matrix is equal to its transpose.
matrix.is_symmetric(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_symmetric()Since ChartScript 1
#matrix.is_triangularfunction
true when the matrix is zero above or below the diagonal.
matrix.is_triangular(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_triangular()Since ChartScript 1
#matrix.is_zerofunction
true when the matrix is every element is 0.
matrix.is_zero(id: matrix<num>): bool| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns bool.
Example
const m = matrix.new<float>(2, 2, 1.0)
const b = m.is_zero()Since ChartScript 1
#matrix.kronfunction
The Kronecker product.
matrix.kron(id1: matrix<num>, id2: matrix<num>): matrix<float>| Parameter | Type | Description |
|---|---|---|
id1 | matrix<num> | The first matrix. |
id2 | matrix<num> | The second matrix (or a number). |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const k = m.kron(m)Since ChartScript 1
#matrix.maxfunction
The largest element.
matrix.max(id: matrix<num>): float| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns float.
Example
const m = matrix.new<float>(2, 2, 1.0)
const v = m.max()Since ChartScript 1
#matrix.medianfunction
The median of the elements.
matrix.median(id: matrix<num>): float| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns float.
Example
const m = matrix.new<float>(2, 2, 1.0)
const v = m.median()Since ChartScript 1
#matrix.minfunction
The smallest element.
matrix.min(id: matrix<num>): float| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns float.
Example
const m = matrix.new<float>(2, 2, 1.0)
const v = m.min()Since ChartScript 1
#matrix.modefunction
The most frequent element (the smallest on a tie).
matrix.mode(id: matrix<num>): float| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns float.
Example
const m = matrix.new<float>(2, 2, 1.0)
const v = m.mode()Since ChartScript 1
#matrix.multfunction
Matrix product (with a matrix or a vector), or the elements times a number.
matrix.mult(id1: matrix<num>, id2: matrix<num>): matrix<float>matrix.mult(id1: matrix<num>, id2: float): matrix<float>matrix.mult(id1: matrix<num>, id2: array<num>): array<float>| Parameter | Type | Description |
|---|---|---|
id1 | matrix<num> | The first matrix. |
id2 | matrix<num> | The second matrix (or a number). |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const p = m.mult(m)Since ChartScript 1
#matrix.new<T>function
A new matrix of the element type in <>.
Returns matrix<T>.
Example
const m = matrix.new<float>(2, 3, 0)Since ChartScript 1
#matrix.pinvfunction
The pseudo-inverse.
matrix.pinv(id: matrix<num>): matrix<float>| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const p = m.pinv()Since ChartScript 1
#matrix.powfunction
The matrix multiplied by itself power times (square matrices).
matrix.pow(id: matrix<num>, power: int): matrix<float>| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The array. |
power | int | The power (a whole number of 0 or more). |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const p = m.pow(2)Since ChartScript 1
#matrix.rankfunction
The rank.
matrix.rank(id: matrix<num>): int| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns int.
Example
const m = matrix.new<float>(2, 2, 1.0)
const r = m.rank()Since ChartScript 1
#matrix.remove_colfunction
Removes a column (the last by default) and returns it.
matrix.remove_col(id: matrix<T>, { column?: int = na }): array<T>| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
column | intdefault na | The column (0-based). |
Returns array<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const c = m.remove_col(0)Since ChartScript 1
#matrix.remove_rowfunction
Removes a row (the last by default) and returns it.
matrix.remove_row(id: matrix<T>, { row?: int = na }): array<T>| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
row | intdefault na | The row (0-based). |
Returns array<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const r = m.remove_row(0)Since ChartScript 1
#matrix.reshapefunction
Changes the shape (rows * columns must equal the element count).
matrix.reshape(id: matrix<T>, rows: int, columns: int)| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
rows | int | The number of rows. |
columns | int | The number of columns. |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.reshape(1, 4)Since ChartScript 1
#matrix.reversefunction
Reverses the order of rows and columns in place.
matrix.reverse(id: matrix<T>)| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The matrix. |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.reverse()Since ChartScript 1
#matrix.rowfunction
A new array of one row.
matrix.row(id: matrix<T>, row: int): array<T>| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
row | int | The row (0-based). |
Returns array<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const r = m.row(0)Since ChartScript 1
#matrix.rowsfunction
The number of rows.
matrix.rows(id: matrix<T>): int| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The matrix. |
Returns int.
Example
const m = matrix.new<float>(2, 2, 1.0)
const n = m.rows()Since ChartScript 1
#matrix.setfunction
Sets the element at row, column.
matrix.set(id: matrix<T>, row: int, column: int, value: T)| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
row | int | The row (0-based). |
column | int | The column (0-based). |
value | T | The value. |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.set(0, 1, close)Since ChartScript 1
#matrix.sortfunction
Sorts the rows by one column.
matrix.sort(id: matrix<T>, { column?: int = 0, order?: order = order.ascending })| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
column | intdefault 0 | The column (0-based). |
order | orderdefault order.ascending | order.ascending or order.descending. |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.sort(0, order.descending)Since ChartScript 1
#matrix.submatrixfunction
A new matrix of part of the elements.
matrix.submatrix(id: matrix<T>, { from_row?: int = 0, to_row?: int = na, from_column?: int = 0, to_column?: int = na }): matrix<T>| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
from_row | intdefault 0 | The first row (inclusive). |
to_row | intdefault na | The last row (exclusive). |
from_column | intdefault 0 | The first column (inclusive). |
to_column | intdefault na | The last column (exclusive). |
Returns matrix<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const s = m.submatrix(0, 1, 0, 1)Since ChartScript 1
#matrix.sumfunction
Element-wise sum with another matrix or a number.
matrix.sum(id1: matrix<num>, id2: matrix<num>): matrix<float>matrix.sum(id1: matrix<num>, id2: float): matrix<float>| Parameter | Type | Description |
|---|---|---|
id1 | matrix<num> | The first matrix. |
id2 | matrix<num> | The second matrix (or a number). |
Returns matrix<float>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const s = m.sum(1.0)Since ChartScript 1
#matrix.swap_columnsfunction
Swaps two columns.
matrix.swap_columns(id: matrix<T>, column1: int, column2: int)| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
column1 | int | The first column. |
column2 | int | The second column. |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.swap_columns(0, 1)Since ChartScript 1
#matrix.swap_rowsfunction
Swaps two rows.
matrix.swap_rows(id: matrix<T>, row1: int, row2: int)| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The array. |
row1 | int | The first row. |
row2 | int | The second row. |
Example
const m = matrix.new<float>(2, 2, 1.0)
m.swap_rows(0, 1)Since ChartScript 1
#matrix.tracefunction
The sum of the diagonal.
matrix.trace(id: matrix<num>): float| Parameter | Type | Description |
|---|---|---|
id | matrix<num> | The matrix. |
Returns float.
Example
const m = matrix.new<float>(2, 2, 1.0)
const t = m.trace()Since ChartScript 1
#matrix.transposefunction
A new transposed matrix.
matrix.transpose(id: matrix<T>): matrix<T>| Parameter | Type | Description |
|---|---|---|
id | matrix<T> | The matrix. |
Returns matrix<T>.
Example
const m = matrix.new<float>(2, 2, 1.0)
const t = m.transpose()Since ChartScript 1