Lab 1 for ENSC 180
Q1:
-
1)
Input:
A = [17, 5, 2, 1, 4, 3, 2, 1, 0, 7, 7, 6];
N = length(A);
B = sum(A) / N;
Output:
-
2)
Input:
A = [17, 5, 2, 1, 4, 3, 2, 1, 0, 7, 7, 6];
N = length(A);
B = sum(A) / N;
V = (sum(((A-(B)).^2)) / N);
Output:
Q2:
-
1)
Input:
b = magic(5);
s1 = sum(b,2);
Output:
-
2)
Input:
b = magic(5);
s2 = sum(b,1);
Output:
-
3)
Input:
b = magic(5);
s3 = sum(diag(b));
Output:
-
4)
Input:
b = magic(5);
s4 = sum(diag(fliplr(b)));
Output:
-
5)
Input:
b = magic(5);
s5 = b < 5;
Output:
5x5 Logical array
-
6)
Input:
b = magic(5);
s6 = b >= 20;
Output:
5x5 logical array
-
7)
Input:
b = magic(5);
s5 = b < 5;
s6 = b >= 20;
>> b(s5|s6) = 100
Output:
Q3:
-
1)
Input:
M = 2;
X = zeros(M, M);
T2 = dct(eye(M));
Output:
-
2)
Input:
M = 2;
X = zeros(M, M);
T2 = dct(eye(M));
M1 = T2*T2.';
Output:
-
3)
Input:
M = 2;
X = zeros(M, M);
T2 = dct(eye(M));
X2 = ones(2);
three = T2*X2;
Output:
-
4)
Input:
M = 2;
X = zeros(M, M);
T2 = dct(eye(M));
X2 = ones(2);
four = T2*X2*T2.';
Output:
-
5)
Input:
M = 4;
T4 = dct(eye(M));
Output:
-
6)
Input:
M = 4;
T4 = dct(eye(M));
six = T4*T4.';
Output:
-
7)
Input:
M = 4;
T4 = dct(eye(M));
X4 = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4];
seven = T4*X4;
Output
-
8)
Input:
M = 4;
T4 = dct(eye(M));
X4 = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4];
eight = T4*X4*T4.';
Output:
-
9)
Input:
M = 4;
T4 = dct(eye(M));
X4 = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4];
nine = sum(X4);
Output:
-
10)
-
- First row: All the elements are identical and positive.
-
- Second row: This row starts with a positive value, decreases to a smaller positive value, goes through zero, and then has the equivalent negative values in the reverse order. It’s a form of alternating symmetry. If we split the row by the middle, each half is the mirror image of the other in terms of absolute value, but with signs flipped.
-
- Third row: The values alternate between positive and negative, but with the same absolute value in the first and last positions and in the two middle positions. This row is symmetric in the same fashion as the second row. If you split it in the middle, the halves are mirror images in terms of absolute values, with signs flipped
-
- Fourth row: This row is similar to the second one, as it features the same type of symmetry. This row also begins with positive values which decrease, followed by the negative reflection of these values in reverse order.
-