Skip to contents

Solves F(x) = 0 for a vector-valued F with the ported Numerics multivariate Newton-Raphson method, iterating x_(n+1) = x_n - J(x_n)^-1 F(x_n).

Usage

root_find_system(
  f,
  jacobian,
  first_guess,
  tolerance = NULL,
  max_iterations = NULL
)

Arguments

f

the system of equations: a function taking a numeric vector and returning a numeric vector of the same length.

jacobian

the Jacobian of f: a function taking the same numeric vector and returning the square matrix of partial derivatives, one ROW per equation.

first_guess

the starting vector; its length fixes the dimension of the system.

tolerance

the convergence tolerance, applied to both the step size and the residual. NULL, the default, leaves the ported solver's own default (1e-8) in force.

max_iterations

the iteration cap; the search raises an error if it is reached. NULL, the default, leaves the ported solver's own default (1000) in force.

Value

the root, a numeric vector the length of first_guess.

Examples

f <- function(v) c(3 * v[1] + v[2] - 9, v[1] + 2 * v[2] - 8)
j <- function(v) matrix(c(3, 1, 1, 2), nrow = 2, byrow = TRUE)
root_find_system(f, j, first_guess = c(0, 0))
#> [1] 2 3