REC11+Problems+Set+Solutions

REC11+Problems+Set+Solutions - 14:440:127 Introduction to...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
14:440:127 Introduction to Computers for Engineers Recitation 11 - Problems for students to attempt - SOLUTIONS 1. Convert 10101101 (Base 2) to base 10. 1*2 7 +0*2 6 +1*2 5 +0*2 4 +1*2 3 +1*2 2 +0*2 1 +1*2 0 1*2 7 +1*2 5 +1*2 3 +1*2 2 +1*2 0 = 173 2. Convert 348 (Base 10) to base 2. __ __ __ __ __ __ __ __ __ __ 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 __ __ __ __ __ __ __ _ 348 – 256 = 92 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 0 1 __ __ __ __ __ _ 92 – 64 = 28 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 0 1 0 1 __ __ __ _ 28 – 16 = 12 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 0 1 0 1 0 1 1 1 0 0 12 – 8 - 4 = 0 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 512 256 128 64 32 16 8 4 2 1 348 base 10 is 0101011100 base 2 3. Create a structure called student that contains 3 felds: exam1, exam2, and exam3. Now, create a 100 element vector oF students, and assign each student random grades (between 0 and 100) For each oF the exams. Assuming the exam grades are weighted equally, which student (number) has the highest course grade? Which student has the lowest course grade? Hint: Look back at you Lecture 07 Notes to see an remind yourselF oF problems with max values. for s = 1:100 student(s).exam1 = ceil(101*rand(1))-1; % ceil(101*rand(1)) gives integers 1 to 101 % ceil(101*rand(1))-1 gives integers 0 to 100 % floor(101*rand(1)) also gives integers 0 to 100 student(s).exam2 = ceil(101*rand(1))-1;
Background image of page 1

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

View Full DocumentRight Arrow Icon
student(s).exam3 = ceil(101*rand(1))-1; first = char(ceil(26*rand(1))+64); % make a capital; rest = char(ceil(26*rand(1,5))+96); % make rest student(s).name = [first rest]; end %calculate averages for s = 1:100 student(s).average = (student(s).exam1 + student(s).exam2 + student(s).exam3)/3; end %finds max using a loop maxval=-inf; for s = 1:100 if(student(s).average>maxval) maxval=student(s).average; coolkid=s; end end fprintf('Student %.0f, %s, has the highest average, %.2f\n',coolkid,student(coolkid).name,maxval) 4. Create a 1000x1000 matrix full of zeros, but set nonzero values for 5 of those elements. Now, convert it to a sparse matrix (and save in a different variable). Use the whos command to determine which uses less memory. Explain your result. This problem is easy if you read your Lecture 11 Notes . >> b = zeros(1000); >> b(1,1)=43; >> b(2,2)=54; >> b(14,45) = 543; >> b(63,15) = 431; >> b(64,14) = 43; >> bsparse = sparse(b); >> whos Name Size Bytes Class b 1000x1000 8000000 double array bsparse 1000x1000 4064 double array (sparse) The sparse matrix uses much less memory since b contains mostly zeros. 5. Create a
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

REC11+Problems+Set+Solutions - 14:440:127 Introduction to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online