% Q3(a) : print the power of 4 from 1 to 10 for i = 1:10 i^4 end % Q3(b) : create an array x that holds the values from 0 to 4pi increment % of pi/2 for i = 1:8 x(i) = (i-1)/(2*pi); end % Q3(c) : create another array that holds the sin values of x for i = 1:8 y(i) = sin(x(i)); end y % Q3(d) : All about hits and reloads on a web server. hits = [52, 48, 64, 38, 47, 29, 38]; total = [78, 60, 73, 45, 62, 43, 44]; hits_mean = mean(hits); total_mean = mean(total); hits_median = median(hits); total_median = median(total); count = 0; for i = 1:7 if hits(i) < 50 count = count + 1; end end plot(hits, 'y+-'); hold plot(total, 'ro-'); title ('Unique Hits and Total Hits of Our Web Server'); legend ('Unique Hits', 'Total Hits'); ylabel('Num of Hits'); xlabel('Days of Week'); % Q3 (e) Plot a beautiful graph for a polynomial. for i = 1:501 x(i) = (i-1)/250 - 1; y(i) = 6*x(i)^3 - 3*x(i)^2 - x(i) + 1; end plot(x, y, 'r.-'); title('y = 6x^3 - 3^x2 - x + 1'); xlabel('x'); ylabel('y'); % Q3 (f) Two dimensional arrays. M = [6 3 -2 5; 3 0 4 -6; -5 2 7 -1]; M(1:3, 2) rowsum = sum(M, 1) colsum = sum(M, 2) C = [M(:,2) M(:,1) M(:,4)] One = ones(1,4); D = [One;M;One] % Q3 (g) Write a new function pos. function [R] = pos(M) row = length(M(:, 1)) col = length(M(1, :)) for i = 1:row; for j = 1:col; if M(i,j) >= 0 R(i,j) = 1; else R(i,j) = 0; end end end N = [5 -3 2 -1; 4 1 -5 -6; -2 0 1 3]; R = pos(N)