[translation] what is a program?
This commit is contained in:
parent
18a9e9445f
commit
b31820e43f
@ -1259,9 +1259,9 @@ end
|
|||||||
\end{lstlisting}
|
\end{lstlisting}
|
||||||
|
|
||||||
\begin{exercise}{logicalIndexingBenchmark.m}{logicalIndexingBenchmark.out}
|
\begin{exercise}{logicalIndexingBenchmark.m}{logicalIndexingBenchmark.out}
|
||||||
Above we claimed the logical indexing is faster that manual
|
Above we claimed the logical indexing is faster and much more
|
||||||
selection of element of a vector. By now we have all the tools at
|
convenient than the manual selection of elements of a vector. By now
|
||||||
hand to test this. \\
|
we have all the tools at hand to test this. \\
|
||||||
For this test create a large vector with 100000 (or more) random
|
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
|
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
|
and copy them to a second vector. Surround you code with the brother
|
||||||
@ -1279,43 +1279,48 @@ end
|
|||||||
the agent takes a step in a random direction.
|
the agent takes a step in a random direction.
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item The program should do 10 random walks with 1000 steps each.
|
\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 With each step decide randomly whether the position is changed
|
||||||
|
by $+1$ or $-1$.
|
||||||
\item Store all positions.
|
\item Store all positions.
|
||||||
\item Create a figure in which you plot the position as a function of the steps.
|
\item Create a figure in which you plot the position as a function
|
||||||
|
of the steps.
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
\section{Skripte und Funktionen}
|
\section{Scripts and functions}
|
||||||
|
|
||||||
\subsection{Was ist ein Programm?}
|
\subsection{What is a program?}
|
||||||
|
|
||||||
Ein Programm ist eine Sammlung von Anweisungen, die in einer Datei auf
|
A program is little more than a collection of statement stored in a
|
||||||
dem Rechner abgelegt sind. Wenn es durch den Aufruf zum Leben erweckt
|
file on the computer. When it is \emph{called}, it is brought to life
|
||||||
wird, dann wird es Zeile f\"ur Zeile von oben nach unten ausgef\"uhrt.
|
and executed line-by-line from top to bottom.
|
||||||
|
|
||||||
\matlab{} kennt drei Arten von Programmen:
|
\matlab{} knows three types of programs:
|
||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item \codeterm[Skript]{Skripte}
|
\item \codeterm[Script]{Scripts}
|
||||||
\item \codeterm[Funktion]{Funktionen}
|
\item \codeterm[Function]{Functions}
|
||||||
\item \codeterm[Objekt]{Objekte} (werden wir hier nicht behandeln)
|
\item \codeterm[Object]{Objects} (not covered here)
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
Alle Programme werden in den sogenannten \codeterm{m-files} gespeichert
|
|
||||||
(z.B. \file{meinProgramm.m}). Um sie zu benutzen werden sie von der
|
Programs are stored in so called \codeterm{m-files}
|
||||||
Kommandozeile aufgerufen oder in anderen Programmen
|
(e.g. \file{myProgram.m}). To use them they have to be \emph{called}
|
||||||
verwendet. Programme erh\"ohen die Wiederverwertbarkeit von
|
from the command line of within another program. Storing your code in
|
||||||
Programmcode. Bislang haben wir ausschlie{\ss}lich Skripte
|
programs increases the re-usability. So far we have used
|
||||||
verwendet. Dabei wurde jede Variable, die erzeugt wurde im
|
\emph{scripts} to store the solutions of the exercises. Any variable
|
||||||
\codeterm{Workspace} abgelegt und konnte wiederverwendet werden. Hierin
|
that was created appeared in the \codeterm{workspace} and existed even
|
||||||
liegt allerdings auch eine Gefahr. In der Regel sind Datenanalysen auf
|
after the program was finished. This is very convenient but also bears
|
||||||
mehrere Skripte verteilt und alle teilen sich den gemeinsamen
|
some risks. Consider the case that \file{script_a.m} creates a certain
|
||||||
Workspace. Verwendet nun ein aufgerufenes Skript eine bereits
|
variable and assigns a value to it for later use. Now it calls a
|
||||||
definierte Variable und weist ihr einen neuen Wert zu, dann kann das
|
second program (\file{script_b.m}) that, by accident, uses the same
|
||||||
erw\"unscht und praktisch sein. Wenn es aber unbeabsichtigt passiert
|
variable name and assigns a different value to it. When
|
||||||
kann es zu Fehlern kommen, die nur sehr schwer erkennbar sind, da ja
|
\file{script_b.m} is done, the control returns to \file{script_a.m}
|
||||||
jedes Skript f\"ur sich enwandtfrei arbeitet. Eine L\"osung f\"ur
|
and if it now want to read the previously stored variable, it will
|
||||||
dieses Problem bieten die \codeterm[Funktion]{Funktionen}.
|
contain a different value than expected. Bugs like this are hard to
|
||||||
|
track down since each of the programs alone is perfectly fine and
|
||||||
\subsection{Funktionen}
|
works as intended. A solution for this problem are the
|
||||||
|
\codeterm[Function]{functions}.
|
||||||
|
|
||||||
|
\subsection{Functions}
|
||||||
|
|
||||||
Eine Funktion in \matlab{} wird \"ahnlich zu einer mathematischen
|
Eine Funktion in \matlab{} wird \"ahnlich zu einer mathematischen
|
||||||
Funktion definiert:
|
Funktion definiert:
|
||||||
|
Reference in New Issue
Block a user