% % Homework #1 - Sample Solution % clear % ***** PART 1 ***** % Create 5x4 matrix G = [ 0.6 1.5 2.3 -0.5 ; 8.2 0.5 -0.1 -2 ; 5.7 8.2 9.0 1.5 ; 0.5 0.5 2.4 0.5 ; 1.2 -2.3 -4.5 0.5 ]; % Create a column vector as the second column of matrix G A = G(:,2); % Create a row vector(or a 1x6 matrix) with integer values in the range 10 to 15 C = 10:15; % Create a 2x6 matrix using the range operator D = [ 4:9; 1:6 ]; % Create a row vector with values ranging from 0.0 to 1.0 incrementing by 0.1 F = 0.0:0.1:1.0; % Create a sub-matrix of G consisting of rows 4-5 and columns 1-3 T1 = G( 4:5, 1:3 ); % Create a sub-matrix of G consisting of odd numbered rows and all columns T2 = G( 1:2:5, :); % ***** PART 2 ***** % Create row vectors A and B A = [ 2 -1 5 0 ]; B = [ 3 2 -1 4 ]; % Add matrices A and B, then subtract a row vector of 3. C = A + B - 3; % Element-by-element divide of matrices A and B D = A ./ B; % Raise matrix A to the power matrix B, then add twice matrix A E = 2*A + A.^B; % Raise matrix 2 to the power matrix B, then add matrix A F = 2.^B + A; % Double matrix B then divide by 3 times matrix A G = 2*B / 3.*A;