[programming/exercises] some fixes

This commit is contained in:
Jan Grewe 2019-11-05 08:46:33 +01:00
parent dc8f270ebf
commit 0be4a67f21

View File

@ -14,7 +14,7 @@
%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry}
\pagestyle{headandfoot}
\header{{\bfseries\large Exercise 5}}{{\bfseries\large Control Flow}}{{\bfseries\large 30. October, 2018}}
\header{{\bfseries\large Exercise 5}}{{\bfseries\large Control Flow}}{{\bfseries\large 05. November, 2019}}
\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email:
jan.grewe@uni-tuebingen.de}
\runningfooter{}{\thepage}{}
@ -47,11 +47,9 @@ following pattern: ``variables\_datatypes\_\{lastname\}.m''
\begin{questions}
\question Implement \code{for} loops in which the \emph{running variable}:
\begin{parts}
\part ... assumes values from 0 to 10. Print the value of the running variable for each iteration step.
\part ... assumes values from 0 to 10. Print (\code{disp}) the value of the running variable for each iteration step.
\begin{solution}
for i = 1:10
disp(i);
end;
for i = 1:10 disp(i); end;
\end{solution}
\part ... assumes values from 10 to 0. Print out the value for each iteration.
\part ... assumes values from 0 to 1 in steps of 0.1. Print out the value for each iteration.
@ -59,12 +57,12 @@ following pattern: ``variables\_datatypes\_\{lastname\}.m''
\question Indexing in vectors:
\begin{parts}
\part Define a vector \code{x} that contains values ranging from 101 to 200.
\part Define a vector \code{x} that contains values ranging from 101 to 200 in steps of 1.
\part Use a \code{for} loop to print each element of \code{x}. Use the running variable for the indexing.
\begin{solution}
\code{for i = 1:length(x); disp(x(i)); end}
\end{solution}
\part Do the same without use the running variable directly (not for indexing).
\part Do the same without using the running variable directly (not for indexing).
\begin{solution}
\code{for i : x; disp(i); end;}
\end{solution}
@ -74,7 +72,7 @@ following pattern: ``variables\_datatypes\_\{lastname\}.m''
\begin{parts}
\part Use a loop to calculate the arithmetic mean. The mean is defined as:
$\overline{x}=\frac{1}{n}\sum\limits_{i=0}^{n}x_i $.
\part Use a loop to estimate the stadard deviation:
\part Use a loop to estimate the standard deviation:
$\sigma=\sqrt{\frac{1}{n}\sum\limits_{i=0}^{n}(x_i-\overline{x})^2}$).
\part Search the MATLAB help for functions that do the calculations for you :-).
\end{parts}
@ -85,13 +83,13 @@ following pattern: ``variables\_datatypes\_\{lastname\}.m''
\part ... iterates endlessly. You can interrupt the execution with the command \code{Strg + C}.
\end{parts}
\question Use an endless \code{while} loop to individually print out the elements of a vector that contains 10 elements. Stop the execution after all elements have been printed.
\question Use an endless \code{while} loop to individually display the elements of a vector that contains 10 elements. Stop the execution after all elements have been displayed on the command line.
\question Use the endless \verb+while+ loop to draw random numbers
(\verb+randn+) until you hit one that is larger than 1.33.
\begin{parts}
\part Count the number of required iterations.
\part Use a \code{for} loop to run the previous test 1000 times. Remember all counts and calculate the mean of it.
\part Use a \code{for} loop to run the previous test 1000 times. Store all counts and calculate the mean of it.
\part Create a plot that shows for each of the 1000 trials, how often you had to draw.
\part Play around with the threshold. What happens?
\end{parts}