% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rxJacobian.R
\name{.rxAdjoint}
\alias{.rxAdjoint}
\title{Adjoint (backward) sensitivity equations for a model}
\usage{
.rxAdjoint(model, vars, states)
}
\arguments{
\item{model}{symengine model environment (as returned by \code{rxS}), with
\code{.rxJacobian(model, c(rxStateOde(model), vars))} already called.}

\item{vars}{character vector of parameter names to differentiate with
respect to (the \code{p} in \code{dy/dp}).  Defaults to \code{model$..vars}.}

\item{states}{character vector of output states of interest (the \code{k}).
Defaults to all ODE states, matching the full coverage of forward
sensitivities.}
}
\value{
character vector of \code{d/dt(...) = ...} lines (costate block followed
by quadrature block).  The costate (\verb{rx__adjLambda_*}) lines are internal
scaffolding; only the quadrature (\verb{rx__sens_*}) lines carry user-visible
output.  Also stashes the result in \code{model$..adjoint}.
}
\description{
Symbolically generates the continuous-adjoint ODE system mirroring the
forward sensitivity output (\code{.rxSens}), reusing the same
\verb{rx__sens_<state>_BY_<param>__} output names.  For each output state \code{k} it
emits two backward-in-time blocks: a costate
\verb{d/dt(rx__adjLambda_<k>_<i>__) = -(J^T lambda)_i} and a quadrature
\verb{d/dt(rx__sens_<k>_BY_<p>__) = -(lambda^T df/dp)_p}.  The derivatives are
taken from the \verb{rx__df_*} symbols \code{.rxJacobian()} already materialised, so no
new differentiation is done; the costate symbols are registered as bare
symengine \code{Symbol}s.
}
\author{
Matthew L. Fidler
}
\keyword{internal}
