solve2 {sanic}R Documentation

Solve Systems of Equations

Description

Solve systems of equations Ax=bAx = 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.

Usage

solve2(a, b, ...)

Arguments

a

Square numeric matrix with the coefficients of the linear system. Both dense and sparse matrices are supported (see sparsify).

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.

Value

Solves for xx and returns a numeric matrix with the results.

Examples

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)


[Package sanic version 0.0.2 Index]