Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Test your understanding of MATLAB with these short questions. question should no

ID: 2079258 • Letter: T

Question

Test your understanding of MATLAB with these short questions. question should not require more than a single line of command or explanation. Provide the commands and the results obtained for each of the following operations: Given C = [57 3 0 -2 9 25 14 0 -21 0 8 -9 11 18 0 5 0], provide the MATLAB commands to execute the following operations: Return the size of C. Delete the zeros (0) from the vector C (you could use the find function). Set the negative values of C to zero. Extract the values of C greater than 3 in a vector D. Add 3 to the values of C that are even (use mod(C, 2)). Compute the average (mean), the standard deviation (std) and the variance (var) of the values of C. Compute the product (prod) of the non-zero elements of C. Obtain the maximum (max) and minimum (min) value of C.

Explanation / Answer

(A). To find the size of the vector/matrix

Command : size(c)

Answer : [1, 17] i.e 1 - row and 17 - columns or a vector with 17 values.

(b) find function returns the index of elements satisfying given function. as we have to delete the zeros replace them by null.

Command :   c( find(c==0) ) = [ ]

Answer : [57 3 -2 9 25 14 -21 8 -9 11 18 5]

(c) c<0 returns the logical indexing i.e 1's and 0's. c(c<0) returns the negative values so eqate them to Zero.

Command : c(c<0) = 0

Answer : [ 57 3 0 0 9 25 14 0 0 0 8 0 11 18 0 5 0 ]

(d) c(c>3) returns the valuse that are greater than 3. so assign it to d.

Command : d = c(c > 3)

Answer : d = [ 57 9 25 14 8 11 18 5 ]

(e) mod(c,2) returns the logical vector showing which values of 'c' are even and odd(i.e its a remainder vector) with even values have 0 and odd values have 1. not(mod(c,2)) is complement i.e even values have 1 and odd values have 0. now multiply this with 3 and add the resultant vector to c.

Command : c = c + not(mod(c,2))*3

Answer : [ 57 3 3 1 9 25 17 3 -21 3 11 -9 11 21 3 5 3 ]

(f) For Mean, Standard Deviation and Variance in Matlab following are direct commands.

Command : mean(c), std(c), var(c)

Answer : mean = 6.9412, Standard deviation = 16.5849, Variance = 275.0588.

(G) ' prod ' function returns the product of all values in a vector. To calculate the non-zero values product we just have to eleminate them.

Command : prod(c(c ~=0))

Answer :    -1.6126e+12

H) Maximum and Minumum values in a vector coan be found by

Command : max(c) and min(c)

Answer : Maximum value = 57, Minimum value = -21.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote