Question
8. Let x = [3 1 5 7 9 2 6]. For each of the following commands first think about what the result should be
8. Let x = [3 1 5 7 9 2 6]. For each of the following commands first think about what the result should be and then type the command and verify your answer. a. x(3) b. x(1:7) c. x(1:end) d. x(1:end-1) e. x(6:-2:1) f. x([1 6 2 1 1]) g. sum(x) 9. Given the array A = [ 2 4 1 ; 6 7 2 ; 3 5 9], provide the commands needed to a. assign the first row of A to a vector called x1 b. assign the last 2 rows of A to an array called y c. compute the sum over the columns of A d. compute the sum over the rows of A 10. Given that x = [1 5 2 8 9 0 1] and y = [5 2 2 6 0 0 2], execute and explain the results of the following commands: a. x > y b. y < x c. x == y d. x <= y e. y >= x f. x | y g. x & y h. x & (~y) 11. Given x = [3 15 9 12 -1 0 -12 9 6 1], provide the command(s) that will a. set the values of x that are positive to zero b. set values that are multiples of 3 to 3 (rem will help here) c. multiply the values of x that are even by 5 d. extract the values of x that are greater than 10 into a vector called y e. set the values in x that are less than the mean to zero f. set the values in x that are above the mean to their difference from the mean In each of the following questions, write down on paper the result of the given MATLAB code fragments for each of the cases indicated. Then use MATLAB to check your answers. 12. if n > 1 m = n+1 else m = n 1 end Cases: a. n = 7 m = ? b. n = 0 m = ? c. n = -10 m = ? 13. if z < 5 w = 2*z elseif z < 10 w = 9 z elseif z < 100 w = sqrt(z) else w = z end Cases: a. z = 1 w = ? b. z = 9 w = ? c. z = 60 w = ? d. z = 200 w = ? 14. if T < 30 h = 2*T + 1 elseif T < 10 h = T 2 else h = 0 end Cases: a. T = 50 h = ? b. T = 15 h = ? c. T = 0 h = ? 15. if 0 < x < 10 y = 4*x elseif 10 < x < 40 y = 10*x else y = 500 end Cases: a. x = -1 y = ? b. x = 5 y = ? c. x = 30 y = ? d. x = 100 y = ? Write brief scripts to evaluate the following functions. You should test that your script provides the correct results. 16. h(T) = T - 10, when 0 < T < 100 = 0.45 T + 900, when T > 100 Test cases: a. T = 5, h = -5 b. T = 110, h = 949.5 17. Create an M-by-N array of random numbers (use rand). Move through the array, element by element, and set any value that is less than 0.2 to the value 0 and any value that is greater than or equal to 0.2 to the value 1. answer 18. Given x = [4 1 6] and y = [6 2 7], compute the following arrays a. aij = xiyj b. bij = xi/yj c. ci = xiyi, then add up the elements of c. d. dij = xi/(2 + xi + yj) e. eij = reciprocal of the lesser of xi and yj ================================================================================================= 19. Find the eigenvalues and associated eigenvectors of the matrix A=[-2 2; 0 -1] 20. Check whether the vectors a = {3; 4; 5}, b = {-3; 0; 5}, c = {4; 4; 4}, d = {3; 4; 0} are linearly independent.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started