% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/adjointDiscrete.R
\name{.rxDiscreteAdjointGrad}
\alias{.rxDiscreteAdjointGrad}
\title{Discrete adjoint gradient of a trajectory objective}
\usage{
.rxDiscreteAdjointGrad(
  build,
  stages,
  params,
  h,
  obsSteps,
  cov,
  doses = NULL,
  lam0Cov = NULL
)
}
\arguments{
\item{build}{object from \code{\link[=.rxDiscreteAdjointBuild]{.rxDiscreteAdjointBuild()}}.}

\item{stages}{RK4 stage list from \code{\link[=.rxDiscreteForwardSens]{.rxDiscreteForwardSens()}}.}

\item{params}{named numeric parameter vector.}

\item{h}{fixed step size (same as the forward solve).}

\item{obsSteps}{integer step indices at which observation covectors apply.}

\item{cov}{list of covector vectors (length \code{ns}), aligned with \code{obsSteps}.}

\item{doses}{optional list of additive-bolus dose specs (same format as
\code{\link[=.rxDiscreteForwardSens]{.rxDiscreteForwardSens()}}); the exact transpose of the forward dose jump
is applied, contributing \code{amt * dF/dtheta * lambda_c} to \code{dG/dtheta}.}

\item{lam0Cov}{optional initial-condition sensitivity \code{dX0/dtheta} (\verb{ns x np})
to add the terminal transversality \verb{lambda(t0)^T dX0/dtheta}; default none.}
}
\value{
named numeric vector \code{dG/dtheta} over \code{build$calcSens}.
}
\description{
Given the RK4 stages from \code{\link[=.rxDiscreteForwardSens]{.rxDiscreteForwardSens()}} and, per observation
step, the objective covector \verb{c_n = dG/dX_\{step_n\}}, computes \code{dG/dtheta} by
reverse-mode differentiation through the RK4 steps -- equal to
\verb{sum_n c_n^T S_\{step_n\}} to machine precision, in one backward pass.
}
\author{
Matthew L. Fidler
}
\keyword{internal}
