improved indices

This commit is contained in:
2019-12-10 00:09:48 +01:00
parent bf52536b7b
commit c063cc9f0e
6 changed files with 175 additions and 164 deletions

View File

@@ -1177,11 +1177,11 @@ segment of data of a certain time span (the stimulus was on,
required. \codeterm[Timetable]{Timetables} offer specific
convenience functions to work with timestamps.
\textbf{Maps} In a \codeterm{map} a \codeterm{value} is associated
with an arbitrary \codeterm{key}. The \codeterm{key} is not
restricted to be an integer but can be almost anything. Maps are an
alternative to structures with the additional advantage that the key
can be used during indexing: \varcode{my\_map('key')}.
\textbf{Maps} In a \code{containers.Map} a \entermde{Wert}{value} is
associated with an arbitrary \entermde{Schl\"ussel}{key}. The key is
not restricted to be an integer but can be almost anything. Maps are
an alternative to structures with the additional advantage that the
key can be used for indexing: \varcode{my\_map('key')}.
\textbf{Categorical arrays} are used to stored values that come from
a limited set of values, e.g. Months. Such categories can then be
@@ -1251,18 +1251,19 @@ used whenever the same commands have to be repeated.
\subsubsection{The \varcode{for} --- loop}
The most common type of loop is the \codeterm{for-loop}. It
consists of a \codeterm[Loop!head]{head} and the
\codeterm[Loop!body]{body}. The head defines how often the code in the
body is executed. In \matlab{} the head begins with the keyword
\code{for} which is followed by the \codeterm{running variable}. In
\matlab{} a for-loop always operates on vectors. With each
\codeterm{iteration} of the loop, the running variable assumes the
next value of this vector. In the body of the loop any code can be
executed which may or may not use the running variable for a certain
purpose. The \code{for} loop is closed with the keyword
The most common type of loop is the
\entermde{For-Schleife}{for-loop}. It consists of a head and the
body. The head defines how often the code in the body is executed. In
\matlab{} a for-loop always operates on vectors. The head of the
\varcode{for}-loop begins with the keyword \code{for} which is
followed by the \enterm[for-loop!running variable]{running variable}
to which a vector is assigned. With each
\entermde{Iteration}{iteration} of the loop, the running variable
assumes the next value of this vector. In the body of the loop any
code can be executed which may or may not use the running variable for
a certain purpose. The \varcode{for}-loop is closed with the keyword
\code{end}. Listing~\ref{looplisting} shows a simple version of such a
\codeterm{for-loop}.
for-loop.
\begin{lstlisting}[caption={Example of a \varcode{for}-loop.}, label=looplisting]
>> for x = 1:3 % head
@@ -1284,14 +1285,14 @@ purpose. The \code{for} loop is closed with the keyword
\subsubsection{The \varcode{while} --- loop}
The \codeterm{while-loop} is the second type of loop that is available in
almost all programming languages. Other, than the \codeterm{for-loop},
that iterates with the running variable over a vector, the while loop
uses a Boolean expression to determine when to execute the code in
it's body. The head of the loop starts with the keyword \code{while}
that is followed by a Boolean expression. If this can be evaluated to
true, the code in the body is executed. The loop is closed with an
\code{end}.
The \entermde{While-Schleife}{while-loop} is the second type of loop
that is available in almost all programming languages. Other than the
\varcode{for}-loop, that iterates with the running variable over a
vector, the while loop uses a Boolean expression to determine when to
execute the code in it's body. The head of the loop starts with the
keyword \code{while} that is followed by a Boolean expression. If this
can be evaluated to true, the code in the body is executed. The loop
is closed with an \code{end}.
\begin{lstlisting}[caption={Basic structure of a \varcode{while} loop.}, label=whileloop]
while x == true % head with a Boolean expression
@@ -1303,7 +1304,6 @@ end
Implement the factorial of a number \varcode{n} using a \varcode{while}-loop.
\end{exercise}
\begin{exercise}{neverendingWhile.m}{}
Implement a \varcode{while}-loop that is never-ending. Hint: the
body is executed as long as the Boolean expression in the head is
@@ -1316,15 +1316,15 @@ end
\begin{itemize}
\item Both execute the code in the body iterative.
\item When using a \code{for}-loop the body of the loop is executed
\item When using a \varcode{for}-loop the body of the loop is executed
at least once (except when the vector used in the head is empty).
\item In a \code{while}-loop, the body is not necessarily
\item In a \varcode{while}-loop, the body is not necessarily
executed. It is entered only if the Boolean expression in the head
yields true.
\item The \code{for}-loop is best suited for cases in which the
\item The \varcode{for}-loop is best suited for cases in which the
elements of a vector have to be used for a computation or when the
number of iterations is known.
\item The \code{while}-loop is best suited for cases when it is not
\item The \varcode{while}-loop is best suited for cases when it is not
known in advance how often a certain piece of code has to be
executed.
\item Any problem that can be solved with one type can also be solve
@@ -1334,25 +1334,24 @@ end
\subsection{Conditional expressions}
The conditional expression are used to control that the enclosed code
is only executed under a certain condition.
With a \enterm{conditional expression} (\determ{bedingte Anweisung})
the enclosed code is only executed under a certain condition.
\subsubsection{The \varcode{if} -- statement}
The most prominent representative of the conditional expressions is
the \codeterm{if statement} (sometimes also called \codeterm{if - else
statement}). It constitutes a kind of branching point. It allows to
control which branch of the code is executed.
the \code{if} statement. It constitutes a kind of branching point. It
allows to control which branch of the code is executed.
Again, the statement consists of the head and the body. The head
begins with the keyword \code{if} followed by a Boolean expression
begins with the keyword \code{if} followed by a boolean expression
that controls whether or not the body is entered. Optionally, the body
can be either ended by the \code{end} keyword or followed by
additional statements \code{elseif}, which allows to add another
Boolean expression and to catch another condition or the \code{else}
the provide a default case. The last body of the \varcode{if - elseif -
else} statement has to be finished with the \code{end}
(listing~\ref{ifelselisting}).
additional \code{elseif} statements, that allow to add further boolean
expressions and to catch other conditions, or the \code{else}
expression to provide a default case. The last body of the
\varcode{if} - \varcode{elseif} - \varcode{else} statement has to be
finished with the \code{end} (listing~\ref{ifelselisting}).
\begin{lstlisting}[label=ifelselisting, caption={Structure of an \varcode{if} statement.}]
if x < y % head
@@ -1377,17 +1376,18 @@ end
\subsubsection{The \varcode{switch} -- statement}
The \codeterm{switch statement} is used whenever a set of conditions
The \code{switch} statement is used whenever a set of conditions
requires separate treatment. The statement is initialized with the
\code{switch} keyword that is followed by a \emph{switch expression} (a
number or string). It is followed by a set of \emph{case expressions}
which start with the keyword \code{case} followed by the condition
that defines against which the \emph{switch expression} is tested. It
is important to note that the case expression always checks for
equality! Optional the case expressions may be followed by the keyword
\code{otherwise} which catches all cases that were not explicitly
stated above (listing~\ref{switchlisting}).
\code{switch} keyword that is followed by a \emph{switch expression}
returning a number or string. It is followed by a set of \emph{case
expressions} which start with the keyword \code{case} followed by
the condition that defines against which the \emph{switch expression}
is tested. It is important to note that the \emph{case expression}
always checks for equality! Optional the \emph{case expressions} may
be followed by the keyword \code{otherwise} which catches all cases
that were not explicitly stated above (listing~\ref{switchlisting}).
As usual the \code{switch} statement needs to be closed with an
\code{end}.
\begin{lstlisting}[label=switchlisting, caption={Structure of a \varcode{switch} statement.}]
mynumber = input('Enter a number:');
@@ -1406,7 +1406,7 @@ end
\begin{itemize}
\item Using the \code{if} statement one can test for arbitrary cases
and treat them separately.
\item The \code{switch} statement does something similar but is always
\item The \code{switch} statement does something similar but always
checks for the equality of \emph{switch} and \emph{case}
expressions.
\item The \code{switch} is a little bit more compact and nicer to read
@@ -1610,10 +1610,10 @@ define (i) how to name the function, (ii) which information it needs
(arguments), and (iii) what it should return to the caller.
\begin{enumerate}
\item \entermde[function!name]{Funktion!-sname}{Name}: the name should be descriptive
\item \entermde[function!name]{Funktionsname}{Name}: the name should be descriptive
of the function's purpose, i.e. the calculation of a sine wave. A
appropriate name might be \varcode{sinewave()}.
\item \entermde[function!arguments]{Funktion!-sargument}{Arguments}:
\item \entermde[function!arguments]{Funktionsargument}{Arguments}:
What information does the function need to do the calculation? There
are obviously the frequency as well as the amplitude. Further we may
want to be able to define the duration of the sine wave and the