0% found this document useful (0 votes)
308 views8 pages

Tarea 2

This document provides 33 exercises for creating and manipulating arrays in MATLAB. The exercises involve creating vectors and matrices with specific elements using operations like concatenation, indexing, and transposition. Students are asked to write a MATLAB script to solve each exercise without explicitly typing out array elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
308 views8 pages

Tarea 2

This document provides 33 exercises for creating and manipulating arrays in MATLAB. The exercises involve creating vectors and matrices with specific elements using operations like concatenation, indexing, and transposition. Students are asked to write a MATLAB script to solve each exercise without explicitly typing out array elements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

TAREA 2

CREACIN Y MANIPULACIN DE ARREGLOS

1. UTILIZANDO MATLAB REALIZA UN SCRIPT EN EL CUAL DESARROLLES LA


SOLUCIN DE CADA UNO DE LOS SIGUIENTES EJERCICIOS.

2. AL INICIO DEL SCRIPT Y EN FORMA DE COMENTARIOS DEBES INDICAR TU


NOMBRE Y GRUPO.

3. EL SCRIPT DEBE SER ALMACENADO CON LAS INICIALES DE TU NOMBRE,


INICIANDO POR APELLIDOS.

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.

17. Create two column vectors: a=[2:3:17] and b=[3:4:15]. Then, by


only using the name of the vectors (a and b), create a column vector c that is
made from the elements of a followed by the elements of b.
18. Create a vector (name it vtA) that has 10 elements of which the first is 8, the
increment is 7, and the last element is 71. Then, assign elements of vtA to a
new vector (call it vtB) such that vtB has 7 elements. The first 4 elements
are the first 4 elements of the vector vtA, and the last 3 are the last 3 elements
of the vector vtA. Do not type the elements of vtA vector explicitly.

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

27. Create three row vectors:


a = 3 1 5 11 4 2 , b = 7 9 2 13 1 2 , c = 2 4 7 8 0 9
(a) Use the three vectors in a MATLAB command to create a 3 6 matrix in
which the rows are the vectors a, b, c, and c.
(b) Use the three vectors in a MATLAB command to create a 6 3 matrix in
which the columns are the vectors b, c, and a.

28. Create three row vectors:


a = 3 1 5 11 4 2 , b = 7 9 2 13 1 2 , c = 2 4 7 8 0 9
(a) Use the three vectors in a MATLAB command to create a 3 4 matrix
such that the first, second, and third rows consist of the last four elements
of the vectors a, b, and c, respectively.
(b) Use the three vectors in a MATLAB command to create a 3 3 matrix
such that the first, second, and third columns consist of the first three ele-
ments of the vectors a, b, and c, respectively.

29. Create two row vectors:


a = 3 9 0.5 3.6 1.5 0.8 4 , b = 12 0.8 6 2 5 3 7.4
(a) Use the two vectors in a MATLAB command to create a 3 4 matrix
such that the first row consists of elements 3 through 6 of vector a, the
second row consists of elements 4 through 7 of vector a, and the third row
consists of elements 2 through 5 of vector b.
(b) Use the two vectors in a MATLAB command to create a 6 2 matrix
such that the first column consists of elements 2 through 7 of vector a,
and the second column consists of elements 1 through 3 and 5 through 7
of vector b.

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]

31. The following vector is defined in MATLAB:


v = 6 11 4 5 8 1 0.2 7 19 5
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=v(3:8) (b) b=v([1,3,2:7,4,6]) (c) c=v([9,1,5,4])

32. The following vector is defined in MATLAB:


v = 6 11 4 5 8 1 0.2 7 19 5
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=[v([1:3 7:-1:5]);v([10,1,4:6,2])]
(b) b=[v([9,2:4,1])' v([5 3 10 2 7])' v([10:-2:4,10])']

33. Create the following matrix A.


36 34 32 30 28 26
A = 24 22 20 18 16 14
12 10 8 6 4 2
By writing one command and using the colon to address range of elements
(do not type individual elements explicitly), use the matrix A to:
(a) Create a six-element row vector named ha that contains the elements of
the second row of A.
(b) Create a three-element column vector named hb that contains the ele-
ments of the sixth column of A.
(c) Create a five-element row vector named hc that contains the first two ele-
ments of the third row of A and the last three element of the first row of A.
34. Create the following vector A.
A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Then using the MATLABs built-in reshape function create the following
matrix B from the vector A:
1 4 7 10 13 16
B = 2 5 8 11 14 17
3 6 9 12 15 18
By writing one command and using the colon to address range of elements
(do not type individual elements explicitly), use the matrix B to:
(a) Create a nine-element column vector named Ba that contains the ele-
ments of the first, third, and fifth columns of B.
(b) Create a seven-element row vector named Bb that contains elements 2
through 5 of the second row of B and the elements of the third column of B.
(c) Create a six-element row vector named Bc that contains elements 3
through 5 of the first row, and elements 2 through 4 of the third row of B.

35. Create the following vector C.


C = 1.5 2 2.5 3 3.5 4 4.5 5 9.6 9.1 8.6 8.1 7.6 7.1 6.6 6.1
Then use MATLABs built-in reshape function and the transpose operation
to create the following matrix D from the vector C:
1.5 2 2.5 3
D = 3.5 4 4.5 5
9.6 9.1 8.6 8.1
7.6 7.1 6.6 6.1
By writing one command and using the colon to address a range of elements
(do not type individual elements explicitly), use the matrix D to:
(a) Create a eight-element column vector named Da that contains the ele-
ments of the first and third rows of D.
(b) Create an eight-element raw vector named Db that contains the elements
of the second and the fourth columns of D.
(c) Create a eight-element row vector named Dc that contains the first two
elements of the first row, the last three elements of the second column, and
the first three elements of the fourth row of D.

36. Create the following matrix E:


0 5 5 5 5 5
E = 0.1 0.3 0.5 0.7 0.7 0.9
12 9 6 3 0 3
6 7 8 9 10 11
(a) Create a 2 3 matrix F from the second and third rows, and the third
through the fifth columns of matrix E.
(b) Create a 4 4 matrix G from all rows and the third through sixth columns
of matrix E.

37. Create the following matrix H:


1.25 1.5 1.75 2 2.25 2.5 2.75
H = 1 2 3 1 2 3 4
45 40 35 30 25 20 15
(a) Create a 2 5 matrix G such that its first row includes the first three ele-
ments and the last two elements of the first row of H, and the second row
of G includes the last five elements of the third row of H.
(b) Create a 4 3 matrix K such that the first, second, third, and fourth rows
are the second, third, fifth and seventh columns of matrix H.

38. The following matrix is defined in MATLAB:


1 4 7 10 13 16
M = 2 5 8 11 14 17
3 6 9 12 15 18

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])

39. The following matrix is defined in MATLAB:


2 10 18 29 41
N = 4 12 20 32 44
6 14 23 35 47
8 16 26 38 50
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=[N(1,1:4),N(2,2:5)]
(b) B=[N(:,3)' N(3,:)]
(c) C(3:4,5:6)=N(2:3,4:5)

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

You might also like