\documentclass[addpoints,10pt]{exam} \usepackage{url} \usepackage{color} \usepackage{hyperref} \usepackage{graphicx} \usepackage{amsmath} \pagestyle{headandfoot} \runningheadrule \firstpageheadrule \firstpageheader{Scientific Computing}{Matrix multiplication}{Oct 28, 2014} %\runningheader{Homework 01}{Page \thepage\ of \numpages}{23. October 2014} \firstpagefooter{}{}{} \runningfooter{}{}{} \pointsinmargin \bracketedpoints %\printanswers \shadedsolutions \usepackage[mediumspace,mediumqspace,Gray]{SIunits} % \ohm, \micro %%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \usepackage{listings} \lstset{ basicstyle=\ttfamily, numbers=left, showstringspaces=false, language=Matlab, breaklines=true, breakautoindent=true, columns=flexible, frame=single, captionpos=t, xleftmargin=2em, xrightmargin=1em, aboveskip=10pt, %title=\lstname, title={\protect\filename@parse{\lstname}\protect\filename@base.\protect\filename@ext} } \begin{document} \sffamily %%%%%%%%%%%%%% Questions %%%%%%%%%%%%%%%%%%%%%%%%% \begin{questions} \question \textbf{Matrix multiplication} Calculate the results of the following matrix multiplications and confirm the result using matlab. \[ \begin{pmatrix} 2 \\ -4 \\ -1 \end{pmatrix} \cdot \begin{pmatrix} 3 & -4 & -4 \end{pmatrix} = \] \[ \begin{pmatrix} 3 & -3 & -1 \end{pmatrix} \cdot \begin{pmatrix} 2 \\ 3 \\ 0 \end{pmatrix} = \] \[ \begin{pmatrix} 4 & -1 & 2 \\ -1 & 3 & 1 \\ 4 & -2 & 1 \\ 4 & -3 & -2 \end{pmatrix} \cdot \begin{pmatrix} -2 & -2 & 0 & -3 \\ 3 & -2 & 1 & 0 \\ 1 & -2 & -4 & 0 \end{pmatrix} = \] \[ \begin{pmatrix} 3 & 1 \\ 1 & 4 \end{pmatrix} \cdot \begin{pmatrix} 0 & -3 & 4 & 1 \\ -2 & -1 & -2 & -3 \\ -3 & 1 & -2 & -3 \end{pmatrix} = \] \[ \begin{pmatrix} 1 & 1 & -4 \end{pmatrix} \cdot \begin{pmatrix} -1 \\ 2 \end{pmatrix} = \] \[ \begin{pmatrix} 3 & 1 & -2 \\ 2 & 1 & 3 \\ 1 & 1 & 2 \end{pmatrix} \cdot \begin{pmatrix} 2 & 2 \\ -3 & 3 \\ -4 & 1 \end{pmatrix} = \] \[ \begin{pmatrix} 3 \\ 2 \end{pmatrix} \cdot \begin{pmatrix} -3 & 2 & -4 & 1 \end{pmatrix} = \] \[ \begin{pmatrix} -1 \\ -4 \\ -1 \end{pmatrix} \cdot \begin{pmatrix} 0 & -4 & 1 \end{pmatrix} = \] \[ \begin{pmatrix} 4 & -2 & -2 & -4 \end{pmatrix} \cdot \begin{pmatrix} 2 \\ 2 \\ 1 \\ -1 \end{pmatrix} = \] \[ \begin{pmatrix} -2 & -3 & -4 \\ 1 & 3 & 2 \\ -4 & -2 & 1 \end{pmatrix} \cdot \begin{pmatrix} 1 & 2 & -2 & 4 \\ 3 & -1 & 1 & -1 \\ -3 & 2 & -1 & 2 \end{pmatrix} = \] \[ \begin{pmatrix} 2 & -4 & 4 & 4 \\ -3 & 3 & 2 & 1 \end{pmatrix} \cdot \begin{pmatrix} 0 & 3 & 4 & -2 \\ -4 & -2 & -1 & 0 \\ 1 & 2 & -4 & -4 \\ 3 & 2 & -2 & -4 \end{pmatrix} = \] \[ \begin{pmatrix} 3 & 1 & -2 & -2 \end{pmatrix} \cdot \begin{pmatrix} -4 \\ 3 \\ -2 \\ 4 \end{pmatrix} = \] \[ \begin{pmatrix} -1 & 3 & 4 \end{pmatrix} \cdot \begin{pmatrix} -1 \\ 4 \\ -3 \end{pmatrix} = \] \[ \begin{pmatrix} 1 & -4 & 3 & 3 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 0 \\ -4 \\ -1 \end{pmatrix} = \] \[ \begin{pmatrix} -4 & -4 & -3 \\ -2 & -2 & 4 \\ -3 & 4 & -3 \end{pmatrix} \cdot \begin{pmatrix} 0 & 3 & -4 & 4 \\ -1 & -2 & -3 & 1 \\ 1 & -2 & 2 & 0 \end{pmatrix} = \] \[ \begin{pmatrix} -3 & 0 & 4 & 1 \\ 0 & 1 & 1 & 4 \end{pmatrix} \cdot \begin{pmatrix} -4 & 3 & 1 & 4 \\ 1 & -4 & 1 & -3 \\ -4 & 0 & -4 & -4 \\ 1 & -2 & 4 & 4 \end{pmatrix} = \] \[ \begin{pmatrix} 4 \\ 3 \\ 4 \\ -2 \end{pmatrix} \cdot \begin{pmatrix} 2 & 4 & 3 & 3 \end{pmatrix} = \] \[ \begin{pmatrix} 1 & 2 & 0 & 3 \end{pmatrix} \cdot \begin{pmatrix} -3 \\ 1 \\ 1 \end{pmatrix} = \] \[ \begin{pmatrix} -4 & 0 & -1 & 3 \\ 0 & -4 & 3 & -3 \end{pmatrix} \cdot \begin{pmatrix} -1 & -4 & -1 \\ 3 & 2 & 0 \\ -2 & 3 & -2 \\ 1 & 2 & -2 \end{pmatrix} = \] \[ \begin{pmatrix} 2 & 0 & 3 \\ 1 & -4 & -1 \\ 3 & 0 & -2 \end{pmatrix} \cdot \begin{pmatrix} 0 & 2 & -1 & -2 \\ -1 & -1 & -3 & 4 \\ 2 & 4 & -4 & 1 \end{pmatrix} = \] \[ \begin{pmatrix} -1 & 4 \end{pmatrix} \cdot \begin{pmatrix} 0 \\ 1 \end{pmatrix} = \] \[ \begin{pmatrix} -4 & 3 \\ -4 & 0 \\ -2 & -2 \end{pmatrix} \cdot \begin{pmatrix} 0 & 1 & -4 & 2 \\ 2 & 3 & -2 & -1 \end{pmatrix} = \] \[ \begin{pmatrix} -2 & -1 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ -2 \end{pmatrix} = \] \[ \begin{pmatrix} -2 & 2 & -2 & -3 \\ 2 & -4 & -2 & 2 \\ 0 & 2 & -2 & -2 \\ 1 & -2 & -2 & -2 \end{pmatrix} \cdot \begin{pmatrix} 1 & -2 & 2 \\ -4 & -2 & -2 \\ 3 & 1 & 4 \\ -4 & 1 & -2 \end{pmatrix} = \] \[ \begin{pmatrix} -1 & -3 & 0 & -1 \\ 4 & -2 & 1 & 2 \end{pmatrix} \cdot \begin{pmatrix} -3 & -4 \\ -4 & 0 \end{pmatrix} = \] \[ \begin{pmatrix} -1 & 1 & -2 \\ -2 & 2 & -4 \\ 1 & -2 & -2 \end{pmatrix} \cdot \begin{pmatrix} -1 & 2 & -4 \\ 1 & 3 & 0 \\ 1 & 4 & -4 \end{pmatrix} = \] \[ \begin{pmatrix} -3 & 3 \\ -3 & 2 \end{pmatrix} \cdot \begin{pmatrix} 2 & -3 \\ -2 & -4 \end{pmatrix} = \] \[ \begin{pmatrix} 1 & 1 & -3 \end{pmatrix} \cdot \begin{pmatrix} -1 \\ -2 \\ 3 \end{pmatrix} = \] \[ \begin{pmatrix} -4 & 2 & 1 \\ 4 & 0 & -2 \\ 2 & 3 & -3 \\ -2 & -2 & -2 \end{pmatrix} \cdot \begin{pmatrix} -1 & 2 & 0 & -2 \\ 2 & -2 & 0 & -1 \\ -4 & 3 & -3 & 4 \end{pmatrix} = \] \[ \begin{pmatrix} -2 & -4 & 2 & 4 \\ 3 & -3 & 2 & 1 \end{pmatrix} \cdot \begin{pmatrix} 0 & 4 & -1 & -4 \\ 2 & 3 & -4 & -1 \\ 3 & 2 & -2 & 4 \end{pmatrix} = \] \[ \begin{pmatrix} -3 & -2 & -1 & -3 \end{pmatrix} \cdot \begin{pmatrix} 2 \\ -2 \\ 3 \\ -2 \end{pmatrix} = \] \[ \begin{pmatrix} 4 & 4 & 2 & 3 \end{pmatrix} \cdot \begin{pmatrix} 3 \\ 3 \\ -2 \\ 1 \end{pmatrix} = \] \[ \begin{pmatrix} 3 & 2 & -2 \end{pmatrix} \cdot \begin{pmatrix} 2 \\ 4 \\ 3 \end{pmatrix} = \] \[ \begin{pmatrix} 2 & -1 & 0 & -2 \\ 0 & -4 & -3 & -1 \end{pmatrix} \cdot \begin{pmatrix} 4 & -3 & 2 & 4 \\ -3 & -4 & 1 & 1 \\ 1 & 3 & -2 & 3 \\ -1 & -2 & 3 & 0 \end{pmatrix} = \] \[ \begin{pmatrix} -3 & -3 & 3 & 2 \\ 2 & 2 & -3 & 1 \end{pmatrix} \cdot \begin{pmatrix} 0 & 1 \\ 4 & 2 \\ -3 & -1 \\ -3 & 4 \end{pmatrix} = \] \[ \begin{pmatrix} -4 & -3 \end{pmatrix} \cdot \begin{pmatrix} -2 \\ 3 \\ 4 \end{pmatrix} = \] \[ \begin{pmatrix} 4 & 4 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 4 \\ -1 \end{pmatrix} = \] \[ \begin{pmatrix} 1 & -2 & 3 \end{pmatrix} \cdot \begin{pmatrix} 3 \\ 1 \\ 2 \end{pmatrix} = \] \[ \begin{pmatrix} -3 & 2 \end{pmatrix} \cdot \begin{pmatrix} -1 \\ 1 \end{pmatrix} = \] \[ \begin{pmatrix} -2 & -4 & -4 & 0 \\ 0 & 3 & 4 & -4 \\ 4 & 2 & -2 & -4 \\ 0 & 0 & 4 & -1 \end{pmatrix} \cdot \begin{pmatrix} 0 & -1 \\ -1 & 1 \\ -4 & -3 \\ 2 & 1 \end{pmatrix} = \] \[ \begin{pmatrix} -3 \\ 3 \\ -3 \\ -4 \end{pmatrix} \cdot \begin{pmatrix} 2 & 4 & -2 & 1 \end{pmatrix} = \] \[ \begin{pmatrix} 2 \\ 0 \end{pmatrix} \cdot \begin{pmatrix} -1 & -3 & -2 & 2 \end{pmatrix} = \] \[ \begin{pmatrix} 0 & -4 & -4 & 4 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 4 \\ 0 \\ 4 \end{pmatrix} = \] \[ \begin{pmatrix} -3 & -1 \\ -3 & -1 \end{pmatrix} \cdot \begin{pmatrix} 0 & -3 & 3 & -2 \\ -4 & 1 & -1 & 4 \end{pmatrix} = \] \[ \begin{pmatrix} 4 & 0 \\ -1 & 4 \\ 1 & -3 \end{pmatrix} \cdot \begin{pmatrix} -4 & -4 \\ -4 & 2 \end{pmatrix} = \] \[ \begin{pmatrix} -1 \\ 3 \\ 2 \\ 4 \end{pmatrix} \cdot \begin{pmatrix} 0 & -1 & 0 & 0 \end{pmatrix} = \] \[ \begin{pmatrix} 3 \\ -2 \\ 2 \\ 3 \end{pmatrix} \cdot \begin{pmatrix} -2 & -3 & -4 & 2 \end{pmatrix} = \] \[ \begin{pmatrix} 2 & -2 & -4 & 4 \\ 0 & 1 & -3 & -2 \\ -1 & 3 & 0 & -2 \end{pmatrix} \cdot \begin{pmatrix} -4 & 1 \\ -4 & 3 \end{pmatrix} = \] \[ \begin{pmatrix} -4 & -1 & 3 \end{pmatrix} \cdot \begin{pmatrix} -4 \\ -3 \\ 3 \end{pmatrix} = \] \question \textbf{Automatic generation of exercises} Write some matlab code that generates exercises like this one automatically! :-) \end{questions} \end{document}