Solves the linear system a %*% x = b for x. Uses LU decomposition
with partial pivoting internally, so a need only be square and
non-singular.
Usage
nv_solve(a, b)
# S3 method for class 'AnvlArray'
solve(a, b, ...)Arguments
- a
(
arrayish)
Square non-singular matrix with exactly 2 axes. Can be any numeric data type:aandbare promoted to a common data type and that is then converted to the default float data type (seedefault_dtypes()) where it is not a float already, since the decomposition is a float one. An R value assumes the other operand's data type within its data type category, and settles on the default float when neither has one.- b
(
arrayish)
Right-hand side, vector of lengthnor matrix withnrows. Promoted together witha– seea.- ...
No additional arguments.
Value
(arrayish)
The solution x such that a %*% x = b, with b's shape and the
operands' common data type – or the default float data type (see
default_dtypes()) where that was an integer one.
Examples
# the solution has `b`'s shape and the operands' common data type
a <- nv_matrix(c(4, 3, 6, 3), nrow = 2, dtype = "f64")
b <- nv_matrix(c(1, 2), nrow = 2, dtype = "f64")
nv_solve(a, b)
#> AnvlArray
#> 1.5000
#> -0.8333
#> [ CPUf64{2,1} ]
# an integer system is solved at the default float data type
nv_solve(nv_matrix(c(3L, 1L, 1L, 2L), nrow = 2), nv_array(c(9L, 8L)))
#> AnvlArray
#> 2.0000
#> 3.0000
#> [ CPUf32{2} ]