06-13-2020, 03:22 PM
If a matrix is diagonalizable, you can use eigendecomposition of a matrix ( A = QΛQ^(-1) ) then apply the function to each element of the diagonal in matrix Λ and assembling everything back. This program takes a matrix and a program with the function to apply and return the matrix with the function applied.
«
SWAP EGV @ Q in level 2 and diagonal of Λ (as a vector)in level 1
ROT MAP @ The function is applied to each eigenvalue
OVER SIZE DIAG→ @ Get a diagonal matrix
OVER INV @ Get the inverse of Q
* * @ assemble the matrix with the function applied
« EVAL » MAP @ Evaluate each element of the new matrix
» 'AFM' |STO|
Example: Find the square root of [[-5 6] [-9 10]]
[[-5 6] -9 10] |ENTER|
« √ » |ENTER| |VAR| |AFM|
1: [[ -1 2 ] [ -3 4 ]]
«
SWAP EGV @ Q in level 2 and diagonal of Λ (as a vector)in level 1
ROT MAP @ The function is applied to each eigenvalue
OVER SIZE DIAG→ @ Get a diagonal matrix
OVER INV @ Get the inverse of Q
* * @ assemble the matrix with the function applied
« EVAL » MAP @ Evaluate each element of the new matrix
» 'AFM' |STO|
Example: Find the square root of [[-5 6] [-9 10]]
[[-5 6] -9 10] |ENTER|
« √ » |ENTER| |VAR| |AFM|
1: [[ -1 2 ] [ -3 4 ]]