# Find a matrix X such that X * X * X = [1, 2; 3, 4]
F <- function(x) {
a <- matrix(c(1, 3, 2, 4), nrow = 2, ncol = 2, byrow = TRUE)
X <- matrix(x, nrow = 2, ncol = 2, byrow = TRUE)
return(c(X %*% X %*% X - a))
}
x0 <- matrix(1, nrow = 2, ncol = 2)
fsolve(F, x0)
# $x
# -0.1291489 0.8602157
# 1.2903236 1.1611747
Run the code above in your browser using DataLab