[exercises] update exercise 3/4
This commit is contained in:
parent
8a5abf5f73
commit
97126dac54
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
%%%%% 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} \header{{\bfseries\large \"Ubung
|
\pagestyle{headandfoot} \header{{\bfseries\large Exercise 4
|
||||||
3}}{{\bfseries\large Boolean Expressions and logical indexing}}{{\bfseries\large 24. Oktober, 2017}}
|
}}{{\bfseries\large Boolean Expressions and logical indexing}}{{\bfseries\large 23. Oktober, 2018}}
|
||||||
\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email:
|
\firstpagefooter{Dr. Jan Grewe}{Phone: 29 74588}{Email:
|
||||||
jan.grewe@uni-tuebingen.de} \runningfooter{}{\thepage}{}
|
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} \\
|
Abteilung Neuroethologie \hfill --- \hfill Institut f\"ur Neurobiologie \hfill --- \hfill \includegraphics[width=0.28\textwidth]{UT_WBMW_Black_RGB} \\
|
||||||
\end{center}
|
\end{center}
|
||||||
|
|
||||||
The exercises are meant for self-monitoring, revision of the lecture
|
The exercises are meant for self-monitoring and revision of the
|
||||||
topic. You should try to solve them on your own. Your solution should
|
lecture. You should try to solve them on your own. Your solution
|
||||||
be submitted as a single script (m-file) in the Ilias system. Each
|
should be submitted as a single script (m-file) in the Ilias
|
||||||
task should be solved in its own ``cell''. Each cell must be
|
system. Each task should be solved in its own ``cell''. Each cell must
|
||||||
executable on its own. The file should be named according to the following pattern:
|
be executable on its own. The file should be named according to the
|
||||||
``variables\_datatypes\_\{lastname\}.m'' benannt werden
|
following pattern: ``variables\_datatypes\_\{lastname\}.m''
|
||||||
(e.g. variables\_datentypes\_mueller.m).
|
(e.g. variables\_datentypes\_mueller.m).
|
||||||
|
|
||||||
\section{Boolean expressions}
|
\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+bitand(10, 8)+
|
||||||
\part Execute and explain: \verb+bitor(10, 8)+
|
\part Execute and explain: \verb+bitor(10, 8)+
|
||||||
\end{parts}
|
\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}
|
\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 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{parts}
|
||||||
\end{questions}
|
\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
|
Boolean expressions can be used to select elements of vectors or
|
||||||
matrices that match in certain criteria. This process is called
|
matrices that match in certain criteria. This process is called
|
||||||
logical indexing.
|
\emph{logical indexing}.
|
||||||
|
|
||||||
\begin{questions}
|
\begin{questions}
|
||||||
\question Given are the vectors \verb+x = (1:10)+ and
|
\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
|
\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}
|
\begin{parts}
|
||||||
\part \verb+x < 5+
|
\part \verb+x < 5+
|
||||||
\part \verb+x( x < 5) )+
|
\part \verb+x( x < 5) )+
|
||||||
@ -90,7 +90,7 @@ logical indexing.
|
|||||||
|
|
||||||
\question Test the random number generator:
|
\question Test the random number generator:
|
||||||
\begin{parts}
|
\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.
|
\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).
|
\part Count the number of elements in each class using Boolean expressions (\verb+sum+ can be used to count the matches).
|
||||||
\end{parts}
|
\end{parts}
|
||||||
|
@ -36,13 +36,13 @@
|
|||||||
Neuroethology \hfill --- \hfill Institute for Neurobiology \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}
|
||||||
|
|
||||||
The exercises are meant for self-monitoring, revision of the lecture
|
The exercises are meant for self-monitoring and revision of the
|
||||||
topic. You should try to solve them on your own. Your solution should
|
lecture. You should try to solve them on your own. Your solution
|
||||||
be submitted as a single script (m-file) in the Ilias system. Each
|
should be submitted as a single script (m-file) in the Ilias
|
||||||
task should be solved in its own ``cell''. Each cell must be
|
system. Each task should be solved in its own ``cell''. Each cell must
|
||||||
executable on its own. The file should be named according to the following pattern:
|
be executable on its own. The file should be named according to the
|
||||||
``variables\_datatypes\_\{lastname\}.m'' benannt werden
|
following pattern:
|
||||||
(e.g. variables\_datentypes\_mueller.m).
|
``matrices\_\{lastname\}.m''(e.g. matrices\_mueller.m).
|
||||||
|
|
||||||
\begin{questions}
|
\begin{questions}
|
||||||
|
|
||||||
@ -58,27 +58,28 @@ executable on its own. The file should be named according to the following patte
|
|||||||
\begin{solution}
|
\begin{solution}
|
||||||
\code{disp(size(x, 1))}\\\code{disp(size(x, 2))}
|
\code{disp(size(x, 1))}\\\code{disp(size(x, 2))}
|
||||||
\end{solution}
|
\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}
|
\begin{solution}
|
||||||
\code{x(3,2)}
|
\code{c = x(3, 2)}
|
||||||
\end{solution}
|
\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}
|
\begin{solution}
|
||||||
\code{disp(x([1 2 3], :));}
|
\code{disp(x([1 2 3], :));}
|
||||||
\end{solution}
|
\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}
|
\begin{solution}
|
||||||
\code{disp(x(:, 1))\\ disp(x(:, 2))\\ disp(x(:, 3))}
|
\code{disp(x(:, 1))\\ disp(x(:, 2))\\ disp(x(:, 3))}
|
||||||
\end{solution}
|
\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}
|
\begin{solution}
|
||||||
\code{x(2,3) = x(2,3) + 1;}
|
\code{x(2,:) = x(2,:) + 1;}\\
|
||||||
|
\code{x(:,3) = x(:,3) + 1;}
|
||||||
\end{solution}
|
\end{solution}
|
||||||
\part Subtract five from all elements of the 1st line.
|
\part Subtract five from all elements of the 1st line.
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
\code{x(1,:) = x(1,:) - 5;}
|
\code{x(1,:) = x(1,:) - 5;}
|
||||||
\end{solution}
|
\end{solution}
|
||||||
\part Multiply all elements of the 3rd column with 2.
|
\part Multiply all elements of the 3rd column by 2.
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
\code{x(:,3) = x(:,3) .* 2;}
|
\code{x(:,3) = x(:,3) .* 2;}
|
||||||
\end{solution}
|
\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
|
\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).
|
\verb+randn()+. Use the help to find out what it does).
|
||||||
\begin{parts}
|
\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}
|
\begin{solution}
|
||||||
\code{M = randn(5, 5);}
|
\code{M = randn(5, 5);}
|
||||||
\code{disp(M(2,3))}
|
\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(:))}
|
\code{sum(M(:))}
|
||||||
\end{solution}
|
\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}
|
\begin{solution}
|
||||||
\code{M(2,:) = M(4,:)}
|
\code{M(2,:) = M(4,:)}
|
||||||
\end{solution}
|
\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)])}
|
\code{x(randi(100, 50, 1)])}
|
||||||
\end{solution}
|
\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}
|
\begin{solution}
|
||||||
Die Matrize ist 2-dimensional. Wenn mit dem subscript index
|
Die Matrize ist 2-dimensional. Wenn mit dem subscript index
|
||||||
zugegriffen werden soll, dann muss auf die Dimensionen
|
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}
|
\end{parts}
|
||||||
|
|
||||||
\question Create the three variables \verb+x = [1 5 9]+ and
|
\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 not? If not, why? Test your predictions.
|
\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}
|
\begin{parts}
|
||||||
\part \code{x + y}
|
\part \code{x + y}
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
@ -209,7 +212,8 @@ executable on its own. The file should be named according to the following patte
|
|||||||
\end{solution}
|
\end{solution}
|
||||||
\end{parts}
|
\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}
|
\begin{parts}
|
||||||
\part Select all elements of the first ``page'' (index 1, 3. dimension).
|
\part Select all elements of the first ``page'' (index 1, 3. dimension).
|
||||||
\begin{solution}
|
\begin{solution}
|
||||||
|
Reference in New Issue
Block a user