From 18a9e9445fb8305811c020918b3ff8dc3d3092e5 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Thu, 13 Oct 2016 11:07:42 +0200 Subject: [PATCH] [translation] break, continue and exercises --- programming/lecture/programming.tex | 49 ++++++++++++++--------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/programming/lecture/programming.tex b/programming/lecture/programming.tex index 1a891b3..6779b5f 100644 --- a/programming/lecture/programming.tex +++ b/programming/lecture/programming.tex @@ -1223,14 +1223,14 @@ end \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 -werden, werden die Schl\"usselworte \code{break} und -\code{continue} eingesetzt (Listings \ref{continuelisting} -und \ref{continuelisting} zeigen, wie sie eingesetzt werden k\"onnen). +Whenever the execution of a loop should be ended or if you want to +skip the execution of the body under certain circumstances, one can +use the keywords \code{break} and \code{continue} +(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; while true if (x > 3) @@ -1245,7 +1245,7 @@ und \ref{continuelisting} zeigen, wie sie eingesetzt werden k\"onnen). 3 \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 if(x > 2 & x < 5) continue; @@ -1259,32 +1259,29 @@ end \end{lstlisting} \begin{exercise}{logicalIndexingBenchmark.m}{logicalIndexingBenchmark.out} - Vergleich von logischem Indizieren und ``manueller'' Auswahl von - Elementen aus einem Vektor. Es wurde oben behauptet, dass die - Auswahl von Elementen mittels logischem Indizieren effizienter - ist. Teste dies indem ein Vektor mit vielen (100000) Zufallszahlen - erzeugt wird aus dem die Elemente gefiltert und gespeichert werden, - die kleiner $0.5$ sind. Umgebe den Programmabschnitt mit den - Br\"udern \code{tic} und \code{toc}. Auf diese Weise misst \matlab{} - die zwischen \code{tic} und \code{toc} vergangene Zeit. + Above we claimed the logical indexing is faster that manual + selection of element of a vector. By now we have all the tools at + hand to test this. \\ + For this test create a large vector with 100000 (or more) random + numbers. Filter from this vector all numbers that are less than 0.5 + and copy them to a second vector. Surround you code with the brother + \code{tic} and \code{toc} to have \matlab{} measure the time that + has passed between the calls of \code{tic} and \code{toc}. \begin{enumerate} - \item Benutze eine \code{for} Schleife um die Elemente auszuw\"ahlen. - \item Benutze logisches Indizieren. + \item Use a \code{for} loop to select the matching values. + \item Use logical indexing. \end{enumerate} \end{exercise} \begin{exercise}{simplerandomwalk.m}{} - Programmiere einen 1-D random walk. Ausgehend von der Startposition - $0$ ``l\"auft'' ein Agent zuf\"allig in die eine oder andere - Richtung. + Implement a 1-D random walk: Starting from the initial position $0$ + the agent takes a step in a random direction. \begin{itemize} - \item In dem Programm sollen 10 Realisationen eines random walk mit - jeweils 1000 Schritten durchgef\"uhrt werden. - \item Die Position des Objektes ver\"andert sich in jedem Schritt zuf\"allig um - $+1$ oder $-1$. - \item Merke Dir alle Positionen. - \item Plotte die Positionen als Funktion der Schrittnummer. + \item The program should do 10 random walks with 1000 steps each. + \item With each step decide randomly whether the position is changed by $+1$ or $-1$. + \item Store all positions. + \item Create a figure in which you plot the position as a function of the steps. \end{itemize} \end{exercise}