Functions
Title

Functions

CASADI_EXPORT Function casadi::rootfinder (const std::string &name, const std::string &solver, const SXDict &rfp, const Dict &opts=Dict())
 
CASADI_EXPORT Function casadi::rootfinder (const std::string &name, const std::string &solver, const MXDict &rfp, const Dict &opts=Dict())
 
CASADI_EXPORT Function casadi::rootfinder (const std::string &name, const std::string &solver, const Function &f, const Dict &opts=Dict())
 
CASADI_EXPORT std::vector< std::string > casadi::rootfinder_in ()
 Get rootfinder input scheme. More...
 
CASADI_EXPORT std::vector< std::string > casadi::rootfinder_out ()
 Get rootfinder output scheme. More...
 
CASADI_EXPORT std::string casadi::rootfinder_in (casadi_int ind)
 Get rootfinder input scheme name by index. More...
 
CASADI_EXPORT std::string casadi::rootfinder_out (casadi_int ind)
 Get rootfinder output scheme name by index. More...
 
CASADI_EXPORT casadi_int casadi::rootfinder_n_in ()
 Number of rootfinder inputs. More...
 
CASADI_EXPORT casadi_int casadi::rootfinder_n_out ()
 Number of rootfinder outputs. More...
 
CASADI_EXPORT std::vector< std::string > casadi::rootfinder_options (const std::string &name)
 Get all options for a plugin. More...
 
CASADI_EXPORT std::string casadi::rootfinder_option_type (const std::string &name, const std::string &op)
 Get type info for a particular option. More...
 
CASADI_EXPORT std::string casadi::rootfinder_option_info (const std::string &name, const std::string &op)
 Get documentation for a particular option. More...
 
CASADI_EXPORT bool casadi::has_rootfinder (const std::string &name)
 Check if a particular plugin is available. More...
 
CASADI_EXPORT void casadi::load_rootfinder (const std::string &name)
 Explicitly load a plugin dynamically. More...
 
CASADI_EXPORT std::string casadi::doc_rootfinder (const std::string &name)
 Get the documentation string for a plugin. More...
 

Detailed Description

Create a solver for rootfinding problems Takes a function where one of the inputs is unknown and one of the outputs is a residual function that is always zero, defines a new function where the the unknown input has been replaced by a guess for the unknown and the residual output has been replaced by the calculated value for the input.

For a function [y0, y1, ...,yi, .., yn] = F(x0, x1, ..., xj, ..., xm), where xj is unknown and yi=0, defines a new function [y0, y1, ...,xj, .., yn] = G(x0, x1, ..., xj_guess, ..., xm),

xj and yi must have the same dimension and d(yi)/d(xj) must be invertable.

By default, the first input is unknown and the first output is the residual.

General information


List of available options
IdTypeDescriptionUsed in
ad_weightOT_DOUBLEWeighting factor for derivative calculation.When there is an option of either using forward or reverse mode directional derivatives, the condition ad_weight*nf<=(1-ad_weight)*na is used where nf and na are estimates of the number of forward/reverse mode directional derivatives needed. By default, ad_weight is calculated automatically, but this can be overridden by setting this option. In particular, 0 means forcing forward mode and 1 forcing reverse mode. Leave unset for (class specific) heuristics.casadi::FunctionInternal
ad_weight_spOT_DOUBLEWeighting factor for sparsity pattern calculation calculation.Overrides default behavior. Set to 0 and 1 to force forward and reverse mode respectively. Cf. option "ad_weight". When set to -1, sparsity is completely ignored and dense matrices are used.casadi::FunctionInternal
always_inlineOT_BOOLForce inlining.casadi::FunctionInternal
cacheOT_DICTPrepopulate the function cache. Default: emptycasadi::FunctionInternal
common_optionsOT_DICTOptions for auto-generated functionscasadi::OracleFunction
compilerOT_STRINGJust-in-time compiler plugin to be used.casadi::FunctionInternal
constraintsOT_INTVECTORConstrain the unknowns. 0 (default): no constraint on ui, 1: ui >= 0.0, -1: ui <= 0.0, 2: ui > 0.0, -2: ui < 0.0.casadi::Rootfinder
custom_jacobianOT_FUNCTIONOverride CasADi's AD. Use together with 'jac_penalty': 0. Note: Highly experimental. Syntax may break often.casadi::FunctionInternal
der_optionsOT_DICTDefault options to be used to populate forward_options, reverse_options, and jacobian_options before those options are merged in.casadi::FunctionInternal
derivative_ofOT_FUNCTIONThe function is a derivative of another function. The type of derivative (directional derivative, Jacobian) is inferred from the function name.casadi::FunctionInternal
dumpOT_BOOLDump function to file upon first evaluation. [false]casadi::FunctionInternal
dump_dirOT_STRINGDirectory to dump inputs/outputs to. Make sure the directory exists [.]casadi::FunctionInternal
dump_formatOT_STRINGChoose file format to dump matrices. See DM.from_file [mtx]casadi::FunctionInternal
dump_inOT_BOOLDump numerical values of inputs to file (readable with DM.from_file) [default: false]casadi::FunctionInternal
dump_outOT_BOOLDump numerical values of outputs to file (readable with DM.from_file) [default: false]casadi::FunctionInternal
enable_fdOT_BOOLEnable derivative calculation by finite differencing. [default: false]]casadi::FunctionInternal
enable_forwardOT_BOOLEnable derivative calculation using generated functions for Jacobian-times-vector products - typically using forward mode AD - if available. [default: true]casadi::FunctionInternal
enable_jacobianOT_BOOLEnable derivative calculation using generated functions for Jacobians of all differentiable outputs with respect to all differentiable inputs - if available. [default: true]casadi::FunctionInternal
enable_reverseOT_BOOLEnable derivative calculation using generated functions for transposed Jacobian-times-vector products - typically using reverse mode AD - if available. [default: true]casadi::FunctionInternal
error_on_failOT_BOOLThrow exceptions when function evaluation fails (default true).casadi::ProtoFunction
expandOT_BOOLReplace MX with SX expressions in problem formulation [false]casadi::OracleFunction
external_transformOT_VECTORVECTORList of external_transform instruction arguments. Default: emptycasadi::FunctionInternal
fd_methodOT_STRINGMethod for finite differencing [default 'central']casadi::FunctionInternal
fd_optionsOT_DICTOptions to be passed to the finite difference instancecasadi::FunctionInternal
forward_optionsOT_DICTOptions to be passed to a forward mode constructorcasadi::FunctionInternal
gather_statsOT_BOOLDeprecated option (ignored): Statistics are now always collected.casadi::FunctionInternal
implicit_inputOT_INTIndex of the input that corresponds to the actual root-findingcasadi::Rootfinder
implicit_outputOT_INTIndex of the output that corresponds to the actual root-findingcasadi::Rootfinder
input_schemeOT_STRINGVECTORDeprecated option (ignored)casadi::FunctionInternal
inputs_checkOT_BOOLThrow exceptions when the numerical values of the inputs don't make sensecasadi::FunctionInternal
is_diff_inOT_BOOLVECTORIndicate for each input if it should be differentiable.casadi::FunctionInternal
is_diff_outOT_BOOLVECTORIndicate for each output if it should be differentiable.casadi::FunctionInternal
jac_penaltyOT_DOUBLEWhen requested for a number of forward/reverse directions, it may be cheaper to compute first the full jacobian and then multiply with seeds, rather than obtain the requested directions in a straightforward manner. Casadi uses a heuristic to decide which is cheaper. A high value of 'jac_penalty' makes it less likely for the heurstic to chose the full Jacobian strategy. The special value -1 indicates never to use the full Jacobian strategycasadi::FunctionInternal
jacobian_functionOT_FUNCTIONFunction object for calculating the Jacobian (autogenerated by default)casadi::Rootfinder
jacobian_optionsOT_DICTOptions to be passed to a Jacobian constructorcasadi::FunctionInternal
jitOT_BOOLUse just-in-time compiler to speed up the evaluationcasadi::FunctionInternal
jit_cleanupOT_BOOLCleanup up the temporary source file that jit creates. Default: truecasadi::FunctionInternal
jit_nameOT_STRINGThe file name used to write out code. The actual file names used depend on 'jit_temp_suffix' and include extensions. Default: 'jit_tmp'casadi::FunctionInternal
jit_optionsOT_DICTOptions to be passed to the jit compiler.casadi::FunctionInternal
jit_serializeOT_STRINGSpecify behaviour when serializing a jitted function: SOURCE|link|embed.casadi::FunctionInternal
jit_temp_suffixOT_BOOLUse a temporary (seemingly random) filename suffix for generated code and libraries. This is desired for thread-safety. This behaviour may defeat caching compiler wrappers. Default: truecasadi::FunctionInternal
linear_solverOT_STRINGUser-defined linear solver class. Needed for sensitivities.casadi::Rootfinder
linear_solver_optionsOT_DICTOptions to be passed to the linear solver.casadi::Rootfinder
max_ioOT_INTAcceptable number of inputs and outputs. Warn if exceeded.casadi::FunctionInternal
max_num_dirOT_INTSpecify the maximum number of directions for derivative functions. Overrules the builtin optimized_num_dir.casadi::FunctionInternal
monitorOT_STRINGVECTORSet of user problem functions to be monitoredcasadi::OracleFunction
never_inlineOT_BOOLForbid inlining.casadi::FunctionInternal
output_schemeOT_STRINGVECTORDeprecated option (ignored)casadi::FunctionInternal
post_expandOT_BOOLAfter construction, expand this Function. Default: Falsecasadi::FunctionInternal
post_expand_optionsOT_DICTOptions to be passed to post-construction expansion. Default: emptycasadi::FunctionInternal
print_inOT_BOOLPrint numerical values of inputs [default: false]casadi::FunctionInternal
print_outOT_BOOLPrint numerical values of outputs [default: false]casadi::FunctionInternal
print_timeOT_BOOLprint information about execution time. Implies record_time.casadi::ProtoFunction
record_timeOT_BOOLrecord information about execution time, for retrieval with stats().casadi::ProtoFunction
regularity_checkOT_BOOLThrow exceptions when NaN or Inf appears during evaluationcasadi::ProtoFunction
reverse_optionsOT_DICTOptions to be passed to a reverse mode constructorcasadi::FunctionInternal
show_eval_warningsOT_BOOLShow warnings generated from function evaluations [true]casadi::OracleFunction
specific_optionsOT_DICTOptions for specific auto-generated functions, overwriting the defaults from common_options. Nested dictionary.casadi::OracleFunction
user_dataOT_VOIDPTRA user-defined field that can be used to identify the function or pass additional informationcasadi::FunctionInternal
verboseOT_BOOLVerbose evaluation – for debuggingcasadi::ProtoFunction

Input scheme: casadi::RootfinderInput (ROOTFINDER_NUM_IN = 2)
Full nameShortDescription
ROOTFINDER_X0x0Initial guess for the solution.
ROOTFINDER_PpParameters.

Output scheme: casadi::RootfinderOutput (ROOTFINDER_NUM_OUT = 1)
Full nameShortDescription
ROOTFINDER_XxSolution to the system of equations.

List of plugins

- kinsol

- fast_newton

- nlpsol

- newton

Note: some of the plugins in this list might not be available on your system. Also, there might be extra plugins available to you that are not listed here. You can obtain their documentation with Rootfinder.doc("myextraplugin")


kinsol

KINSOL interface from the Sundials suite

Extra doc: https://github.com/casadi/casadi/wiki/L_226


List of available options
IdTypeDescription
abstolOT_DOUBLEStopping criterion tolerance
disable_internal_warningsOT_BOOLDisable KINSOL internal warning messages
exact_jacobianOT_BOOLUse exact Jacobian information
f_scaleOT_DOUBLEVECTOREquation scaling factors
iterative_solverOT_STRINGgmres|bcgstab|tfqmr
linear_solver_typeOT_STRINGdense|banded|iterative|user_defined
lower_bandwidthOT_INTLower bandwidth for banded linear solvers
max_iterOT_INTMaximum number of Newton iterations. Putting 0 sets the default value of KinSol.
max_krylovOT_INTMaximum Krylov space dimension
pretypeOT_STRINGType of preconditioner
print_levelOT_INTVerbosity level
strategyOT_STRINGGlobalization strategy
u_scaleOT_DOUBLEVECTORVariable scaling factors
upper_bandwidthOT_INTUpper bandwidth for banded linear solvers
use_preconditionerOT_BOOLPrecondition an iterative solver

fast_newton

Implements simple newton iterations to solve an implicit function.

Extra doc: https://github.com/casadi/casadi/wiki/L_237


List of available options
IdTypeDescription
abstolOT_DOUBLEStopping criterion tolerance on ||g||__inf)
abstolStepOT_DOUBLEStopping criterion tolerance on step size
max_iterOT_INTMaximum number of Newton iterations to perform before returning.

nlpsol


newton

Implements simple newton iterations to solve an implicit function.

Extra doc: https://github.com/casadi/casadi/wiki/L_236


List of available options
IdTypeDescription
abstolOT_DOUBLEStopping criterion tolerance on max(|F|)
abstolStepOT_DOUBLEStopping criterion tolerance on step size
line_searchOT_BOOLEnable line-search (default: true)
max_iterOT_INTMaximum number of Newton iterations to perform before returning.
print_iterationOT_BOOLPrint information about each iteration
Author
Joel Andersson
Date
2011-2015

Extra doc: https://github.com/casadi/casadi/wiki/L_21r

Function Documentation

◆ doc_rootfinder()

CASADI_EXPORT std::string casadi::doc_rootfinder ( const std::string &  name)

◆ has_rootfinder()

CASADI_EXPORT bool casadi::has_rootfinder ( const std::string &  name)

◆ load_rootfinder()

CASADI_EXPORT void casadi::load_rootfinder ( const std::string &  name)

◆ rootfinder() [1/3]

CASADI_EXPORT Function casadi::rootfinder ( const std::string &  name,
const std::string &  solver,
const Function f,
const Dict opts = Dict() 
)

◆ rootfinder() [2/3]

CASADI_EXPORT Function casadi::rootfinder ( const std::string &  name,
const std::string &  solver,
const MXDict rfp,
const Dict opts = Dict() 
)

◆ rootfinder() [3/3]

CASADI_EXPORT Function casadi::rootfinder ( const std::string &  name,
const std::string &  solver,
const SXDict rfp,
const Dict opts = Dict() 
)

◆ rootfinder_in() [1/2]

CASADI_EXPORT std::vector<std::string> casadi::rootfinder_in ( )

◆ rootfinder_in() [2/2]

CASADI_EXPORT std::string casadi::rootfinder_in ( casadi_int  ind)

◆ rootfinder_n_in()

CASADI_EXPORT casadi_int casadi::rootfinder_n_in ( )

◆ rootfinder_n_out()

CASADI_EXPORT casadi_int casadi::rootfinder_n_out ( )

◆ rootfinder_option_info()

CASADI_EXPORT std::string casadi::rootfinder_option_info ( const std::string &  name,
const std::string &  op 
)

◆ rootfinder_option_type()

CASADI_EXPORT std::string casadi::rootfinder_option_type ( const std::string &  name,
const std::string &  op 
)

◆ rootfinder_options()

CASADI_EXPORT std::vector<std::string> casadi::rootfinder_options ( const std::string &  name)

◆ rootfinder_out() [1/2]

CASADI_EXPORT std::vector<std::string> casadi::rootfinder_out ( )

◆ rootfinder_out() [2/2]

CASADI_EXPORT std::string casadi::rootfinder_out ( casadi_int  ind)