[exercises] update exercise 3/4
This commit is contained in:
parent
8a5abf5f73
commit
97126dac54
@ -13,8 +13,8 @@
|
||||
|
||||
%%%%% text size %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
\usepackage[left=20mm,right=20mm,top=25mm,bottom=25mm]{geometry}
|
||||
\pagestyle{headandfoot} \header{{\bfseries\large \"Ubung
|
||||
3}}{{\bfseries\large Boolean Expressions and logical indexing}}{{\bfseries\large 24. Oktober, 2017}}
|
||||
\pagestyle{headandfoot} \header{{\bfseries\large Exercise 4
|
||||
}}{{\bfseries\large Boolean Expressions and logical indexing}}{{\bfseries\large 23. Oktober, 2018}}
|
||||
\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email:
|
||||
jan.grewe@uni-tuebingen.de} \runningfooter{}{\thepage}{}
|
||||
|
||||
@ -35,12 +35,12 @@
|
||||
Abteilung Neuroethologie \hfill --- \hfill Institut f\"ur Neurobiologie \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
|
||||
\end{center}
|
||||
|
||||
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
|
||||
The exercises are meant for self-monitoring and revision of the
|
||||
lecture. 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''
|
||||
(e.g. variables\_datentypes\_mueller.m).
|
||||
|
||||
\section{Boolean expressions}
|
||||
@ -62,10 +62,10 @@ executable on its own. The file should be named according to the following patte
|
||||
\part Execute and explain: \verb+bitand(10, 8)+
|
||||
\part Execute and explain: \verb+bitor(10, 8)+
|
||||
\end{parts}
|
||||
\item Implemen the following Boolean expressions. Test using randomly selected integer values for \verb+x+ and \verb+y+.
|
||||
\item Implement the following Boolean expressions. Test using randomly selected integer values for \verb+x+ and \verb+y+.
|
||||
\begin{parts}
|
||||
\part The result should be \verb+true+ if \verb+x+ greater than \verb+y+ and the sum of \verb+x+ and \verb+y+ is not less than 100.
|
||||
\part The result shoudl be \verb+true+ if \verb+x+ and \verb+y+ are not equal zero or \verb+x+ and \verb+y+ are equal.
|
||||
\part The result should be \verb+true+ if \verb+x+ and \verb+y+ are not equal zero or \verb+x+ and \verb+y+ are equal.
|
||||
\end{parts}
|
||||
\end{questions}
|
||||
|
||||
@ -74,12 +74,12 @@ executable on its own. The file should be named according to the following patte
|
||||
|
||||
Boolean expressions can be used to select elements of vectors or
|
||||
matrices that match in certain criteria. This process is called
|
||||
logical indexing.
|
||||
\emph{logical indexing}.
|
||||
|
||||
\begin{questions}
|
||||
\question Given are the vectors \verb+x = (1:10)+ and
|
||||
\verb+y = [3 1 5 6 8 2 9 4 7 0]+. Try to understand the results of
|
||||
the following commands. Explain.
|
||||
the following commands and explain.
|
||||
\begin{parts}
|
||||
\part \verb+x < 5+
|
||||
\part \verb+x( x < 5) )+
|
||||
@ -90,7 +90,7 @@ logical indexing.
|
||||
|
||||
\question Test the random number generator:
|
||||
\begin{parts}
|
||||
\part Create a 100x100 2-D matrix that is filled with random numbers in the range 0 to 100 (\verb+randi+). Replace the elements according to these rules: \verb+x < 33+ to 0,
|
||||
\part Create a $100 \times 100$ 2-D matrix that is filled with random numbers in the range 0 to 100. Replace the elements according to these rules: \verb+x < 33+ to 0,
|
||||
\verb+x >= 33 and x < 66+ to 1 and all \verb+x >= 66+ to 2.
|
||||
\part Count the number of elements in each class using Boolean expressions (\verb+sum+ can be used to count the matches).
|
||||
\end{parts}
|
||||
|
@ -36,13 +36,13 @@
|
||||
Neuroethology \hfill --- \hfill Institute for Neurobiology \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
|
||||
\end{center}
|
||||
|
||||
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).
|
||||
The exercises are meant for self-monitoring and revision of the
|
||||
lecture. 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:
|
||||
``matrices\_\{lastname\}.m''(e.g. matrices\_mueller.m).
|
||||
|
||||
\begin{questions}
|
||||
|
||||
@ -58,27 +58,28 @@ executable on its own. The file should be named according to the following patte
|
||||
\begin{solution}
|
||||
\code{disp(size(x, 1))}\\\code{disp(size(x, 2))}
|
||||
\end{solution}
|
||||
\part Retrieve the element at the position 3rd line, 2nd column.
|
||||
\part Copy the content at the position 3rd line, 2nd column to a new variable.
|
||||
\begin{solution}
|
||||
\code{x(3,2)}
|
||||
\code{c = x(3, 2)}
|
||||
\end{solution}
|
||||
\part Print all elements of the 1st, 2nd and 3rd line.
|
||||
\part Display all elements of the 1st, 2nd and 3rd line.
|
||||
\begin{solution}
|
||||
\code{disp(x([1 2 3],:));}
|
||||
\code{disp(x([1 2 3], :));}
|
||||
\end{solution}
|
||||
\part Print all elements of the 1st, 2nd, and 3rd column.
|
||||
\part Display all elements of the 1st, 2nd, and 3rd column.
|
||||
\begin{solution}
|
||||
\code{disp(x(:, 1))\\ disp(x(:, 2))\\ disp(x(:, 3))}
|
||||
\end{solution}
|
||||
\part Increment all elements of the 2nd line and the 3rd column about 1.
|
||||
\part Increment all elements of the 2nd line and the 3rd column about 1 (reassign the result to the respective elements).
|
||||
\begin{solution}
|
||||
\code{x(2,3) = x(2,3) + 1;}
|
||||
\code{x(2,:) = x(2,:) + 1;}\\
|
||||
\code{x(:,3) = x(:,3) + 1;}
|
||||
\end{solution}
|
||||
\part Subtract five from all elements of the 1st line.
|
||||
\begin{solution}
|
||||
\code{x(1,:) = x(1,:) - 5;}
|
||||
\end{solution}
|
||||
\part Multiply all elements of the 3rd column with 2.
|
||||
\part Multiply all elements of the 3rd column by 2.
|
||||
\begin{solution}
|
||||
\code{x(:,3) = x(:,3) .* 2;}
|
||||
\end{solution}
|
||||
@ -87,7 +88,7 @@ executable on its own. The file should be named according to the following patte
|
||||
\question Create a $5 \times 5$ matrix \code{M} that contains random numbers (use the function
|
||||
\verb+randn()+. Use the help to find out what it does).
|
||||
\begin{parts}
|
||||
\part Print the element at the position 2nd line and 3rd column.
|
||||
\part Display the content of \code{M} at position 2nd line and 3rd column.
|
||||
\begin{solution}
|
||||
\code{M = randn(5, 5);}
|
||||
\code{disp(M(2,3))}
|
||||
@ -124,7 +125,7 @@ executable on its own. The file should be named according to the following patte
|
||||
\code{sum(M(:))}
|
||||
\end{solution}
|
||||
|
||||
\part Exchange all elements of the 2nd with those of the 4th line.
|
||||
\part Replace all elements of the 2nd line with those of the 4th line.
|
||||
\begin{solution}
|
||||
\code{M(2,:) = M(4,:)}
|
||||
\end{solution}
|
||||
@ -158,7 +159,7 @@ executable on its own. The file should be named according to the following patte
|
||||
\code{x(randi(100, 50, 1)])}
|
||||
\end{solution}
|
||||
|
||||
\part Is there an advantage to use the linear indexing?
|
||||
\part Can you imaging an advantage of using linear indexing instead of subscript indexing?
|
||||
\begin{solution}
|
||||
Die Matrize ist 2-dimensional. Wenn mit dem subscript index
|
||||
zugegriffen werden soll, dann muss auf die Dimensionen
|
||||
@ -175,8 +176,10 @@ executable on its own. The file should be named according to the following patte
|
||||
|
||||
\end{parts}
|
||||
|
||||
\question Create the three variables \verb+x = [1 5 9]+ and
|
||||
\verb+y = [7 1 5]+ and \verb+M = [3 1 6; 5 2 7]+. Which of the following commands will pass? Which command will not? If not, why? Test your predictions.
|
||||
\question Create three variables \verb+x = [1 5 9]+ and
|
||||
\verb+y = [7 1 5]+ and \verb+M = [3 1 6; 5 2 7]+. Which of the
|
||||
following commands will pass? Which command will fail? If it fails,
|
||||
why? Test your predictions.
|
||||
\begin{parts}
|
||||
\part \code{x + y}
|
||||
\begin{solution}
|
||||
@ -209,7 +212,8 @@ executable on its own. The file should be named according to the following patte
|
||||
\end{solution}
|
||||
\end{parts}
|
||||
|
||||
\question Create a 3-D matrix from two 2-D matrices. Use the function cat (check the help to learn its usage).
|
||||
\question Create a 3-D matrix from two 2-D matrices. Use the
|
||||
function \code{cat} (check the help to learn its usage).
|
||||
\begin{parts}
|
||||
\part Select all elements of the first ``page'' (index 1, 3. dimension).
|
||||
\begin{solution}
|
||||
|
Reference in New Issue
Block a user