[exercises] translate day 1 exercise to english

This commit is contained in:
Jan Grewe 2017-10-16 14:08:23 +02:00
parent cb70e2b6f1
commit 0ee4db5a8d

View File

@ -15,7 +15,7 @@
%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry} \usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry}
\pagestyle{headandfoot} \pagestyle{headandfoot}
\header{{\bfseries\large \"Ubung 1}}{{\bfseries\large Variablen und Datentypen}}{{\bfseries\large 18. Oktober, 2016}} \header{{\bfseries\large Exercise 1}}{{\bfseries\large Variables und Datatypes}}{{\bfseries\large 17. Oktober, 2017}}
\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email: \firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email:
jan.grewe@uni-tuebingen.de} jan.grewe@uni-tuebingen.de}
\runningfooter{}{\thepage}{} \runningfooter{}{\thepage}{}
@ -26,123 +26,108 @@
\renewcommand{\baselinestretch}{1.15} \renewcommand{\baselinestretch}{1.15}
\newcommand{\code}[1]{\texttt{#1}} \newcommand{\code}[1]{\texttt{#1}}
\renewcommand{\solutiontitle}{\noindent\textbf{L\"osung:}\par\noindent} \renewcommand{\solutiontitle}{\noindent\textbf{Solutions:}\par\noindent}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} \begin{document}
\vspace*{-6.5ex} \vspace*{-6.5ex}
\begin{center} \begin{center}
\textbf{\Large Einf\"uhrung in die wissenschaftliche Datenverarbeitung}\\[1ex] \textbf{\Large Introduction to Scientific Computing}\\[1ex]
{\large Jan Grewe, Jan Benda}\\[-3ex] {\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} \\ Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
\end{center} \end{center}
Die folgenden Aufgaben dienen der Wiederholung, \"Ubung und The exercises are meant for self-monitoring, revision of the lecture
Selbstkontrolle und sollten eigenst\"andig bearbeitet und gel\"ost topic. You should try to solve them on your own. Your solution should
werden. Die L\"osung soll in Form eines einzelnen Skriptes (m-files) be submitted as a single script (m-file) in the Ilias system. Each
im ILIAS hochgeladen werden. Jede Aufgabe sollte in einer eigenen task should be solved in its own ``cell''. Each cell must be
``Zelle'' gel\"ost sein. Die Zellen \textbf{m\"ussen} unabh\"angig executable on its own. The file should be named according to the following pattern:
voneinander ausf\"uhrbar sein. Das Skript sollte nach dem Muster:\linebreak ``variables\_datatypes\_\{lastname\}.m'' benannt werden
``variablen\_datentypen\_\{nachname\}.m'' benannt werden (e.g. variables\_datentypes\_mueller.m).
(z.B. variablen\_datentypen\_mueller.m).
\begin{questions} \begin{questions}
\question Creating and deleting variables:
\question Erzeugen und L\"oschen von Variablen:
\begin{parts} \begin{parts}
\part Erzeuge zwei Variablen \code{a}, \code{b} und weise ihnen \part Create two new variables \code{a}, \code{b} and assign arbitrary values to them. End each command with a semicolon. Create a variable \code{c} that is empty.
unterschiedliche Werte zu. Schlie{\ss}e die Zeilen mit einem
Semikolon ab. Erstelle eine Variable \code{c} die leer ist.
\begin{solution} \begin{solution}
\code{a = 1;} \code{b = 2;} \code{c = [];} \code{a = 1;} \code{b = 2;} \code{c = [];}
\end{solution} \end{solution}
\part Lass die Werte der Variablen ausgeben. \part Print the varaibles and their content in the matlab command line
\begin{solution} \begin{solution}
\code{disp(a)}; \code{disp(b)}; \code{disp(c)} \code{disp(a)}; \code{disp(b)}; \code{disp(c)}
\end{solution} \end{solution}
\part Benuzte die Kommandozeile um herauszufinden, welche Variablen \part Use the appropriate command to find out which variables have been created.
es im Workspace gibt.
\begin{solution} \begin{solution}
\code{who} \code{who}
\end{solution} \end{solution}
\part Benuzte die Kommandozeile um herauszufinden, welche Datentypen sie haben. \part Use the appropriate command to additionally display the data type.
\begin{solution} \begin{solution}
\code{whos} oder \code{class(a)}, \code{class(b)}, \code{class(c)} \code{whos} or \code{class(a)}, \code{class(b)}, \code{class(c)}
\end{solution} \end{solution}
\part Finde in der Hilfe mehr Information \"uber das \code{clear} Kommando. \part Use the help system to learn about the \code{clear} command.
\begin{solution} \begin{solution}
\code{help clear} \code{help clear}
\end{solution} \end{solution}
\part L\"osche eine Variable. \part Delete a single variable.
\begin{solution} \begin{solution}
\code{clear a} \code{clear a}
\end{solution} \end{solution}
\part L\"osche alle \"ubrigen Variablen. \part Delete all remaining variables.
\begin{solution} \begin{solution}
\code{clear all} oder einfach \code{clear} \code{clear all} or simply \code{clear}
\end{solution} \end{solution}
\end{parts} \end{parts}
\question Operationen auf Variablen: \question Working with variables:
\begin{parts} \begin{parts}
\part Erstelle die Variablen \code{a} und \code{b} und weise ihnen \part Create two new variables \code{a}, \code{b} and assign arbitrary numeric values.
beliebige Werte zu.
\begin{solution} \begin{solution}
\code{a = 5; b = 3.14;} \code{a = 5; b = 3.14;}
\end{solution} \end{solution}
\part Addiere beliebige andere Zahlen zu den Variablen \code{a} und \code{b}. \part Add a number to \code{a} and \code{b}.
\begin{solution} \begin{solution}
\code{a + 5} \code{b + 7.28} \code{a + 5} \code{b + 7.28}
\end{solution} \end{solution}
\part Addiere die Variablen. \part Add the variables themselves.
\begin{solution} \begin{solution}
\code{a + b} \code{a + b}
\end{solution} \end{solution}
\part Mulipliziere die Variablen miteinander. \part Multiply \code{a} and \code{b}.
\begin{solution} \begin{solution}
\code{a * b} \code{a * b}
\end{solution} \end{solution}
\part \"Andern sich die urspr\"unglichen Werte der Variablen? \part Do \code{a} and \code{b} change?
\begin{solution} \begin{solution}
Nein, die Operationen benutzen die Werte der Variablen. Die No, we make use of the stored values, the values remaing untouched.
Variablen bleiben unver\"andert.
\end{solution} \end{solution}
\part F\"uhre eine beliebige Berechnungen mit den Variablen aus und \part Execute any arithmetic operation with \code{a} and \code{b} and store the result in a new variabel \code{x}.
weise die Ergebnisse einer neuen Variable \code{x} zu.
\begin{solution} \begin{solution}
\code{x = a * b;} \code{x = a * b;}
\end{solution} \end{solution}
\part Weise \code{a} und \code{b} neue Werte zu. Hat sich etwas am \part Assign new values to \code{a} and \code{b}. Did \code{x} change?
Wert von \code{x} ge\"andert?
\begin{solution} \begin{solution}
Nein, der Variablen \code{x} wird ein Wert zugewiesen, der sich No, the content of \code{x} does not change, it stores a value, \textbf{not} a recipe.
nicht \"andert bis der Variablen ein neuer Wert zugewiesen
wird. Die Variable 'x' speichert das Resultat der Rechnung
\textbf{nicht} die Anweisung.
\end{solution} \end{solution}
\end{parts} \end{parts}
\question Berechne die Fakult\"at von 5: \question Calculate the faculty of 5:
\begin{parts} \begin{parts}
\part Erzeuge eine Variable \code{x} und weise ihr den Wert 1 zu. \part Create a variable \code{x} an assign the value 1.
\part Berechne den ersten Schritt (\code{*2}) und weise das Ergebnis \code{x} \part In a first step multiply \code{x} with 2 and assign the result to \code{x} itself.
zu. \part Proceed in a similar manner until x stores $5!$.
\part Fahre schrittweise fort, bis die Fakult\"at von 5 berechnet ist. \code{x}
sollte nun das Endergebnis enthalten.
\end{parts} \end{parts}
\begin{solution} \begin{solution}
\code{x = 1;} \\ \code{x = x * 2;}\\ \code{x = x * 3;} \\ \code{x = x * 4;} \\ \code{x = x * 5;}\\ \code{disp(x)}\\ \code{x = 1;} \\ \code{x = x * 2;}\\ \code{x = x * 3;} \\ \code{x = x * 4;} \\ \code{x = x * 5;}\\ \code{disp(x)}\\
\code{ 120} \code{ 120}
\end{solution} \end{solution}
\question Erstelle eine Variable, die einen beliebigen Text enth\"alt. Was \question Create a variable and assign a string to it. What is the data type of that variable?
ist ihr Datentyp?
\begin{solution} \begin{solution}
\code{x = 'einfacher Text'}\\ \code{class(x)\\ char} \code{x = 'some text'}\\ \code{class(x)\\ char}
\end{solution} \end{solution}
\question Was sind die gr\"o{\ss}ten Zahlen, die in den Integer 8, 16, 32 \question List the largest numbers that can stored in 8, 16, 32
und 64 bit Datentypen abgelegt werden k\"onnen? and 64 bit integer data types?
\begin{solution} \begin{solution}
\verb+2^8 / 2 - 1+\\ \verb+2^8 / 2 - 1+\\
\verb+2^16 / 2 - 1+\\ \verb+2^16 / 2 - 1+\\
@ -150,94 +135,86 @@ voneinander ausf\"uhrbar sein. Das Skript sollte nach dem Muster:\linebreak
\verb+2^64 / 2 - 1+ \verb+2^64 / 2 - 1+
\end{solution} \end{solution}
\question Erstelle eine Variable des 8 Bit Integer Datentyps und weise \question Create an 8 bit integer variable \code{x} and assign a
ihr einen Wert zu. Addiere \code{300}. Welchen Wert enth\"alt nun die valid numeric value to it. Add \code{300} and re-assign the result
Variable? Warum? to \code{x}. Which value is now stored in \code{x}? Why?
\begin{solution} \begin{solution}
\code{x = int8(35);\\x = x + 300;\\ disp(x)\\ 127}\\ \code{x = int8(35);\\x = x + 300;\\ disp(x)\\ 127}\\
Der Datentype int8 kann nur Werte von -128 bis 127 speichern. The int8 dtype can only store values between -128 and 127.
\end{solution} \end{solution}
\question Erkl\"are die Ausgaben von \code{int8(1024)} und \code{uint8(1024)}. \question Explain the output of the follwoing commands: \code{int8(1024)} and \code{uint8(1024)}.
\begin{solution} \begin{solution}
Der int8 Datentyp kann Werte von -128 bis maximal 127 ablegen. Der int8 can store values between -128 and 127. uint8 is
uint8 Typ ist \textit{unsigned}, er speichert Werte zwischen 0 und \textit{unsigned}, ist stores values between 0 and 255.
255.
\end{solution} \end{solution}
\question Typkonvertierung: \question Typeconversion:
\begin{parts} \begin{parts}
\part F\"uhre aus: \code{x = 131.333}. Welchen Datentyp hat die \part Execute: \code{x = 131.333}. What is the datatype of \code{x}?
Variable \code{x}?
\begin{solution} \begin{solution}
Sie hat den Typ \textit{double}. \textit{double}.
\end{solution} \end{solution}
\part Wandle \code{x} in den speichereffizientesten Integer Datentypen um. \part Convert \code{x} to the most efficient integer datatype.
\begin{solution} \begin{solution}
\code{x = uint8(x);}\\Ben\"otigt 8 bit anstelle der 64 bit f\"ur \code{x = uint8(x);}\\Needs 8 bit instead of 64 bit for double.
den double.
\end{solution} \end{solution}
\part Welchen Wert hat nun \code{x} ? \part What is the value stored in \code{x} after conversion?
\begin{solution} \begin{solution}
131 131
\end{solution} \end{solution}
\end{parts} \end{parts}
\question Flie{\ss}kommazahlen 1: Endliche Pr\"azision bei Addition \question Floating point numbers I: Limited precision during additions
\begin{parts} \begin{parts}
\part Weise der Variablen \code{a} eine Zahl mit Nachkommastellen zu. \part Create the variable \code{a} and assign an arbitrary floting point number.
\begin{solution} \begin{solution}
\code{a = 3.14;} \code{a = 3.14;}
\end{solution} \end{solution}
\part Eine weitere Variable \code{b} soll den Wert \code{a+0.001} \part A second variable \code{b} stores the value \code{a+0.001}. What is the result of \code{b-a} ?
haben. Was ist das Ergebnis von \code{b-a} ?
\begin{solution} \begin{solution}
\code{b = a + 0.001;}\\ \code{disp(b - a)\\0.001}\\ \code{b = a + 0.001;}\\ \code{disp(b - a)\\0.001}\\
Alles ok, Ergebnis wie erwartet. All cool, result as expected.
\end{solution} \end{solution}
\part Einer dritte Variable \code{c} soll der Wert \code{a+1e-16} \part Create a third variable \code{c} and assign \code{a+1e-16}. What is the result of \code{c-a}? Why?
zugewiesen werden. Was ist das Ergebnis von \code{c-a} ? Warum?
\begin{solution} \begin{solution}
Das Ergebnis ist 0! Auch die double Werte haben nur eine endliche Result is 0! Also with doubles there is a limited precision in
P\"azision in den Nachkommastellen. the decimal part.
\end{solution} \end{solution}
\part Berechne \verb=(2^52 + 1) - 2^52= sowie \part Calculate \verb=(2^52 + 1) - 2^52= and
\verb=(2^53 + 1) - 2^53=. \verb=(2^53 + 1) - 2^53=.
\begin{solution} \begin{solution}
Im Ersten Fall ist das Ergebnis = 1, im Zweiten = 0. Bei so First command results in = 1, in the second case = 0. With such
gro{\ss}en Zahlen k\"onnen so kleine Unterschiede nicht mehr high numbers, small differences (1!) cannot be resolved.
aufgel\"ost werden.
\end{solution} \end{solution}
\part Berechne \code{sqrt(1+1e-16)-1} . Ist das richtig? Warum? \part Calculate \code{sqrt(1+1e-16)-1}. Is the result correct? Why (not)?
\begin{solution} \begin{solution}
Die Wurzel von 1 + etwas sollte nicht 1 sein! Das Ergebnis Square root of something larger than 1 should not be 1 and thus
sollte nicht 0 sein. the result must not be 0.
\end{solution} \end{solution}
\part Vergleiche mit dem Ergebnis beim Addieren einer etwas \part Compare wwith the result when adding a slightly largern number (e.g. 1e-8).
gr\"o{\ss}eren Zahl (z.B. 1e-8).
\begin{solution} \begin{solution}
Hier sollte das Ergebnis ungleich 0 sein. Result is not equal to zero.
\end{solution} \end{solution}
\end{parts} \end{parts}
\question Flie{\ss}kommazahlen 2: Endliche Pr\"azision bei Multiplikation \question Floating point numbers II: Limited precision during multiplications.
\begin{parts} \begin{parts}
\part Weise der Variablen \code{a} die Zahl \code{4/3} zu. \part Create a variable \code{a} and assign \code{4/3}.
\part Die Variable \code{b} soll den Wert \code{3*(a-1)} erhalten. \part Variable \code{b} should contain the value \code{3*(a-1)}.
\part Welches Ergebnis erwartest du f\"ur \code{b-1} ? \part What do you expect for \code{b-1}?
\begin{solution} \begin{solution}
\code{a = 4/3;}\\ \code{b = 3 * (a-1)}\\ \code{a = 4/3;}\\ \code{b = 3 * (a-1)}\\
b sollte nun 1 sein. d.h., \code{b-1} sollte 0 sein. b should be 1. i.e., \code{b-1} should give 0.
\end{solution} \end{solution}
\part Berechne mit matlab \code{b-1} ! \part Calculate with matlab \code{b-1}!
\begin{solution} \begin{solution}
\code{disp(b - 1)\\ -2.2204e-16}\\ Aufgrund von Rundungsfehlern \code{disp(b - 1)\\ -2.2204e-16}\\ Due to rounding mistakes.
kommt es zu diesem Ergebnis.
\end{solution} \end{solution}
\part Was sollte \code{sin(pi)} ergeben ? Was sagt matlab? \part What should be the result of \code{sin(pi)}? What gives matlab?
\begin{solution} \begin{solution}
Sollte 0 sein, ist es aber nicht. Wie oben, Rundungsfehler Should be 0, but it is not. See above, due to rounding errors we
f\"uhren zu diesen Abweichungen. get some deviation.
\end{solution} \end{solution}
\end{parts} \end{parts}