====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
gibson:teaching:spring-2015:math445:lab2 [2015/01/28 12:31] gibson |
gibson:teaching:spring-2015:math445:lab2 [2015/01/28 12:40] (current) gibson |
||
---|---|---|---|
Line 3: | Line 3: | ||
---- | ---- | ||
- | **Problem 1.** Show how to create the following vectors in Matlab three different ways, | + | **Problem 1.** Creation of vectors. Show how to create the following vectors in Matlab three different ways, |
using square brackets, ''linspace,'' and colon syntax. | using square brackets, ''linspace,'' and colon syntax. | ||
Line 32: | Line 32: | ||
---- | ---- | ||
- | **Problem 2:** subvectors. Given the $x$ vector of problem 1d, | + | **Problem 2:** Extracting and assigning subvectors. Given the $x$ vector of problem 1d, |
**(a)** What is the value of the 73th element of $x$? | **(a)** What is the value of the 73th element of $x$? | ||
- | **(b)** Assign every seventh element of $x$ and into the vector $v$. How many elements does $v$ have? | + | **(b)** Assign every seventh element of $x$ into the vector $v$. How many elements does $v$ have? |
What is the value of $v$'s second-to-last element? | What is the value of $v$'s second-to-last element? | ||
Line 47: | Line 47: | ||
---- | ---- | ||
- | **Problem 3.** | + | **Problem 3.** Creation of matrices, extracting and assigning elements and subvectors. |
**(a)** Create the matrix A | **(a)** Create the matrix A | ||
\begin{eqnarray*} | \begin{eqnarray*} | ||
A = \left[ \begin{array}{rrr} 3 & 7 & 2 \\ -2 & 4 & 6 \\ 5 & 1 & 0 \end{array} \right] | A = \left[ \begin{array}{rrr} 3 & 7 & 2 \\ -2 & 4 & 6 \\ 5 & 1 & 0 \end{array} \right] | ||
\end{eqnarray*} | \end{eqnarray*} | ||
- | **(b)** Change $A_{2,3}$ to 7.\\ | + | |
- | **%%(c)%%** Assign the third column of A to the variable v.\\ | + | **(b)** Change $A_{2,3}$ to 7. |
- | **(d)** Change the first row of A to (8, 1, 4)\\ | + | |
+ | **%%(c)%%** Assign the third column of A to the variable v. | ||
+ | |||
+ | **(d)** Change the first row of A to (8, 1, 4). | ||
**(e)** Change A so that all the values in the second column are doubled. Do this in one line of Matlab code | **(e)** Change A so that all the values in the second column are doubled. Do this in one line of Matlab code | ||
that extracts the second column, multiplies it by 2, and then assigns it back into the second column. | that extracts the second column, multiplies it by 2, and then assigns it back into the second column. | ||
Line 60: | Line 65: | ||
---- | ---- | ||
- | **Problem 4.** | + | **Problem 4. Extracting and assigning submatrices.** |
**(a)** Create a $5 \times 5$ matrix A of zeros. | **(a)** Create a $5 \times 5$ matrix A of zeros. | ||
+ | |||
**(b)** Assign the upper-left $2 \times 3$ submatrix of A to | **(b)** Assign the upper-left $2 \times 3$ submatrix of A to | ||
+ | \begin{eqnarray*} | ||
\left[ \begin{array}{rrr} 1 & -4 & 3 \\ 6 & 2 & 1 \end{array} \right] | \left[ \begin{array}{rrr} 1 & -4 & 3 \\ 6 & 2 & 1 \end{array} \right] | ||
+ | \end{eqnarray*} | ||
+ | |||
**%%(c)%%** Assign ones to the bottom-right $3 \times 3$ submatrix of A. | **%%(c)%%** Assign ones to the bottom-right $3 \times 3$ submatrix of A. | ||
+ | |||
**(d)** Set the third column of A to a normally-distributed random vector. | **(d)** Set the third column of A to a normally-distributed random vector. | ||
+ | |||
**(e)** What is the fourth row of $A$? | **(e)** What is the fourth row of $A$? | ||
+ | **(f)** What is the central $3 \times 3$ submatrix of $A$? |