gibson:teaching:fall-2014:math445:hw3solns

John Gibson Math 445 HW3 solutions Oct 7, 2014 Problem 1: Given the vectors x=[3 7 2 9 0] and y=[7 10 2 8 13], what would be the Matlab output for the following expressions? Think through what the answer should be, write it down, and then try it out in Matlab. If you got anything wrong, figure out what your mistake was and why Matlab gave the answer it did. (a) x > y [0 0 0 1 0] (b) y < x [0 0 0 1 0] (c) x == y [0 0 1 0 0] (d) x <= y [1 1 1 0 1] (e) y >= x [1 1 1 0 1] (f) x & y [1 1 1 1 0] (g) x & (~y) [0 0 0 0 0] (h) (~x) & (y) [0 0 0 0 1] (i) x | y [1 1 1 1 1] (j) xor(x,y) [0 0 0 0 1] (k) (x > y) & (y < x) [0 0 0 1 0] Problem 2: Write down Matlab expressions for the following. You can assume that a,b,c are logical variables, x,y,z are double-precision numbers, u,v,w are vectors of the same dimension, and A,B,C are matrices of compatible sizes. (a) Both a and b are true. a && b (b) Neither a nor b is true. ~a && ~b (c) Either a and b are both true, or b and c are both false. (a && b) || (~b && ~c) (d) Either x equals y, or x is not equal to z. (x == y) || (x ~= z) (e) x, y, and z are all equal. (x == y) && (x == z) && (y == z) (f) None of the components of u equal the corresponding components of v. ~any(u == v) (g) Each component of u is the same as either the same component of v or w. all(u == v) (h) The vector whose components are the polynomial 3u^2 - 5u + 6 evaluated at each of the components of u. 3*u.^2 - 5*u + 6 (i) The matrix product AB. A*B (j) The matrix whose elements are the product of the elements of A and B. A.*B Problem 3: A theater has a seating capacity of 900 and charges $2.50 for children, $4 for students, and $5.50 for adults. At a certain screening with full attendance, there were half as many adults as children and students combined. The total money brought in was $3825. How many children, students, and adults attended the show? show? The equations are c + s + a = 900 2.5c + 4s + 5.5a = 3825 0.5(c + s) = a or c + s + a = 900 2.5c + 4s + 5.5a = 3825 0.5c + 0.5s - a = 0 To put this in matrix-vector notation, let the column vector x have components [c s a]'. Then A = [1 1 1; 2.5 4 5.5; 0.5 0.5 -1]; b = [900 3825 0]'; x = A\b x = 150 450 300 So 150 children, 450 students, and 300 adults attended the show.

gibson/teaching/fall-2014/math445/hw3solns.txt · Last modified: 2014/10/07 10:43 by gibson