All of the commands that you use to complete this quiz must be entered in the file
/phys210/$LOGNAME/matlab/q2.m
The first statement in this file must be
q2_setup
If this line is not included you will be unable to complete
the quiz. Also, if you prefer to work the questions interactively and
then transfer your answers to q2.m
be sure to type
>> q2_setup
before you do anything else.
q2_setup
is a script that defines 13 variables: 8 row vectors
v1, v1_el, m1_row, m1_col, w1, w2, w3 and w4
and 5 matrices
m1, a1, a2, a3, a4
You can display any of these by simply entering their names at the
Matlab prompt, but be warned that v1
and m1
contain many
elements. I'll leave it as an exercise for you to determine how
many.
Try to answer the questions using as few Matlab statements as possible, but note that in several cases it may be advantageous to first copy a vector or matrix and then modify it, i.e,
>> foo1 = foo
>> foo1(...) = ...
I will use (copy) to label the instances where I suggest you do this.
I will indicate the number of statements you are expected to use in the parenthesis following the question label, that number will include assignment statements used to copy arrays.
IMPORTANT: Several questions ask you to create vectors or matrices by selecting subsets of elements other vectors and matrices. Unless specified otherwise, the elements in the new arrays should be in the "same order" as those in the original.
Example 1: Given
a = 1 2 3 4 5 6 7 8 9 10
the vector
a1 = 3 9 10
is a subset of elements of a that are in the "same order" whereas
a2 = 9 3 10
is not.
Example 2: Given
m =
10 15 20 25
30 35 40 45
50 55 60 75
the matrix
m1 =
10 25
50 75
is a subset of elements of a that are in the "same order" whereas
m2 =
20 15
35 40
is not.
I will denote the questions where the order of elements is to be preserved in this manner with (order)
OK, on with the quiz, and remember that the first line in q2.m
, or
the first command that you type should you wish to first solve the
problems interactively, must be
q2_setup
Assign to v1_length
the number of elements of v1
.
Assign to m1_m
and m1_n
the number of rows and columns, respectively,
of m1
(try to do it with a single assignment statement).
Define v2
to be a column vector that contains the following elements
of v1
:
10056 24493 26631 27740 36992 45365 56733 62284 65056 84730
(e.g 10056 means the 10056-th element of v1
)
Define m2
to be the matrix that contains all elements of m1
that
are in one of the following rows:
53 59 73 106
and one of the following columns:
158 255 340
Define v3
to be the column vector containing elements 53400 through
53451, inclusive, of v1
.
Define v4
to have all of the elements of v3
except the 15th and 27th.
Do not use a :
operator, use element deletion.
Define m3
to be the matrix that contains all elements of m1
that
are in one of rows 35 through 39, inclusive, and one of columns
102 through 107 inclusive.
Define m4
to be the matrix containing the elements of m3
with
the following modifiations: (1) All elements of the middle row
of m3
except the last one have been replaced by 0.
(2) All elements of the last column of m3
have been replaced
by 1's.
Define m5
to be the matrix that contains all elements of m1
that
are in one of rows 25, 38, 51, ... 220, 233
and one of columns 10, 52, 94, .., 346, 388.
Define m6a
to be the matrix resulting from the deletion of every
third row of m5
starting with the second (i.e. delete rows
2, 5, 8). Use row deletion.
Define m6b
to be the matrix in which the entries in column 8 of
m5
have been reversed.
Define a row vector v5
which contains the following elements:
The elements of w1, followed by the elements of w2 in reverse order, followed by every 8th element of w3 starting with the 6th, followed by the 8th from last and last element of w4.
Define a column vector v5a
which contains the elements of v5
, with
the first 10 elements replaced by 0 and the last 10 by the integers from
11 through 20 in reverse order.
IMPORTANT
When you've completed the quiz, execute the following from the terminal command line:
% date > /phys210/$LOGNAME/matlab/date
YOU CAN THEN WORK ON THE HOMEWORK OR TALK TO ME ABOUT YOUR TERM PROJECTS WHILE YOU WAIT FOR THE CLASS TO FINISH THE QUIZ