Matlab Lab Assignment A7

This assignment is designed only to get you to practice using Matlab and to
learn its basic operations . It is not terribly long, and you should be able to do
most of it during your lab on the last week of classes. It counts as a lab, and
it also counts as an assignment: it will be graded, and the grade will be count
toward your final weighted total.

No groups for this assignment . Do it by yourself.
Submit on the CMS a file named a7.m that contains: (1) as a comment, your
name and your netid (2) the answers to the questions below. Most of the answers
are matlab expressions, statements, or functions. When answering a question,
first get it working correctly in the Command- line window . When it works
properly, copy it to file a7.m. Label the answers with the question number and
them in ascending order. If an answer is not a matlab expression, statement,
or function, then make the answer a Matlab comment.

Do not use loops in this assignment.
it simply as a text file and just put things into it.

1 Matrix Operations

1. Write assignment statements that assign these two matrices to A and B:

2. Type an expression to catenate B’s columns to A’s rows, resulting in the
following matrix:

3. Type an expression to catenate B’s rows to A’s columns resulting in the
following matrix:

4. Try calculating A + B and explain what happens.
5. The previous expression doesn’t work due to dimensions mismatch, now
do the following. (Remember that At is the transpose of A, which is found
by interchanging rows and columns.)

(a) Calculate the following two matrices : C1 = At+B and C2 = A+Bt.
(b) Write a one- line expression that checks whether ; This expression
should return 1 if the equality holds and 0 otherwise. (Hint:
use functions find and isempty).

6. Type an expression that results in a 4x5 matrix all of whose elements are
(don’t type the elements one by one !)

7. Type an expression that results in a 3x4 matrix all of whose elements are
equal to 5. (don’t type the elements one by one !)

8. Type an expression that creates a vector (one-dimensional array) whose
elements are the odd numbers in the range 1..23.

9. Type a one-line expression (don’t type the elements one by one) that
results in the following matrix:

10. Write an expression that results in a matrix each element of which is the
square of the corresponding element from matrix D1 in (10), i.e.

11. Write a one-line expression whose value is this sum :
3 + 6 + 9 + 12 + 15 + . . . + 297
Use function sum.

12. Define the following two arrays:

Write an expression that will calculate the following sum based on v1 and

13. Given are two series:

Write a one-line expression whose value is the first 10 elements of the series

Hint: Use function cumsum.

2 Functions and Plots

1. Write a function (it should not use loops) whose parameter is a matrix
with an odd number of rows and that yields the matrix reflected over its
horizontal symmetric axis. The input matrix has at least 3 rows . For
example, for the argument matrix:

the function returns this matrix:

Hint 1: Use function size to determine the number of lines. [numrows] =
size(Din, 1).
Hint 2: If you think that you need an integer division (though you really
don’t need one) use matlab function floor.

2. Plot the sin function over the range [−2 × π, . . . , +2 × π]. The step size
should be 0.1. Your expression should be a one-line expression. You can
use the matlab constant pi.

Prev Next