Skip to content

Commit

Permalink
Describe derivative.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed Feb 19, 2021
1 parent 818dd38 commit 32ec498
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion chapters/functions.tex
Expand Up @@ -1176,13 +1176,36 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati
The \lstinline!derivative! annotation can influence simulation time and accuracy and can be applied to both functions written in Modelica and to external functions.
A \lstinline!derivative! annotation can state that it is only valid under certain restrictions on the input arguments.
These restrictions are defined using the following optional attributes: \lstinline!order! (only a restriction if $\text{\lstinline!order!} > 1$, the default for \lstinline!order! is 1), \lstinline!noDerivative!, and \lstinline!zeroDerivative!.
The given derivative-function can only be used to compute the derivative of a function call if these restrictions are satisfied.
The given derivative-function must be a valid derivative if these restrictions are satisfied, and can thus be used to compute the derivative in those cases.
There may be multiple restrictions on the derivative, in which case they must all be satisfied. The restrictions also imply that some derivatives of some inputs are excluded from the call of the derivative (since they are not necessary).
A function may supply multiple derivative functions subject to different restrictions, the first one that can be used (i.e.\ satisfying the restrictions) will be used for each call.

\begin{nonnormative}
This means that the most restrictive derivatives should be written first.
\end{nonnormative}
\begin{nonnormative}
A straightforward way of explaining a valid derivative is given by this model.
The function value, \lstinline!x1!, should up to numerical precision match the integral of the derivative, \lstinline!x2!.
Note that in practive tools may over-optimize this.
\begin{lstlisting}[language=modelica]
function f
input Real x;
output Real y;
annotation(derivative=fder);
external "C";
end f;
model M
input Real u;
Real x1 "Directly from function";
Real x2 "Integrated from derivative";
equation
x1 = f(u);
der(x2) = der(x1);
initial equation
x2=x1;
end M;
\end{lstlisting}
\end{nonnormative}

\begin{example}
\begin{lstlisting}[language=modelica]
Expand Down

0 comments on commit 32ec498

Please sign in to comment.