[exercises] translate scripts and functions
This commit is contained in:
parent
78f6b352a2
commit
eb10de858e
@ -16,7 +16,7 @@
|
||||
%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry}
|
||||
\pagestyle{headandfoot}
|
||||
\header{{\bfseries\large \"Ubung 5}}{{\bfseries\large Skripte und Funktionen}}{{\bfseries\large 15. November, 2016}}
|
||||
\header{{\bfseries\large \"Ubung 5}}{{\bfseries\large Scripts and functions}}{{\bfseries\large 07. November, 2017}}
|
||||
\firstpagefooter{Prof. Jan Benda}{Phone: 29 74 573}{Email:
|
||||
jan.benda@uni-tuebingen.de}
|
||||
\runningfooter{}{\thepage}{}
|
||||
@ -54,79 +54,82 @@
|
||||
|
||||
\vspace*{-6.5ex}
|
||||
\begin{center}
|
||||
\textbf{\Large Einf\"uhrung in die wissenschaftliche Datenverarbeitung}\\[1ex]
|
||||
{\large Jan Grewe, Jan Benda}\\[-3ex]
|
||||
Abteilung Neuroethologie \hfill --- \hfill Institut f\"ur Neurobiologie \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
|
||||
\textbf{\Large Introduction to Scientific Computing}\\[1ex]
|
||||
{\large Jan Grewe, Jan Benda}\\[-3ex]
|
||||
Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
|
||||
\end{center}
|
||||
|
||||
Die folgenden Aufgaben dienen der Wiederholung, \"Ubung und
|
||||
Selbstkontrolle und sollten eigenst\"andig bearbeitet und gel\"ost
|
||||
werden. Im Gegensatz zu den vorherigen \"Ubungsbl\"attern k\"onnen die
|
||||
L\"osungen nicht mehr in einer Datei gemacht werden. Die L\"osungen
|
||||
also als zip-Archiv auf ILIAS hochladen. Das Archiv sollte nach dem Muster:
|
||||
``skripte\_funktionen\_\{nachname\}.zip'' benannt werden.
|
||||
The exercises are meant for self-monitoring and revision of the
|
||||
lecture topic. You should try to solve them on your own. In contrast
|
||||
to previous exercises, the solutions can not be saved in a single file
|
||||
but each question needs an individual file. Combine the files into a
|
||||
single zip archive and submit it via ILIAS. Name the archive according
|
||||
to the pattern: ``scripts\_functions\_\{surname\}.zip''.
|
||||
|
||||
\begin{questions}
|
||||
|
||||
\question Berechne die Fakult\"at einer Zahl.
|
||||
\question Calculate the factorial of a given number $n$.
|
||||
\begin{parts}
|
||||
\part Version 1: Schreibe eine Skript, das die Fakult\"at von 5 berechnet und das
|
||||
Resultat auf dem Bildschirm ausgibt.
|
||||
\part{}
|
||||
Version 1: Write a script that calculates the factorial of 5 and
|
||||
prints out the result.
|
||||
\begin{solution}
|
||||
\lstinputlisting{factorialscripta.m}
|
||||
\end{solution}
|
||||
|
||||
\part Version 2: Wie Version 1, aber als Funktion, die als
|
||||
Argument die Zahl, von der die Fakult\"at berechnet werden soll,
|
||||
\"ubernimmt.
|
||||
\part{}
|
||||
Version 2: like version 1, but as a function that takes $n$ as
|
||||
input argument.
|
||||
\begin{solution}
|
||||
\lstinputlisting{printfactorial.m}
|
||||
\lstinputlisting{factorialscriptb.m}
|
||||
\end{solution}
|
||||
|
||||
\part Version 3: Wie Version 2, die Funktion soll den berechneten
|
||||
Wert nicht ausgeben, sondern als Funktionswert zur\"uckgeben. Das
|
||||
aufrufende Skript soll dann den berechneten Wert auf dem
|
||||
Bildschirm ausgeben.
|
||||
\part{}
|
||||
Version 3: like version 2, but the calculated result should not be
|
||||
printed on the command line but returned by the function. Write a
|
||||
script that calls the function and prints out the result.
|
||||
\begin{solution}
|
||||
\lstinputlisting{myfactorial.m}
|
||||
\lstinputlisting{factorialscriptc.m}
|
||||
\end{solution}
|
||||
|
||||
\end{parts}
|
||||
|
||||
\question Grafische Darstellung einer Sinuswelle.
|
||||
\question Graphical display of a sinewave.
|
||||
\begin{parts}
|
||||
\part Implementiere eine Funktion, die einen Sinus mit der
|
||||
Amplitude 1 und der Frequenz $f = $ 50\,Hz plottet ($\sin(2\pi \cdot
|
||||
f \cdot t)$). Rufe die Funktion auf.
|
||||
\part{}
|
||||
Implement a function that plots a sine with the amplitude 1 and
|
||||
the frequency $f=50$\,Hz $\left(\sin(2\pi \cdot f \cdot t)\right)$. Call the
|
||||
function in a script.
|
||||
\begin{solution}
|
||||
\lstinputlisting{plotsine50.m}
|
||||
\lstinputlisting{plotsinea.m}
|
||||
\end{solution}
|
||||
|
||||
\part Erweitere die Funktion so, dass die L\"ange der Zeitachse,
|
||||
die Amplitude, und die Frequenz als Argumente \"ubergeben werden
|
||||
k\"onnen. Die Schrittweite soll in der Funktion aus der Frequenz
|
||||
berechnet werden.
|
||||
\part{}
|
||||
Improve the function that it takes the duration of the time axis,
|
||||
the amplitude and the frequency as input arguments. The
|
||||
calculation should use a temporal stepsize that is 0.01 of the
|
||||
frequency.
|
||||
\begin{solution}
|
||||
\lstinputlisting{plotsine.m}
|
||||
\lstinputlisting{plotsineb.m}
|
||||
\lstinputlisting{plotsine.m} \lstinputlisting{plotsineb.m}
|
||||
\end{solution}
|
||||
|
||||
\part Verlagere alle plot Befehle in das aufrufende Skript
|
||||
und ver\"andere die Funktion so, dass sie sowohl den Sinus als
|
||||
auch die Zeitachse zur\"uckgibt.
|
||||
\part{}
|
||||
Write a script that calls the function and controls the
|
||||
plotting. Change the function in a way that it returns a proper
|
||||
time-axis and the calculated sinwave.
|
||||
\begin{solution}
|
||||
\lstinputlisting{sinewave.m}
|
||||
\lstinputlisting{plotsinec.m}
|
||||
\end{solution}
|
||||
|
||||
\part Schreibe eine zweite Funktion, die den Sinus plotted und
|
||||
daf\"ur die Zeitachse und den Sinus als Argument erh\"alt. Diese
|
||||
Funktion soll die Achsen richtig beschriften. Schreibe ein kleines
|
||||
Skript, dass beide Funktionen aufruft, um einen Sinus von 5\,Hz
|
||||
mit der Amplitude 2 \"uber 1.5 Sekunden zu plotten.
|
||||
\part{}
|
||||
Write a second function that does the plotting. It accepts the
|
||||
time and the sine as arguments. Make sure, that the plot is
|
||||
properly labeled. Write a small script that uses both funtions to
|
||||
plot a sine of $5$\,Hz frequency and an amplitude of 2 for a
|
||||
duration of 1.5\,s.
|
||||
\begin{solution}
|
||||
\lstinputlisting{plotsinewave.m}
|
||||
\lstinputlisting{plotsined.m}
|
||||
@ -138,40 +141,46 @@ also als zip-Archiv auf ILIAS hochladen. Das Archiv sollte nach dem Muster:
|
||||
%Vektor zur\"uckgibt. Welche Argumente muss die Funktion
|
||||
%\"ubernehmen?
|
||||
|
||||
\question Random Walk.
|
||||
\begin{parts}
|
||||
\part Lies die Aufgabe bis zum Ende durch. \"Uberlege dir dann ein
|
||||
geeignetes ``Programmlayout'' aus Funktionen und Skripten.
|
||||
\question Random Walk. In a 1-D random walk an \emph{agent} walks
|
||||
randomly either in the one ($+1$) or the other ($-1$)
|
||||
direction. With each simulation step one direction is chosen and the
|
||||
position is updated accordingly.
|
||||
|
||||
Was w\"are eine geeigente Funktion f\"ur diese Aufgabe? Welche
|
||||
Argumente sollte sie entgegennehmen? Was soll sie berechnen und
|
||||
zur\"uckgeben?
|
||||
\begin{parts}
|
||||
\part{}
|
||||
Read the exercise completely before starting the implementation
|
||||
and then come up with a proper program layout of scripts and
|
||||
functions. What would be a suitable function to solve the task? Which
|
||||
arguments should it take? Which results should it return?
|
||||
\begin{solution}
|
||||
One function that computes one realisation of a random walk.
|
||||
Scripts for plotting and analysis.
|
||||
\lstinputlisting{randomwalkthresh.m}
|
||||
\end{solution}
|
||||
|
||||
\part Simuliere und plotte die Positionen von 10 Realisationen
|
||||
eines random walk mit gleichen Wahrscheinlichkeiten f\"ur beide
|
||||
Richtungen. Jeder Walker startet an der Position 0 und soll so
|
||||
lange laufen, bis er den Wert 50 \"uberschreitet oder den Wert
|
||||
$-50$ unterschreitet.
|
||||
\part{}
|
||||
Run the simulation 10 times and plot the time-course of the
|
||||
positions of the \emph{agents} into the same plot. The probability
|
||||
of the two directions should be the same. Each \emph{agent} starts
|
||||
at position $0$ and the simulation should run until the position is
|
||||
greater than $50$ or less than $-50$.
|
||||
\begin{solution}
|
||||
\lstinputlisting{randomwalkscriptb.m}
|
||||
\end{solution}
|
||||
|
||||
\part Jetzt wollen wir die Wahrscheinlichkeit $p$ f\"ur eine
|
||||
Bewegung zu gr\"o{\ss}eren Positionen im Bereich $0.5 \le p < 0.8$
|
||||
variieren. Simuliere 10 Realisationen des random walk f\"ur vier
|
||||
verschiedene Wahrscheinlichkeiten.
|
||||
\part{}
|
||||
Now we want to know how the probability of $p_{+1}$ (the
|
||||
probability to walk into the $+1$ direction) impacts the random
|
||||
walk. Vary $p_{+1}$ in the range $0.5 \le p_{+1} < 0.8$. Do 10
|
||||
random walks for four probabilities (apply the same thresholds for
|
||||
stopping the simulations as before).
|
||||
\begin{solution}
|
||||
\lstinputlisting{randomwalkscriptc.m}
|
||||
\end{solution}
|
||||
|
||||
\part Wie entwickelt sich die mittlere ben\"otigte Schrittanzahl
|
||||
in Abh\"angigkeit der Wahrscheinlichkeit? Stelle die Mittelwerte
|
||||
und die Standardabweichungen graphisch dar.
|
||||
\part{}
|
||||
How does $p_{+1}$ affect the number of simulation steps? Plot the
|
||||
averages and standard deviations as a function of $p_{+1}$.
|
||||
\begin{solution}
|
||||
\lstinputlisting{randomwalkscriptd.m}
|
||||
\end{solution}
|
||||
|
Reference in New Issue
Block a user