Script:
~addons/finance/finexec/actuarialmethods/matrix_tools.ijs
Contributor: William Szuch
Updated: 2022 6 25
Depend: nil
Definitions: loaded to locale base
Status: dev
Script source:
matrix_tools.ijs
Tools for manipulations of matrices.
Rotation of matrices.
Transposing of matrices.
For example development tables: incident/accident and report
periods.
Special matrices.
Definitions
|
mat_det
|
m
|
Determinant of matrix y
|
|
mat_id
|
m
|
Create an identy matrix
|
|
mat_inv
|
m
|
Inverse of matrix y
|
|
mat_mult
|
m
|
Matrix multiplication of x and y
|
bottom_triL (monad)
Form: tacit
Depend: nil
Create a matrix with 1s to the RHS.
Bottom row is all 1s.
Columns are 0 and 1s
Syntax
bottom_triL(R,[C})
R = rows dimension of square matrix
[C] = optional number of columns for a rectangular matrix
Example
bottom_triL 4
0 0 0 1
0 0 1 1
0 1 1 1
1 1 1 1
bottom_triL(4 6)
0 0 0 1 1 1
0 0 1 1 1 1
0 1 1 1 1 1
1 1 1 1 1 1
bottom_triR (monad)
Form: tacit
Depend: nil
Create a matrix with 1s to the RHS.
Bottom row is all 1s.
Columns are 0 and 1s
Syntax
uppertriR(R,[C})
R = rows dimension of square matrix
[C] = optional number of columns for a rectangular matrix
Example
bottom_triR 4
0 0 0 1
0 0 1 1
0 1 1 1
1 1 1 1
bottom_triR(4 6)
0 0 0 1 1 1
0 0 1 1 1 1
0 1 1 1 1 1
1 1 1 1 1 1
left_tri (monad)
Form: tacit
Depend: nil
Create a matrix with 1s to the LHS.
Left column is all 1s.
Rows are 0 and 1s
Syntax
left_tri(R,[C])
R = rows dimension of square matrix
[C] = optional number of columns for a rectangular matrix
Example
left_tri 4
1 0 0 0
1 1 0 0
1 1 1 0
1 1 1 1
left_tri(4 6)
1 0 0 0 0 0
1 1 0 0 0 0
1 1 1 0 0 0
1 1 1 1 0 0
left_tri(6 4)
1 0 0 0
1 1 0 0
1 1 1 0
1 1 1 1
1 1 1 1
1 1 1 1
right_tri (monad)
Form: tacit
Depend: nil
Create a matrix with 1s to the RHS.
Right column is all 1s.
Rows are 0 and 1s
Syntax
right_tri(R,[C})
R = rows dimension of square matrix
[C] = optional number of columns for a rectangular matrix
Example
right_tri 4
0 0 0 1
0 0 1 1
0 1 1 1
1 1 1 1
right_tri(4 6)
0 0 0 0 0 1
0 0 0 0 1 1
0 0 0 1 1 1
0 0 1 1 1 1
rotate1 (monad)
Form: explicit
Depend: nil
Rotate a matrix along its rows from right to left.
For example: report period to development period.
Syntax
rorate1(M)
M = matrix to be rotated
Example
rotate1(4 4 $ i. 4)
0 1 2 3
1 2 3 0
2 3 0 1
3 0 1 2
rotate1(3 4 $ i. 4)
0 1 2 3
1 2 3 0
2 3 0 1
rotate1(4 3 $ i. 3)
0 1 2
1 2 0
2 0 1
0 1 2
rotate2 (monad)
Form: explicit
Depend: nil
Rotate a matrix along its rows from left to right.
For example: development period to report period.
Syntax
rorate2(M)
M = matrix to be rotated
Example
rotate2(4 4 $ i. 4)
0 1 2 3
3 0 1 2
2 3 0 1
1 2 3 0
rotate2(3 4 $ i. 4)
0 1 2 3
3 0 1 2
2 3 0 1
rotate2(4 3 $ i. 3)
0 1 2
2 0 1
1 2 0
0 1 2
rotate3 (monad)
Form: explicit
Depend: rotate1
Rotate a matrix along its rows along the reserve diagonal.
Syntax
rorate3(M)
M = matrix to be rotated
Example
rotate3(4 4 $ i. 4)
3 0 1 2
2 3 0 1
1 2 3 0
0 1 2 3
rotate3(3 4 $ i. 4)
2 3 0 1
1 2 3 0
0 1 2 3
rotate3(4 3 $ i. 3)
0 1 2
2 0 1
1 2 0
0 1 2
rotate4 (monad)
Form: explicit
Depend: rotate2
Rotate a matrix along its rows along the diagonal.
Syntax
rorate3(M)
M = matrix to be rotated
Example
rotate3(4 4 $ i. 4)
3 0 1 2
2 3 0 1
1 2 3 0
0 1 2 3
rotate3(3 4 $ i. 4)
2 3 0 1
1 2 3 0
0 1 2 3
rotate3(4 3 $ i. 3)
0 1 2
2 0 1
1 2 0
0 1 2
top_triL (monad)
Form: tacit
Depend: nil
Create a matrix with 1s to the LHS.
Top row is all 1s.
Columns are 0 and 1s
Syntax
top_triL(R,[C])
R = rows dimension of square matrix
[C] = optional number of columns for a rectangular matrix
Example
top_triL 4
1 1 1 1
1 1 1 0
1 1 0 0
1 0 0 0
top_triL(4 6)
1 1 1 1 1 1
1 1 1 1 1 0
1 1 1 1 0 0
1 1 1 0 0 0
top_triL(6 4)
1 1 1 1
1 1 1 0
1 1 0 0
1 0 0 0
0 0 0 0
0 0 0 0
top_triR (monad)
Form: tacit
Depend: nil
Create a matrix with 1s to the RHS.
Top row is all 1s.
Columns are 0 and 1s
Syntax
top_triR(R,[C])
R = rows of a square matrix
[C] = optional number of columns for a rectangular matrix
Example
top_triR 4
1 1 1 1
0 1 1 1
0 0 1 1
0 0 0 1
top_triR(4 6)
1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
top_triR(6 4)
1 1 1 1
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
0 0 0 0