Sym
objectsDefine a character matrix (covariance matrix from a certain \(AR(1)\)):
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] -alpha 1 0 0
## [3,] 0 -alpha 1 0
## [4,] 0 0 -alpha 1
Now, this can be converted to a Sym
object:
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] -alpha 1 0 0
## [3,] 0 -alpha 1 0
## [4,] 0 0 -alpha 1
Operations can be performed:
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] 5 4 4 4
## [2,] 4 - alpha 5 4 4
## [3,] 4 4 - alpha 5 4
## [4,] 4 4 4 - alpha 5
## Yacas matrix:
## [,1] [,2] [,3]
## [1,] 1 0 0
## [2,] -4 * alpha 1 0
## [3,] 3 * alpha^2 - -3 * alpha^2 -4 * alpha 1
## [4,] -(alpha^3 + alpha * (3 * alpha^2)) 3 * alpha^2 - -3 * alpha^2 -4 * alpha
## [,4]
## [1,] 0
## [2,] 0
## [3,] 0
## [4,] 1
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] 1 0 0 0
## [2,] -4 * alpha 1 0 0
## [3,] 6 * alpha^2 -4 * alpha 1 0
## [4,] -4 * alpha^3 6 * alpha^2 -4 * alpha 1
Or the concentration matrix \(K=L L'\) can be found:
## Yacas matrix:
## [,1] [,2] [,3] [,4]
## [1,] 1 -alpha 0 0
## [2,] -alpha alpha^2 + 1 -alpha 0
## [3,] 0 -alpha alpha^2 + 1 -alpha
## [4,] 0 0 -alpha alpha^2 + 1
This can be converted to \(\LaTeX\):
## [1] "\\left( \\begin{array}{cccc} 1 & - \\alpha & 0 & 0 \\\\ - \\alpha & \\alpha ^{2} + 1 & - \\alpha & 0 \\\\ 0 & - \\alpha & \\alpha ^{2} + 1 & - \\alpha \\\\ 0 & 0 & - \\alpha & \\alpha ^{2} + 1 \\end{array} \\right)"
Which look like this:
\[ K_1 = \left( \begin{array}{cccc} 1 & - \alpha & 0 & 0 \\ - \alpha & \alpha ^{2} + 1 & - \alpha & 0 \\ 0 & - \alpha & \alpha ^{2} + 1 & - \alpha \\ 0 & 0 & - \alpha & \alpha ^{2} + 1 \end{array} \right) \]
Similar can be done for vectors:
## Yacas vector:
## [1] x1 x2
And matrix-vector multiplication (or matrix-matrix multiplication):
## Yacas matrix:
## [,1] [,2]
## [1,] a11 a12
## [2,] a21 a22
## Yacas vector:
## [1] a11 * x1 + a12 * x2 a21 * x1 + a22 * x2
## Yacas matrix:
## [,1] [,2]
## [1,] a11^2 + a12 * a21 a11 * a12 + a12 * a22
## [2,] a21 * a11 + a22 * a21 a21 * a12 + a22^2
## Yacas vector:
## [1] x1 x2
## [1] 2 3
## Yacas matrix:
## [,1] [,2]
## [1,] a11 a12
## [2,] a21 a22
## [,1] [,2]
## [1,] 11 12
## [2,] 21 22
The functionality can be disabled as follows:
## [1] TRUE
## Yacas matrix:
## [,1] [,2]
## [1,] a11 a12
## [2,] a21 a22
## yacas_expression(list(list(a11, a12), list(a21, a22)))