Skip to content

Commit

Permalink
Misc style cleanup of matrix and vector algebra functions and constru…
Browse files Browse the repository at this point in the history
…ctors
  • Loading branch information
henrikt-ma committed Jun 16, 2020
1 parent 32f8c4f commit 6f85e67
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 31 deletions.
76 changes: 46 additions & 30 deletions chapters/arrays.tex
Expand Up @@ -493,59 +493,75 @@ \subsubsection{Reduction Expressions}\doublelabel{reduction-expressions}

\subsection{Matrix and Vector Algebra Functions}\doublelabel{matrix-and-vector-algebra-functions}

The following set of built-in matrix and vector algebra functions are
available. The function transpose and symmetric can be applied to any matrix. The
functions outerProduct, cross and skew require Real/Integer
vector(s) or matrix as input(s) and returns a Real/Integer vector or matrix (the result is only Integer
if the input/all inputs are Integer):
The following set of built-in matrix and vector algebra functions are available. The function transpose and symmetric can be applied to any matrix.
The functions \lstinline!outerProduct!, \lstinline!cross! and \lstinline!skew! require \lstinline!Real!/\lstinline!Integer! vector(s) or matrix as input(s)
and returns a \lstinline!Real!/\lstinline!Integer! vector or matrix (the result is only \lstinline!Integer! if the input/all inputs are \lstinline!Integer!):
\begin{longtable}[]{|p{3.5cm}|p{11.5cm}|}
\caption{Matrix and vector algebra functions.}\\
\hline
\tablehead{Modelica} & \tablehead{Explanation}\\ \hline
\endhead
\lstinline!transpose(A)!
& Permutes the first two dimensions of array A. It is an error, if array A
& Permutes the first two dimensions of array \lstinline!A!. It is an error, if array \lstinline!A!
does not have at least 2 dimensions.\\ \hline
\lstinline!outerProduct(v1,v2)!
& Returns the outer product of vectors v1 and v2 ( = matrix(v1)*transpose(
matrix(v2) ) ).\\ \hline
\lstinline!outerProduct(v1, v2)!
&
\begin{tabular}{@{}p{10cm}@{}}
Returns the outer product of vectors \lstinline!v1! and \lstinline!v2!:\\
\lstinline!= matrix(v1) * transpose(matrix(v2))!
\end{tabular}\\ \hline
\lstinline!symmetric(A)!
& Returns a symmetric matrix which is identical to the square matrix \lstinline!A!
on and above the diagonal, i.e., \lstinline!B := symmetric(A) ->!
\lstinline!B[i,j] := A[i,j], if i <= j, ! \lstinline! B[i,j] := A[j,i], if i > j!.\\ \hline
\lstinline!cross(x,y)!
& Returns the cross product of the 3-vectors x and y, i.e.
\lstinline!cross(x,y) = vector( [ x[2]*y[3]-x[3]*y[2]; x[3]*y[1]-x[1]*y[3]; x[1]*y[2]-x[2]*y[1] ] );!\\ \hline
on and above the diagonal, i.e., \lstinline!B := symmetric(A)! implies
\begin{equation*}
\text{\lstinline[mathescape=true]!B[$i$, $j$]!} =
\begin{cases}
\text{\lstinline[mathescape=true]!A[$i$, $j$]!} & \text{if $i \leq j$}\\
\text{\lstinline[mathescape=true]!A[$j$, $i$]!} & \text{if $i > j$}
\end{cases}
\end{equation*}\\ \hline
\lstinline!cross(x, y)!
&
\begin{tabular}{@{}p{10cm}@{}}
Returns the cross product of the 3-vectors \lstinline!x! and \lstinline!y!:
\begin{lstlisting}[frame=none,aboveskip=-\parskip,belowskip=-\medskipamount]
= vector([ x[2] * y[3] - x[3] * y[2];
x[3] * y[1] - x[1] * y[3];
x[1] * y[2] - x[2] * y[1] ])
\end{lstlisting}
\end{tabular}\\ \hline
\lstinline!skew(x)!
& Returns the 3 x 3 skew symmetric matrix associated with a 3-vector,
i.e., \lstinline!cross(x,y) = skew(x)*y; skew(x) = [0, -x[3], x[2]; x[3], 0, -x[1]; -x[2], x[1], 0];!\\ \hline
&
\begin{tabular}{@{}p{10cm}@{}}
Returns the $3 \times 3$ skew symmetric matrix associated with a 3-vector, i.e., \lstinline!cross(x, y) = skew(x) * y!, or --- equivalently --- \lstinline!skew(x)!
\begin{lstlisting}[frame=none,aboveskip=-\parskip,belowskip=-\medskipamount]
= [ 0, -x[3], x[2] ;
x[3], 0, -x[1] ;
-x[2], x[1], 0 ]
\end{lstlisting}
\end{tabular}\\ \hline
\end{longtable}

\section{Vector, Matrix and Array Constructors}\doublelabel{vector-matrix-and-array-constructors}

The constructor function \lstinline!array(A,B,C,...)! constructs an array from its
arguments according to the following rules:
The constructor function \lstinline[mathescape=true]!array(A, B, C, $\ldots$)! constructs an array from its arguments according to the following rules:
\begin{itemize}
\item
Size matching: All arguments must have the same sizes, i.e.,
\lstinline!size(A)=size(B)=size(C)=!...
\lstinline!size(A)! = \lstinline!size(B)! = \lstinline!size(C)! = \ldots
\item
All arguments must be type compatible expressions (\autoref{type-compatible-expressions}) giving
the type of the elements. The data type of the result array is the
maximally expanded type of the arguments. Real and Integer subtypes
can be mixed resulting in a Real result array where the Integer
numbers have been transformed to Real numbers.
All arguments must be type compatible expressions (\autoref{type-compatible-expressions}) giving the type of the elements. The data type of the result array is the
maximally expanded type of the arguments. \lstinline!Real! and \lstinline!Integer! subtypes can be mixed resulting in a \lstinline!Real! result array where the
\lstinline!Integer! numbers have been transformed to \lstinline!Real! numbers.
\item
Each application of this constructor function adds a one-sized
dimension to the left in the result compared to the dimensions of the
argument arrays, i.e., \lstinline!ndims(array(A,B,C)) = ndims(A) + 1 = ndims(B) + 1, ...!
Each application of this constructor function adds a one-sized dimension to the left in the result compared to the dimensions of the argument arrays, i.e.,
\lstinline[mathescape=true]!ndims(array(A, B, C)) = ndims(A) + 1 = ndims(B) + 1, $\ldots$!
\item
\lstinline!{A, B, C, ...}! is a shorthand notation for \lstinline!array(A, B, C, ...)!.
\lstinline[mathescape=true]!{A, B, C, $\ldots$}! is a shorthand notation for \lstinline[mathescape=true]!array(A, B, C, $\ldots$)!.
\item
There must be at least one argument.
\begin{nonnormative}
The reason \lstinline!array()! or \lstinline!{}! is not defined is that at least one argument is
needed to determine the type of the resulting array.
The reason \lstinline!array()! or \lstinline!{}! is not defined is that at least one argument is needed to determine the type of the resulting array.
\end{nonnormative}
\end{itemize}

Expand Down
3 changes: 2 additions & 1 deletion preamble.tex
Expand Up @@ -213,7 +213,8 @@

\lstset{ %
backgroundcolor=\color{white}, % choose the background color
breaklines=true, % automatic line breaking only at whitespace
breaklines=true, % automatic line breaking only at whitespace
keepspaces, % don't remove space such as those after closing parenthesis
captionpos=b, % sets the caption-position to bottom
commentstyle=\color[rgb]{0,0.4,0}\sffamily, % comment style
keywordstyle=\color{blue}\ttfamily\bfseries, % keyword style
Expand Down

0 comments on commit 6f85e67

Please sign in to comment.