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