[translation] break, continue and exercises

This commit is contained in:
Jan Grewe 2016-10-13 11:07:42 +02:00
parent 014b141ad1
commit 18a9e9445f

View File

@ -1223,14 +1223,14 @@ end
\end{itemize} \end{itemize}
\subsection{Die Schl\"usselworte \code{break} und \code{continue}} \subsection{The keywords \code{break} and \code{continue}}
Soll die Ausf\"uhrung einer Schleife abgebrochen oder \"ubersprungen Whenever the execution of a loop should be ended or if you want to
werden, werden die Schl\"usselworte \code{break} und skip the execution of the body under certain circumstances, one can
\code{continue} eingesetzt (Listings \ref{continuelisting} use the keywords \code{break} and \code{continue}
und \ref{continuelisting} zeigen, wie sie eingesetzt werden k\"onnen). (listings~\ref{continuelisting} and \ref{continuelisting}).
\begin{lstlisting}[caption={Abbrechen von Schleifen mit \varcode{break}.}, label=breaklisting] \begin{lstlisting}[caption={Stop the execution of a loop using \varcode{break}.}, label=breaklisting]
>> x = 1; >> x = 1;
while true while true
if (x > 3) if (x > 3)
@ -1245,7 +1245,7 @@ und \ref{continuelisting} zeigen, wie sie eingesetzt werden k\"onnen).
3 3
\end{lstlisting} \end{lstlisting}
\begin{lstlisting}[caption={\"Uberspringen von Code-Abschnitten in Schleifen mit \varcode{continue}.}, label=continuelisting] \begin{lstlisting}[caption={Skipping iterations using \varcode{continue}.}, label=continuelisting]
for x = 1:5 for x = 1:5
if(x > 2 & x < 5) if(x > 2 & x < 5)
continue; continue;
@ -1259,32 +1259,29 @@ end
\end{lstlisting} \end{lstlisting}
\begin{exercise}{logicalIndexingBenchmark.m}{logicalIndexingBenchmark.out} \begin{exercise}{logicalIndexingBenchmark.m}{logicalIndexingBenchmark.out}
Vergleich von logischem Indizieren und ``manueller'' Auswahl von Above we claimed the logical indexing is faster that manual
Elementen aus einem Vektor. Es wurde oben behauptet, dass die selection of element of a vector. By now we have all the tools at
Auswahl von Elementen mittels logischem Indizieren effizienter hand to test this. \\
ist. Teste dies indem ein Vektor mit vielen (100000) Zufallszahlen For this test create a large vector with 100000 (or more) random
erzeugt wird aus dem die Elemente gefiltert und gespeichert werden, numbers. Filter from this vector all numbers that are less than 0.5
die kleiner $0.5$ sind. Umgebe den Programmabschnitt mit den and copy them to a second vector. Surround you code with the brother
Br\"udern \code{tic} und \code{toc}. Auf diese Weise misst \matlab{} \code{tic} and \code{toc} to have \matlab{} measure the time that
die zwischen \code{tic} und \code{toc} vergangene Zeit. has passed between the calls of \code{tic} and \code{toc}.
\begin{enumerate} \begin{enumerate}
\item Benutze eine \code{for} Schleife um die Elemente auszuw\"ahlen. \item Use a \code{for} loop to select the matching values.
\item Benutze logisches Indizieren. \item Use logical indexing.
\end{enumerate} \end{enumerate}
\end{exercise} \end{exercise}
\begin{exercise}{simplerandomwalk.m}{} \begin{exercise}{simplerandomwalk.m}{}
Programmiere einen 1-D random walk. Ausgehend von der Startposition Implement a 1-D random walk: Starting from the initial position $0$
$0$ ``l\"auft'' ein Agent zuf\"allig in die eine oder andere the agent takes a step in a random direction.
Richtung.
\begin{itemize} \begin{itemize}
\item In dem Programm sollen 10 Realisationen eines random walk mit \item The program should do 10 random walks with 1000 steps each.
jeweils 1000 Schritten durchgef\"uhrt werden. \item With each step decide randomly whether the position is changed by $+1$ or $-1$.
\item Die Position des Objektes ver\"andert sich in jedem Schritt zuf\"allig um \item Store all positions.
$+1$ oder $-1$. \item Create a figure in which you plot the position as a function of the steps.
\item Merke Dir alle Positionen.
\item Plotte die Positionen als Funktion der Schrittnummer.
\end{itemize} \end{itemize}
\end{exercise} \end{exercise}