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

C2 Creating Arrays Problem 5th Ed.

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
45 views8 pages

C2 Creating Arrays Problem 5th Ed.

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
2.11 Proeuens 1. Create a row vector that has the following elements: 8, 10/4, 12 « 1.4, 51, tan 85°, 4%, and 0.15. 2. Create a row vector that has the following elements: 5 «10° Ings/0.a°, S86rs, 129, and cos" (a/20). 3+ Create a column vector that has the following elements: 25, 4. Create a column vector that has the following elements: 2%, sin®g5°, 6.1, 2 [Link]. 5. Define the variables x = 0.85, y = 12.5, and then use them to create a column vector that has the following elements: y, y', In(y/x), 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 a, 0°, a/b, a+b, and sf. following element: 7. Create a row vector in which the first element is 1 and the last clement 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 element is 96 and the last clement is 2. ‘9. Create a coltumn 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 element 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 1 inspace command, create a row vector (assign it to a variable named Wines) 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 os. Do not type the veetor elements explicitly. 14, Use a single command to create a row vector (assign it to a variable named i) with 8 elements such that the last three element are 3.8 and the rest of the elements are Os. Do not type the vector elements explicitly. 15, Use a single command to create a row vector (assign it to a variable named 5) with 1 elements such that b= 0 2 4 . Do not type the vector explicitly. 36, Create two row vectors: 3=2:3:17 and: 5, Then, by only using the name of the vectors (and b), create a row vector ¢ that is made from the elements of a followed by the elements of b. 2:17)’ and b=[3:4:15) . Then, by only using the name of 17. Create two column vectors: the vectors (@ and b), create a column vector c that is made from the elements of a followed by the elements of 418, Create a vector (name it v2A) 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 vt2) such that vtB has 7 elements. The first 4 elements are the first 4 elements of the vector vt, and the last g 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 vat to new vectors, create the following two vectors: (a) A vector (name it Cod) that contains all the elements with od index of vetc; ie., Codd = 5 13 21... 45 (b) A vector (name it Coven) that contains all the elements with even index of vet; ive, Coven = 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 v=t-Dop) that consist ofthe elements of vot in reverse order. Do it by assigning elements of vet to vet Dop. (Do not type the elements of vetDop vector explicitly.) 21, Create the following matrix by using vector notation for creating vectors with constant spacing and/or the Lins; c command. Do not type individual elements explicitly. so 10 90 7 50 30a A=] 1 29333 46667 65 6.333 10.1667 12 pn pas @ 7 22, Create the following matrix by using vector notation for creating vectors with the Linspace command. Do not type individual elements explicit 523 a= [523] 523] 523 2, Create the following matrix by typing one command. Do not type individual elements explicitly e-fr77] pa717 24. Create the following matrix by typing one command. Do not type individual elements explicitly. ‘25, Create the following matrix by typing one command. Do not type individual elements explicitly foovod loo oo loos 43] looz idl 26, Create the following matrix by typing one command. Do not type individual elements explicitly foovoe lo 01 10 24 loo2 8 24 loos 6 34 27. Create three row vectors: [-24-7809] a=[3-1511-42], b=[7-9 2131-2], (a) Use the three vectors in 2 MATLAB command to create a 3 x 6 matrix in which the rows are the vectors a, b, ¢, and c. (b) Use the three vectors in a MATLAB command to create a 6 x 3 matrix in which the columns are the vectors be, and a 28, Create three row vectors: a= [37151142], b=[7-92231-2], 24-7809) (a) Use the three vectors in a MATLAB command to create a 3 x 4 matrix such that the first, second, and third rows consist of the last four elements of the vectors a, b, and e, respectivel (b) Use the three vectors in a MATLAB command to create a 3 x 3 matrix such that the first, second, and third columns consist of the first three elements of the vectors a, b, and ¢, respectively. 29. Create two row vectors: 3.9 -0.5 3.61. -0.8 4], b= 12 -0.8 6253 -7.4] (a) Use the two vectors in a MATLAB command to create a 3 x 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 § of vector b. (b) Use the two vectors in a MATLAB command to create a 6 x 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 displaved if the following commands are executed by MATLAB, Check your answers by executing the commands with MATLAB. (Parts (b), (€), (@, and (e) use the vector that was defined in part (a).) (@)aqi:4:17 (Wb=la(ts3) al (c)o=lazal’ @ela! (@erllar ar ar ar al al 31. The following vector is defined in MATLAB: v=[611-4581-0.2-7195] By hand (pencil and paper) write what will be displayed if the following commands are executed by MATLAB. Check your answers by executing the commands with MATLAB. @ a=v(3:8) (b)b=v([1,3,227,4, 61) (© cav(19/1,5,4))" 32. The following vector is defined in MATLAB: (6 11-45 81-0.2-7195] By hand (pencil and paper) write what will be displayed if the following commands are executed by MATLAB. Check your answers by executing the commands with MATLAB. @amtv({1:3 74-1:5]) 2V((10,1, 426,2))1 (@pHtv(19, 224,11)" vCl5 3 10 2 71)" v({20:-224,101) "1 39. Create the following matrix A. as 34 22 30 28 24 A= [220 20 18 16 14 rt 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 elements of the sixth column of A. (©) Create a five-clement row vector named he that contains the first two elements of the third row of A and the last three element of the first row of A. 34. Create the following vector A. A= [123456789 10111213 14 15 161718] ‘Then using the MATLAB's built-in rechape function create the following matrix B from the vector A: 1471013 16] =)seuuu| 3.691215 15 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-clement column vector named 2 that contains the elements of the first, third, and fifth columns of B. (b) Create a seven-element row vector named 5b 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 2c that contains elements 3 through 5 of the first row, and clements 2 through 4 of the third row of B. 35. Create the following vector C. C= 1152253354455 9.6 9.18.6 8.17.6 7.1 6.6 6.1] ‘Then use MATLAB's built-in reshape function and the transpose operation to create the following matrix D from the vector C: hs 22s Iss 445 5 leosisost 75741 66 61 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 Ds that contains the elements of the first and third rows of D. () Create an eight-element raw vector named Db that contains the elements of the second and the fourth columns of D. (e) 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. 96. Create the following matrix E: os sss lor 0305070709] R963 0-3 678 90m (a@) Create a 2 x 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: 1231234 fas ass 2 22825274 He ; 45 40 35 30.25 20 15, (@) Create a 2 x 5 matrix G such that its first row includes the first three elements 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 x 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: fi 47 1013 16 pssnwa p69 1215 13 By hand (pencil and paper) write what will be displayed if the following commands are executed by MATLAB. Check your answers by executing the commands with MATLAB. a) A=M([1, 31, [1,5, 61) b)yB=M(: 39. The following matris is defined in MATLAB: 2 10 18 29 a fs 12 20 32 4 6 14 23 35 a7 5 16 26 38 50 By hand (pencil and paper) write what wil be displayed if the following commands are executed by MATLAB. Check your answers by executing the commands with MATLAB. (aye IN (1, 224)" N(2, 225) 7] @ N(2,3)" N(3yE ()C(324, 526) aN (223,42 40. By hand (pencil and paper) write what willbe displayed if the following commands are executed by MATLAB. Check your answers by executing the commands with MATLAB. MQ, MGS) w snes (size (M)) 41, Using the zeros, ones, and eye commands, create the following arrays by typing one command: tai] © |oo0q 0000) @ prod & [iooor bio lor004 42. Using the zeros, ones, and eye commands create the following arrays by typing one command: hid oriie orig hi orii9 a » c oping © fe Bat p14 0001 43. Use the . ones, and zeros commands to create the following arrays: a=P9 eft] cafod fo 1 oo Using the variables 4, B, and C, write a command that creates the following matrix D: hori0d p= |1ti0d lootitol loot104 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: 110d 110d 1104 oul ooud oid

You might also like