Skip to content

Commit

Permalink
Attempt to use fDer instead of f_der since the other option doesn't l…
Browse files Browse the repository at this point in the history
…ook nice in pdf.
  • Loading branch information
HansOlsson committed Feb 23, 2021
1 parent a3d6552 commit e40ff93
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions chapters/functions.tex
Expand Up @@ -1360,9 +1360,9 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati
Assume that function \lstinline!f! takes a matrix and a scalar.
Since the matrix argument is usually a parameter expression it is then
useful to define the function as follows (the additional derivative =
\lstinline!f_general_der! is optional and can be used when the derivative of
the matrix or offset is non-zero). Note that \lstinline!f_der! must have
\lstinline!zeroDerivative! for both \lstinline!y! and \lstinline!offset!, but \lstinline!f_general_der! shall not have
\lstinline!fGeneralDer! is optional and can be used when the derivative of
the matrix or offset is non-zero). Note that \lstinline!fDer! must have
\lstinline!zeroDerivative! for both \lstinline!y! and \lstinline!offset!, but \lstinline!fGeneralDer! shall not have
\lstinline!zeroDerivative! for either of them (it may \lstinline!zeroDerivative! for \lstinline!x_der!,
\lstinline!y_der!, or \lstinline!offset_der!).

Expand All @@ -1374,22 +1374,22 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati
output Real z;
algorithm
$\ldots$
annotation(derivative(zeroDerivative=y, zeroDerivative=offset)= f_der,
derivative=f_general_der);
annotation(derivative(zeroDerivative=y, zeroDerivative=offset)= fDer,
derivative=fGeneralDer);
end f;

function f_der "Derivative of simple table lookup"
function fDer "Derivative of simple table lookup"
input Real x;
input Real y[:, 2];
input Real offset;
input Real x_der;
output Real z_der;
algorithm
$\ldots$
annotation(derivative(zeroDerivative=y, zeroDerivative=offset, order=2) = f_der2);
end f_der;
annotation(derivative(zeroDerivative=y, zeroDerivative=offset, order=2) = fDer2);
end fDer;

function f_der2 "Second derivative of simple table lookup"
function fDer2 "Second derivative of simple table lookup"
input Real x;
input Real y[:, 2];
input Real offset;
Expand All @@ -1398,9 +1398,9 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati
output Real z_der2;
algorithm
$\ldots$
end f_der2;
end fDer2;

function f_general_der "Derivative of table lookup taking
function fGeneralDer "Derivative of table lookup taking
into account varying tables"
input Real x;
input Real y[:, 2];
Expand All @@ -1411,14 +1411,15 @@ \subsection{Using the Derivative Annotation}\label{using-the-derivative-annotati
output Real z_der;
algorithm
$\ldots$
//annotation(derivative(order=2) = f_general_der2);
end f_general_der;
//annotation(derivative(order=2) = fGeneralDer2);
end fGeneralDer;
\end{lstlisting}
In the example above \lstinline!zeroDerivative=y! and \lstinline!zeroDerivative=offset! imply that
\begin{eqnarray*}
\frac{d}{dt}f(x(t),y(t),o(t))&=&\frac{\partial f}{\partial x}\frac{dx}{dt}+\frac{\partial f}{\partial y}\frac{dy}{dt}+\frac{\partial f}{\partial o}\frac{do}{dt}\\
&=&\frac{\partial f}{\partial x}\frac{dx}{dt}+\frac{\partial f}{\partial y}\cdot 0+\frac{\partial f}{\partial o}\cdot 0\\
&=&\frac{\partial f}{\partial x}\frac{dx}{dt}
&=&\frac{\partial f}{\partial x}\frac{dx}{dt}\\
&=&fDer\cdot\frac{dx}{dt}
\end{eqnarray*}
\end{nonnormative}

Expand Down

0 comments on commit e40ff93

Please sign in to comment.