User Tools

Site Tools


gibson:teaching:spring-2015:math445:lab2

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gibson:teaching:spring-2015:math445:lab2 [2015/01/28 10:55]
gibson created
gibson:teaching:spring-2015:math445:lab2 [2015/01/28 12:40] (current)
gibson
Line 1: Line 1:
 ====== Math 445 lab 2: Vectors and Matrices ====== ====== Math 445 lab 2: Vectors and Matrices ======
  
-**1** +---- 
 + 
 +**Problem ​1.** Creation of vectors. Show how to create the following vectors in Matlab three different ways,  
 +using square brackets, ''​linspace,''​ and colon syntax.  
 + 
 +**(a)** The row vector  
 + 
 +\begin{eqnarray*} 
 +x = (1, 3, 5, 7, 9) 
 +\end{eqnarray*} 
 + 
 +**(b)** The column vector  
 + 
 +\begin{eqnarray*}  
 +x = \left(\begin{array}{c} 
 +     5 \\ 1 \\ -3 \\ -7 \\ -11 
 +    \end{array}\right) 
 +\end{eqnarray*}  
 + 
 +**%%(c)%%** The row vector  
 + 
 +\begin{eqnarray*} 
 +x = (1, 3, 9, 27, 81) 
 +\end{eqnarray*} 
 + 
 +**(d)** A column vector $x$ of 100 evenly spaced values between -1 and 13, including those endpoints. Listing  
 +out all the elements with square bracket syntax would be very tedious and error-prone,​ so just show how to  
 +do this with ''​linspace''​ and colon syntax.  
 + 
 +---- 
 + 
 +**Problem 2:** Extracting and assigning subvectors. Given the $x$ vector of problem 1d, 
 + 
 +**(a)** What is the value of the 73th element of $x$? 
 + 
 +**(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? 
 + 
 +**%%(c)%%** Set elements 21 through 29 of $x$ to the values of elements 34 through 42. 
 + 
 +**(d)** Set elements 21 through 29 of $x$ to the values of elements 42 through 34 (same as before but backwards!) 
 + 
 +**(e)** Modify the $x$ vector so that every other element between 21 through 31 is zero.  
 + 
 +---- 
 + 
 +**Problem 3.** Creation of matrices, extracting and assigning elements and subvectors. 
 + 
 +**(a)** Create the matrix A 
 +\begin{eqnarray*} 
 +A = \left[ \begin{array}{rrr} 3 & 7 & 2 \\ -2 & 4 & 6 \\ 5 & 1 & 0 \end{array} \right] 
 +\end{eqnarray*} 
 + 
 +**(b)** Change $A_{2,3}$ to 7. 
 + 
 +**%%(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 
 +that extracts the second column, multiplies it by 2, and then assigns it back into the second column. 
 + 
 +---- 
 + 
 +**Problem 4. Extracting and assigning submatrices.**  
 + 
 +**(a)** Create a $5 \times 5$ matrix A of zeros. ​  
 + 
 +**(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] 
 +\end{eqnarray*} 
 + 
 +**%%(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. 
 + 
 +**(e)** What is the fourth row of $A$? 
 + 
 +**(f)** What is the central $3 \times 3$ submatrix of $A$?
gibson/teaching/spring-2015/math445/lab2.1422471315.txt.gz · Last modified: 2015/01/28 10:55 by gibson