You are on page 1of 8

MATLAB EXERCISES

Use Matlab to calculate the following expressions

1 122  2
x 
1. 21 36  log(5)
y  2
2.
x
z   log( x) log10 ( y )  x y
3. y
x
4. 0

x  9
5.
MATLAB EXERCISES

6. In the Matlab command window, use the “upper arrow” key on


your keyboard to recall the command corresponding to the
command for Ex.1(1). Then use the “left arrow” and “right
arrow” key to edit the command such that you can calculate

1 122  2
x 
22 36 log(7)
MATLAB EXERCISES

7. Calculate x + z. Then use the clear command to clear the


variables x and z, and try x + z again.

8. Use the lookfor command to find out the command


corresponding to the log2(𝑦) function, then use the help
command to obtain detailed.
MATLAB EXERCISES
9. Create a row vector that starts with -10, ends at 18, with a step
size of 4.
10. Create a column vector that starts with 6, ends at -9, with a
step size -3.
11. Create a row vector that starts with 1, ends at 90, and has
exactly 20 elements.
12. Create the following three matrices

2 3 7 1  i 2 
1 2 3
A   B  C   3 4  i 
1 5 6 4 5 6  5 6 

13. Calculate A + B, B + 2, A - transpose(C), element-wise A.*B


and A./B
MATLAB EXERCISES
14. Is A*B valid? Is A*transpose(B) valid?
15. Use matrix indexing access the following elements:
i. The element on the 2 nd row and 3 rd column of A
ii. The 2 nd row of B
iii. The 3 rd column of A
iv. The elements on the 2 nd row and 2 nd and 3 rd columns of
A
v. A new 2x2 matrix D, the 1 st column of D is the 2 nd column
of A, and the 2 nd column of D is the 3 rd column of B.

16. Use a logic matrix to indicate the locations where the elements of
A and B are the same.
17. Find the elements of B that is less than or equal to 3
MATLAB EXERCISES
18. Write a short MATLAB expression to build the following matrix

1 2 3 4 5 6 7 
A9 7 5 3 1 1 3 
4 8 16 32 64 128 256

19. Give a Matlab expression that multiplies two vectors to obtain

0 0 0
1 2 3 4 5 1 1 1 

i) A1 2 3 4 5 ii) A  2 2 2
 
1 2 3 4 5 3 3 3
 4 4 4 
MATLAB EXERCISES
20. For given matrix, give MATLAB expression that uses only a
single matrix multiplication with A to obtain

1 2 3 4 5 6 7 
A9 7 5 3 1 1 3 
4 8 16 32 64 128 256

i) the sum of columns 5 and 7 of A


ii) the last row of A
iii) a version of A with rows 2 and 3 swapped
MATLAB EXERCISES
21. Let x=[1 2 3]. Write MATLAB commands to compute the
following and write the result
i) cos(x)sin(x)
ii) sin(x)2
iii) sin(x2)
iv) f(x)= 7x2sin(1/7x2)
v) f(x)= x-(cos(x)-sin(x)/sin(x)+cos(x))
vi) f(x)= 1/10(x-x3/2/10)2

22. Let a=1:2:20 b=1:10 c=1:2:10


comment on the following using MATLAB
i) b+c ii) a+b iii) a./b iv) a*b

You might also like