Tarea 2
Tarea 2
1. Create a row vector that has the following elements: 8, 10 4 , 12 1.4 , 51,
tan 85 , 26 , and 0.15.
25
2. Create a row vector that has the following elements: 15 10 3 , ----------------2- ,
14 6
sin 65
ln 35 0.4 3 , ----------------- , 129, and cos2 ( 20 ) .
cos 80
( 14 tan 58 )
3. Create a column vector that has the following elements: 25.5, ---------------------------
-,
2 ( 2.1 + 11 )
6! , 2.7 4 , 0.0375, and 5 .
32
4. Create a column vector that has the following elements: ---------2 , sin2 35 , 6.1,
3.2
ln 29 2 , 0.00552, ln2 29 , and 133.
5. Define the variables x = 0.85 , y = 12.5 , and then use them to create a col-
umn vector that has the following elements: y , y x , ln ( y x ) , x y , and
x+y.
6. Define the variables a = 3.5 , b = 6.4 , and then use them to create a row
vector that has the following elements: a , a 2 , a b , a b , and a .
7. Create a row vector in which the first element is 1 and the last element is 43,
with an increment of 6 between the elements (1, 7, 13, , 43).
8. Create a row vector with 11 equally spaced elements in which the first ele-
ment is 96 and the last element is 2.
9. Create a column vector in which the first element is 26, the elements decrease
with increments of 3.6, and the last element is 10. (A column vector can be
created by the transpose of a row vector.)
10. Create a column vector with 9 equally spaced elements in which the first ele-
ment is 34 and the last element is 7. (A column vector can be created by the
transpose of a row vector.)
11. Using the colon symbol, create a row vector (assign it to a variable named
Fives) with five elements that are all 5.
12. Using the linspace command, create a row vector (assign it to a variable
named Nines) with nine elements that are all 9.
13. Use a single command to create a row vector (assign it to a variable named a)
with 6 elements such that the last element is 4.7 and the rest of the elements
are 0s. Do not type the vector elements explicitly.
14. Use a single command to create a row vector (assign it to a variable named b)
with 8 elements such that the last three element are 3.8 and the rest of the ele-
ments are 0s. Do not type the vector elements explicitly.
15. Use a single command to create a row vector (assign it to a variable named b)
with 11 elements such that
b =
0 2 4 6 8 10 12 9 6 3 0
Do not type the vector explicitly.
16. Create two row vectors: a=2:3:17 and b=3:4:15. Then, by only using the
name of the vectors (a and b), create a row vector c that is made from the ele-
ments of a followed by the elements of b.
19. Create a vector (name it vctC) that has 12 elements of which the first is 5, the
increment is 4 and the last element is 49. Then, by assigning elements of
vctC to new vectors, create the following two vectors:
(a) A vector (name it Codd) that contains all the elements with odd index of
vctC; i.e., Codd = 5 13 21 ... 45.
(b) A vector (name it Ceven) that contains all the elements with even index
of vct; i.e., Ceven = 9 17 25 ... 49.
In both parts use vectors of odd and even numbers for the index of Codd and
Ceven, respectively. Do not type the elements of the vectors explicitly.
20. Create a vector (name it vctD) that has 9 elements of which the first is 0, the
increment is 3 and the last element is 27. Then create a vector (name it vct-
Dop) that consist of the elements of vctD in reverse order. Do it by assigning
elements of vctD to vctDop. (Do not type the elements of vctDop vector
explicitly.)
21. Create the following matrix by using vector notation for creating vectors with
constant spacing and/or the linspace command. Do not type individual
elements explicitly.
130 110 90 70 50 30 10
A = 1 2.8333 4.6667 6.5 8.3333 10.1667 12
12 22 32 42 52 62 72
22. Create the following matrix by using vector notation for creating vectors with
the linspace command. Do not type individual elements explicitly.
5 2 3
B = 5 2 3
5 2 3
5 2 3
23. Create the following matrix by typing one command. Do not type individual
elements explicitly.
C = 7 7 7 7 7
7 7 7 7 7
24. Create the following matrix by typing one command. Do not type individual
elements explicitly.
0 0 0 0 8
D = 0 0 0 0 7
0 0 0 0 6
25. Create the following matrix by typing one command. Do not type individual
elements explicitly.
0 0 0 0 0
E = 0 0 0 0 0
0 0 5 4 3
0 0 2 1 0
26. Create the following matrix by typing one command. Do not type individual
elements explicitly.
0 0 0 0 0
F = 0 0 1 10 20
0 0 2 8 26
0 0 3 6 32
30. By hand (pencil and paper) write what will be displayed if the following com-
mands are executed by MATLAB. Check your answers by executing the com-
mands with MATLAB. (Parts (b), (c), (d), and (e) use the vector that was
defined in part (a).)
(a) a=1:4:17 (b) b=[a(1:3) a] (c) c=[a;a]
(d) d=[a a] (e) e=[[a; a; a; a; a] a]
By hand (pencil and paper) write what will be displayed if the following com-
mands are executed by MATLAB. Check your answers by executing the com-
mands with MATLAB.
a) A=M([1,3],[1,5,6]) b) B=M(:,[4,4:6])
c) C=M([1,2],:) d) D=M([2,3],[2,3])
40. By hand (pencil and paper) write what will be displayed if the following com-
mands are executed by MATLAB. Check your answers by executing the com-
mands with MATLAB.
v=1:2:23
M=reshape(v,3,4)
M(2,:)=[]
M(:,3)=[]
N=ones(size(M))
41. Using the zeros, ones, and eye commands, create the following arrays by
typing one command:
1 1 1 1
(a) 11 0 0 (b) 10 0 0 1 1 (c) 0 0 0 0
11 0 0 01 0 0 1 1
0 0 0 0
42. Using the zeros, ones, and eye commands create the following arrays by
typing one command:
1 1 1 1 0 1 1 1 0
(a) 1 0 1 10 (b) 1 1 1 1 (c) 0 1 1 1 0
0 1 1 10 1 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 1
43. Use the eye, ones, and zeros commands to create the following arrays:
A = 1 0 B = 1 1 C = 0 0
0 1 1 1 0 0
Using the variables A, B, and C, write a command that creates the following
matrix D:
1 0 1 1 0 0
D = 0 1 1 1 0 0
0 0 1 1 1 0
0 0 1 1 0 1
44. Create a 2 3 matrix A in which all the elements are 1. Then reassign A to
itself (several times) such that A will become:
1 1 0 0
1 1 0 0
A = 1 1 0 0
0 0 1 1
0 0 1 1
0 0 1 1