Wichita State University Logo

M451: Mathematical Computing with MATLAB©

Assignment 2: Vectors and Matrices



Instructions:

Be sure to type diary on to start your work session. Please name your diary file (first initial)(Last name)L02. For example, my file would be jMearsL02.


Exercises:

  1. Enter the following matrices into MATLAB©. Don't clear your work after you enter them.
    $$ A = \left(\begin{matrix} -1 & 1 \\ 2 & 3 \end{matrix}\right), \quad B = \left(\begin{matrix} 1 & 2\\ 3 & 4\end{matrix}\right), \quad C = \left(\begin{matrix} 1 & 2 & 3\\ -2 & 6 & 9\end{matrix}\right),\quad D=\left(\begin{matrix} 2 & 2 & -2 & 4\\1 & 3 & 5 & 7\\2 & 4 & 6 & 8\end{matrix}\right) $$
  2. Using the above matrices, find $A*B$ and $B*A$ by hand, and then using MATLAB.

  3. The rand function creates a row vector, column vector, or matrix with pseudo-random entries between 0 and 1. (type help rand for more information). Create a new matrix $F$ which is $3\times 3$ and has all random entries.

  4. Store the first column of $F$ in a vector called $x$, and then replace the second column of $D$ by $x$. What happens if you try to replace the second column of $C$ by $x$?

  5. An important operator that you will find useful in MATLAB© is the : operator. It allows us to easily create vectors with equally spaced elements. For example, type z = 1:10 into MATLAB© and describe the results. Next type w = 1:2:10 into MATLAB© and describe the results. What does the middle term :2: determine? Now using this idea and the : operator to replace the first row of $D$ with the vector $(2, 4, 6, 8)$.

  6. One nice thing about arrays and matrices is that most built-in functions for MATLAB© will work using arrays and matrices as inputs. To see this, use the : operator to create the vector $y = \left(0,\dfrac{\pi}{2},\pi,\dfrac{3\pi}{2},2\pi\right)$. Then enter sin(y) and explain the results.


© 2020 Justin L. Mears

Your use of any material found at this site is subject to this Creative Commons License.