The Sylvester equation is of form $$AX + XB = C$$ where \(X\) is the unknown and others are given. Though it's possible to have non-square \(A\) and \(B\) matrices, we currently support square matrices only. This is a wrapper of armadillo's sylvester function.

sylvester(A, B, C)

Arguments

A

a \((p\times p)\) matrix as above.

B

a \((p\times p)\) matrix as above.

C

a \((p\times p)\) matrix as above.

Value

a solution matrix \(X\) of size \((p\times p)\).

References

Sanderson C, Curtin R (2016). “Armadillo: A Template-Based C++ Library for Linear Algebra.” The Journal of Open Source Software, 1(2), 26.

Eddelbuettel D, Sanderson C (2014). “RcppArmadillo: Accelerating R with High-Performance C++ Linear Algebra.” Computational Statistics and Data Analysis, 71, 1054--1063.

Examples

## simulated example
#  generate square matrices
A = matrix(rnorm(25),nrow=5)
X = matrix(rnorm(25),nrow=5)
B = matrix(rnorm(25),nrow=5)
C = A%*%X + X%*%B

#  solve using 'sylvester' function
solX = sylvester(A,B,C)
pm1 = "* Experiment with Sylvester Solver"
pm2 = paste("* Absolute Error  : ",norm(solX-X,"f"),sep="")
pm3 = paste("* Relative Error  : ",norm(solX-X,"f")/norm(X,"f"),sep="")
cat(paste(pm1,"\n",pm2,"\n",pm3,sep=""))
#> * Experiment with Sylvester Solver
#> * Absolute Error  : 4.58301577182012e-12
#> * Relative Error  : 1.03140878720829e-12