{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Final Review Questions Solutions

# Final Review Questions Solutions - CS1371 Final Review...

This preview shows pages 1–4. Sign up to view the full content.

CS1371 Final Review Packet 1) Vectors: Given vec1 and vec2 (assume they are the same length) , write the code to do the following. After each segment, assume that vec1 and vec2 go back to the same as above. a. Concatenate vec1 and vec2 into a vector, vec3 b. Concatenate the even values of vec1 and the odd values of vec2 into a vector, vec4 c. Concatenate the even indices of vec1 and the odd indic es of vec2 into a vector, vec5 d. Create vec6, which will contain all the elements in vec1 less than the median of vec2 e. Raise vec1 to the power of the square root of vec2 and store it in vec7 f. Create a vector, vec8, that will go from the smallest value in vec1 to the largest value in vec2 using twice as many points that are in vec1 g. Create vec9, which will start at the mean of vec1 and go to the largest value in vec2 in steps of .25 h. Plot the data series as if your x values are vec1 and y values are vec2. Plot them as red circles with a title, and appropriate labels i. Create a function that returns a Boolean true or false and consumes a vector and a number. The function should output a true if that number appears in the vector. Do not use iteration vec3 = [ vec1, vec2] vec4 = [ vec1(mod(vec,2)==0) , vec2(mod(vec,2)==1)] vec5 = [ vec1(2:2:end) , vec2(1:2:end)] vec6 = vec1(vec1 < mean(vec2)) vec7 = vec1.^(sqrt(vec2)) vec8 = linspace(min(vec1),max(vec2),2*length(vec1)) Vec9=mean(vec1) : .25 : max(vec2) plot( vec1 , vec2 , ro ) xlabel( x-axis ) ylabel( y-axis ) title( PlotStuff ) function ret = findme(vec,num) ret = false; locs = find(vec==num); if length(locs)>0 ret = true; end

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2) Boolean Logic: Given a = true, b=true, c = false and vec1 = [ 4, 5, 3, 9, 12, 44, 23, 13 ] and vec2 = [ 19, 43, 5, 9, 8, 21, 45, 11 ], write the results of the following: a. (a & c) | b b. ( ((a & ~b) | c) & (c | (a|b))) | ((a | b) & ((c|~a) | ~b)) c. vec1( vec2<vec1 & [ a a c b b c a c ]) 3) Iteration/Conditionals: a. Given vec1 and vec2 (assumed same length), write the code to create vecN which will contain the largest value of either of the two vectors at every index. b. Create a function that returns a Boolean true or false and consumes a vector and a number. The function should output a true if that number appears in the vector. Use iteration c. Create a function that will take consumes a vector and returns an augmented version of that vector. Your function should concatenate a random, positive, whole number between 5 and 10 to the end of the vector until the sum of the vector is greater than the product of the largest and smallest number in the vector. True False [ 12 ] function ret = largestIndex(v1,v2) for in = 1:length(v1) ret(in) = max([ v1(in) , v2(in)]); end function ret = findmeIter(vec,num) ret = false; for in = 1:length(vec) if vec(in) == num ret = true; end end function ret = crazyConcate(vec) ret = vec; while min(ret)*max(ret) > sum (ret) tmp = 5 + 5*round(rand(1,1)); ret = [ ret , tmp ]; end
d. noRepeats.mCreate a function that takes in a vector and will output the same vector without any repeated values. Thus, if 3 occurs in the vector 4 times, make sure to delete 3 of them.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern