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
(b) The column vector
(c) The row vector
(d) A column vector 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 vector of problem 1d,
(a) What is the value of the 73th element of ?
(b) Assign every seventh element of into the vector
. How many elements does
have?
What is the value of
's second-to-last element?
(c) Set elements 21 through 29 of to the values of elements 34 through 42.
(d) Set elements 21 through 29 of to the values of elements 42 through 34 (same as before but backwards!)
(e) Modify the 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
(b) Change 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 matrix A of zeros.
(b) Assign the upper-left submatrix of A to
(c) Assign ones to the bottom-right submatrix of A.
(d) Set the third column of A to a normally-distributed random vector.
(e) What is the fourth row of ?
(f) What is the central submatrix of
?