12.4 algebra_solver, algebra_solver_newton algebraic solvers
These algebraic solver functions have been replaced by those described in:
12.4.1 Specifying an algebraic equation as a function
An algebraic system is specified as an ordinary function in Stan within the function block. The algebraic system function must have this signature:
vector algebra_system(vector y, vector theta,
data array[] real x_r, array[] int x_i)
The algebraic system function should return the value of the algebraic function which goes to 0, when we plug in the solution to the algebraic system.
The argument of this function are:
y
, the unknowns we wish to solve fortheta
, parameter values used to evaluate the algebraic systemx_r
, data values used to evaluate the algebraic systemx_i
, integer data used to evaluate the algebraic system
The algebraic system function separates parameter values, theta
,
from data values, x_r
, for efficiency in propagating the derivatives
through the algebraic system.
12.4.2 Call to the algebraic solver
vector
algebra_solver
(function algebra_system, vector y_guess, vector theta, data array[] real x_r, array[] int x_i)
Solves the algebraic system, given an initial guess, using the Powell
hybrid algorithm.
Available since 2.17, deprecated in 2.31
vector
algebra_solver
(function algebra_system, vector y_guess, vector theta, data array[] real x_r, array[] int x_i, data real rel_tol, data real f_tol, int max_steps)
Solves the algebraic system, given an initial guess, using the Powell
hybrid algorithm with additional control parameters for the solver.
Available since 2.17, deprecated in 2.31
Note: In future releases, the function algebra_solver
will be deprecated
and replaced with algebra_solver_powell
.
vector
algebra_solver_newton
(function algebra_system, vector y_guess, vector theta, data array[] real x_r, array[] int x_i)
Solves the algebraic system, given an initial guess, using Newton’s method.
Available since 2.24, deprecated in 2.31
vector
algebra_solver_newton
(function algebra_system, vector y_guess, vector theta, data array[] real x_r, array[] int x_i, data real rel_tol, data real f_tol, int max_steps)
Solves the algebraic system, given an initial guess, using Newton’s method
with additional control parameters for the solver.
Available since 2.24, deprecated in 2.31
12.4.2.1 Arguments to the algebraic solver
The arguments to the algebraic solvers are as follows:
algebra_system
: function literal referring to a function specifying the system of algebraic equations with signature(vector, vector, array[] real, array[] int):vector
. The arguments represent (1) unknowns, (2) parameters, (3) real data, and (4) integer data, and the return value contains the value of the algebraic function, which goes to 0 when we plug in the solution to the algebraic system,y_guess
: initial guess for the solution, typevector
,theta
: parameters only, typevector
,x_r
: real data only, typearray[] real
, andx_i
: integer data only, typearray[] int
.
For more fine-grained control of the algebraic solver, these parameters can also be provided:
rel_tol
: relative tolerance for the algebraic solver, typereal
, data only,function_tol
: function tolerance for the algebraic solver, typereal
, data only,max_num_steps
: maximum number of steps to take in the algebraic solver, typeint
, data only.