Question: *MATLAB 3. (50 pt) In this problem you will perform various tasks on a 1-by-n array V, whose elements are integers from 1 to 9.

*MATLAB
3. (50 pt) In this problem you will perform various tasks on a 1-by-n array V, whose elements are integers from 1 to 9. In the template, you are already given the matrix V to be V = [1,4,3,3,5,6,7,1,2,9, 8, 6, 6, 3, 1,4,9,5); For each of the following tasks test your code for many different values and lengths of V (the graders may change the V matrix when grading to evaluate whether your code is correct). (a) Write code using a while loop to calculate the sum of all elements in the vector V. Define the calculated sum as variable Vi. For example, for V = [1, 2, 3, 4, 5, 6], V1 = 21. (Note: you will get zero point for this question if you use the sum function or use a for loop). (b) Write code to flip the sign of each odd number in the original matrix V. Define the new vector as V2. For example, V = [1, 2, 3, 4, 5, 6] would become V2 = (1, 2, -3, 4, -5, 6). (c) Write code to find the number of times (defined as V3) that two successive elements in V are the same. For example, for V = [1, 2, 2, 4, 6, 6), V3 = 2. (d) (Bonus Question, 10 pt) Write code using a for loop that will show all the elements of the V in a reverse order. Define the new vector as V4. For example, V = [1, 2, 3, 4, 5, 6] would become V4 = [6, 5, 4, 3, 2, 1). (Note: you will get zero point for this question if you use the flip function directly)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
