Assignment4_solutions.pdf - Question 1 a = 0 for b = 1:15...

This preview shows page 1 - 4 out of 4 pages.

% Question 1 a = 0; for b = 1:15 if rem(b,3) == 0 a = a + b; end end fprintf( 'The sum is: %i' ,a) The sum is: 45 % Question 2 matrix = rand(10); a = matrix(3,:); b = matrix(:,6); mult = a.*b'; average = mean(mult); fprintf( 'The average is: %i' ,average) The average is: 2.928602e-01 % Question 3 a = input( 'Stop number: ' ); b = zeros(10); c = 0:a/9:10; for d = 1:10 b(d,d) = c(1,d); end disp(b) 0 0 0 0 0 0 0 0 0 0 0 1.1111 0 0 0 0 0 0 0 0 0 0 2.2222 0 0 0 0 0 0 0 0 0 0 3.3333 0 0 0 0 0 0 0 0 0 0 4.4444 0 0 0 0 0 0 0 0 0 0 5.5556 0 0 0 0 0 0 0 0 0 0 6.6667 0 0 0 0 0 0 0 0 0 0 7.7778 0 0 0 0 0 0 0 0 0 0 8.8889 0 0 0 0 0 0 0 0 0 0 10.0000 % Question 4 midterms = input( 'Enter 3 midterm grades in [a,b,c] format: ' ); final = input( 'Enter final exam grade: ' ); mid_worth = mean(midterms)*0.7; final_worth = final*0.3; grade = mid_worth + final_worth; if grade < 60 gf = 'F' ; elseif grade < 70 gf = 'D' ; elseif grade < 80 gf = 'C' ; 1
elseif grade < 90 gf = 'B'

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture