Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. % Vignesh Kumar
  2. % RUID last 4 digits: 3719
  3. % Math 250 Lab Assignment #2
  4. % Section C2
  5. rand('seed', 3719)
  6. % Question 1 (a)
  7. A = rmat(3,5), rank(A(:,1:3))
  8. A =
  9. 5 4 2 0 9
  10. 5 8 3 6 6
  11. 1 6 2 9 9
  12. ans =
  13. 3
  14. b = rvect(3), R = rref([A b])
  15. b =
  16. 1
  17. 8
  18. 4
  19. R =
  20. Columns 1 through 4
  21. 1.0000 0 0 -2.0000
  22. 0 1.0000 0 0.5000
  23. 0 0 1.0000 4.0000
  24. Columns 5 through 6
  25. -5.0000 2.3333
  26. -10.0000 6.1667
  27. 37.0000 -17.6667
  28. S = R(:,1:5)
  29. S =
  30. Columns 1 through 4
  31. 1.0000 0 0 -2.0000
  32. 0 1.0000 0 0.5000
  33. 0 0 1.0000 4.0000
  34. Column 5
  35. -5.0000
  36. -10.0000
  37. 37.0000
  38. % Question 1 (a) (i) Columns 1, 2, and 3 are the pivot columns
  39. % Question 1 (a) (ii) The rank of both matrices are 3 since there are 3 pivots
  40. % Question 1 (a) (iii) Nullity is equal to 2 since it is # of columns - rank
  41. % Question 1 (a) (iv) Since there are no zero rows, Ax = b is consistent for all values
  42. % Question 1 (b)
  43. c = R(:,6)
  44. c =
  45. 2.3333
  46. 6.1667
  47. -17.6667
  48. x = [c; 0; 0]
  49. x =
  50. 2.3333
  51. 6.1667
  52. -17.6667
  53. 0
  54. 0
  55. A*x - b
  56. ans =
  57. 1.0e-14 *
  58. 0
  59. -0.3553
  60. 0
  61. S*x - c
  62. ans =
  63. 0
  64. 0
  65. 0
  66. % Question 1 (b) (ii) Since Ax = b, Ax - b would mean it equals a zero vector and there are no zero rows, we know it is consistent for all b
  67. % Question 1 (c)
  68. u = [-S(:,4); 1; 0], v = [-S(:,5);0;1]
  69. u =
  70. 2.0000
  71. -0.5000
  72. -4.0000
  73. 1.0000
  74. 0
  75. v =
  76. 5
  77. 10
  78. -37
  79. 0
  80. 1
  81. % Question 1 (i)
  82. % (i) Since u and v are scaled by -1 and therefore opposites. Therefore, the sum equals 0
  83. S*u
  84. ans =
  85. 0
  86. 0
  87. 0
  88. A*u
  89. ans =
  90. 0
  91. 0
  92. 0
  93. S*v
  94. ans =
  95. 0
  96. 0
  97. 0
  98. A*v
  99. ans =
  100. 0
  101. 0
  102. 0
  103. s = rand(1), t = rand(1), y = s*u + t*v
  104. s =
  105. 0.9588
  106. t =
  107. 0.5333
  108. y =
  109. 4.5843
  110. 4.8540
  111. -23.5689
  112. 0.9588
  113. 0.5333
  114. % Question 1 (c) (ii)
  115. % Ay = 0 since Az = A(x+y)=Ax+Ay, and Ax=Ax+Ay, therefore you can assume Ax+Ay=b
  116. % Question 1 (d)
  117. z = x + y
  118. z =
  119. 6.9176
  120. 11.0207
  121. -41.2356
  122. 0.9588
  123. 0.5333
  124. A*z-b
  125. ans =
  126. 1.0e-13 *
  127. 0.0400
  128. 0.1421
  129. 0.0799
  130. u1 = rvect(3), u2= rvect(3), u3 = rvect(3), u4 = rvect(3)
  131. u1 =
  132. 8
  133. 3
  134. 3
  135. u2 =
  136. 2
  137. 8
  138. 4
  139. u3 =
  140. 2
  141. 9
  142. 9
  143. u4 =
  144. 4
  145. 9
  146. 5
  147. % Question 2 (a)
  148. A = [u1 u2 u3], rref(A)
  149. A =
  150. 8 2 2
  151. 3 8 9
  152. 3 4 9
  153. ans =
  154. 1 0 0
  155. 0 1 0
  156. 0 0 1
  157. % Question 2(i)
  158. % Since there are no free variables and it is linearly independent (nullity=0)
  159. % Question 2 (b)
  160. B = [u1 u2 u3 u4], rref(B)
  161. B =
  162. 8 2 2 4
  163. 3 8 9 9
  164. 3 4 9 5
  165. ans =
  166. 1.0000 0 0 0.2424
  167. 0 1.0000 0 1.0000
  168. 0 0 1.0000 0.0303
  169. % Question 2 (bi)
  170. % There is one free variable, and it is therefore linearly dependent since nullity>0
  171. % Question 2 (c)
  172. % Since both u1,u2 have random scalar values and v is a linear combination of u1&u2, we can say the set is linearly independent
  173. v = rand(1)*u1 + rand(1)*u2
  174. v =
  175. 0.6205
  176. 1.8517
  177. 0.9584
  178. V = [u1, u2, v], rref(V)
  179. V =
  180. 8.0000 2.0000 0.6205
  181. 3.0000 8.0000 1.8517
  182. 3.0000 4.0000 0.9584
  183. ans =
  184. 1.0000 0 0.0217
  185. 0 1.0000 0.2233
  186. 0 0 0
  187. % Question 3 (a)
  188. A = rmat(2,3), B = rmat(3, 4), C = rmat(4,3), v = rvect(4)
  189. A =
  190. 2 8 4
  191. 5 3 8
  192. B =
  193. 3 2 1 6
  194. 4 3 7 5
  195. 6 7 5 0
  196. C =
  197. 4 5 2
  198. 9 1 8
  199. 8 3 9
  200. 8 6 1
  201. v =
  202. 5
  203. 1
  204. 6
  205. 8
  206. u = B*v, A*u, D = A*B, D*v
  207. u =
  208. 71
  209. 105
  210. 67
  211. ans =
  212. 1250
  213. 1206
  214. D =
  215. 62 56 78 52
  216. 75 75 66 45
  217. ans =
  218. 1250
  219. 1206
  220. % Question 3 (b)
  221. A = [0 1; 0 0], B = [0 0; 1 0], C = [0 1;1 0]
  222. A =
  223. 0 1
  224. 0 0
  225. B =
  226. 0 0
  227. 1 0
  228. C =
  229. 0 1
  230. 1 0
  231. A*B
  232. ans =
  233. 1 0
  234. 0 0
  235. B*A
  236. ans =
  237. 0 0
  238. 0 1
  239. % When you take the product matrix of AB and Ba, they aren't equal to each other
  240. (A + B)^2
  241. ans =
  242. 1 0
  243. 0 1
  244. (A^2)+(2*(A*B))+(B^2)
  245. ans =
  246. 2 0
  247. 0 0
  248. % A^2=0, since it is matrix multiplication, which follows the row*column form, if it were a number it would have been the square of a number
  249. % Question 3 (iii)
  250. A*C
  251. ans =
  252. 1 0
  253. 0 0
  254. A*B
  255. ans =
  256. 1 0
  257. 0 0
  258. % Since this is matrix multiplication, you can not infer that they are the same unless they are identity matrixes. If this was numbers, you would be able to assume that A, B, and C are the same
  259. % Although, they are clearly not the same in this case with matrixes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement