| solve2 | R Documentation |
Solve systems of equations Ax = b using an automatically
chosen direct method (see solve_chol). Methods are chosen for
speed at reasonable accuracy. Please choose a suitable method manually if
numerical stability is the main consideration.
solve2(a, b, ...)
## Default S3 method:
solve2(a, b, ...)
## S3 method for class 'sanic_lu'
solve2(a, b, ...)
a |
Numeric matrix with the coefficients of the linear system, dense or
sparse (see |
b |
Numeric vector or matrix at the right-hand side of the linear system. If missing, 'b' is set to an identity matrix and 'a' is inverted. |
... |
Dispatched to methods in the solvers. |
Solves for x and returns a numeric matrix with the results.
set.seed(42)
x <- rnorm(3)
# Solve using a general matrix
A <- matrix(rnorm(9), nrow = 3, ncol = 3)
b <- A %*% x
norm(solve2(A, b) - x)
# Solve using a symmetric matrix
A <- crossprod(matrix(rnorm(9), nrow = 3, ncol = 3))
b <- A %*% x
norm(solve2(A, b) - x)
# Solve using a square matrix
A <- matrix(rnorm(12), nrow = 4, ncol = 3)
b <- A %*% x
norm(solve2(A, b) - x)
# Solve reusing an LU factorization
A <- matrix(rnorm(9), nrow = 3, ncol = 3)
f <- factorize_lu(A)
norm(solve2(f, A %*% x) - x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.