library(matlib)
Q <- matrix(c(4,2,9,5,1,-2,-4,-6,2), nrow = 3, ncol = 3)
R <- c(2, 5, 8)
Q
## [,1] [,2] [,3]
## [1,] 4 5 -4
## [2,] 2 1 -6
## [3,] 9 -2 2
R
## [1] 2 5 8
Solve(Q,R)
## x1 = 0.85611511
## x2 = -0.83453237
## x3 = -0.68705036
plotEqn3d(Q,R)
plotEqn3d
## function (A, b, vars, xlim = c(-2, 2), ylim = c(-2, 2), zlim,
## col = 2:(nrow(A) + 1), alpha = 0.9, labels = FALSE, solution = TRUE,
## axes = TRUE, lit = FALSE)
## {
## if (!is.numeric(A) || !is.matrix(A))
## stop("A must be a numeric matrix")
## if (missing(b)) {
## b <- A[, ncol(A)]
## A <- A[, -ncol(A)]
## }
## if (ncol(A) != 3)
## stop("plotEqn3d only handles three-variable equations")
## if (missing(vars))
## vars <- paste0("x", 1:ncol(A))
## neq <- nrow(A)
## if (missing(zlim)) {
## x <- xlim
## y <- ylim
## zlim <- c(0, 0)
## for (i in 1:neq) {
## if (A[i, 3] != 0) {
## z <- (b[i] - A[i, 1] * x - A[i, 2] * y)/A[i,
## 3]
## zlim <- range(c(zlim, z))
## }
## }
## }
## if (length(col) < neq)
## col <- rep_len(col, length.out = neq)
## if (is.logical(labels) && labels) {
## labels <- paste0("(", 1:neq, ")")
## }
## else labels = NULL
## depth_mask <- if (alpha < 1)
## TRUE
## else FALSE
## dat <- replicate(2, 1:3)
## rgl::plot3d(dat, type = "n", xlim = xlim, ylim = ylim, zlim = c(-3,
## 3), xlab = vars[1], ylab = vars[2], zlab = vars[3], axes = axes)
## rgl::planes3d(A[, 1], A[, 2], A[, 3], -b, col = col, alpha = alpha,
## lit = lit, depth_mask = depth_mask)
## if (solution) {
## x <- try(solve(A, b), silent = TRUE)
## if (!inherits(x, "try-error"))
## rgl::spheres3d(solve(A, b), radius = 0.2)
## }
## }
## <bytecode: 0x00000268d06db838>
## <environment: namespace:matlib>