Lab 3: Matrices and Vectors
Lab 3: Matrices and Vectors
Numair Hussain
208562316
Contents
Question 1
Question 2
Question 2a
Question 2b
Question 3
Question 1
Generate a vector of 15 random variables from 10 to 50, and store the multiples of 3 in a
vector called "tri".
vec = randi([10,50], 1, 15)
tri = vec(rem(vec, 3)==0)
vec =
Columns 1 through 11
40
20
30
38
46
49
32
15
16
20
44
Columns 12 through 15
20
43
19
15
48
48
tri =
30
Question 2
Solve a system of equations using matrices.
A) Use the function rref(M) to solve for values of x, and place into a vector called "x"
B) Using properties of matrices, calculate values of x and place into a vector called "x"
Question 2a
A =
b =
M =
red
x =
[2 -4.5 1; 3 -1 1; 3.3 2.1 -3];
[3;-2.5;0.5];
[A,b];
= rref(M);
red(:,[4])
x =
-0.6701
-1.3800
-1.8697
Lab3.html[2015-01-27 7:32:05 PM]
Lab 3: Matrices and Vectors
Question 2b
Ainv = inv(A);
x = (Ainv*b)
x =
-0.6701
-1.3800
-1.8697
Question 3
Using matrix properties, apply transformations to a series of points and plot on a graph.
Display the legend.
x = [1 1 1 0 -1 -1 -1 0];
y = [1 0 -1 -1 -1 0 1 1];
angle = -45*pi/180;
R = [cos(angle) -sin(angle); sin(angle) cos(angle)];
PointsOld = [x;y]
PointsNew = R*[x;y]
xNew = PointsNew(1:1, 1:8);
yNew = PointsNew(2:2, 1:8);
plot(x, y, '*' , xNew, yNew, '+')
axis([-3 3 -3 3]);
legend('Original Square','Square rotated 45 clockwise', 'Location', 'southeast');
PointsOld =
1
1
1
0
1
-1
0
-1
-1
-1
-1
0
-1
1
0
1
PointsNew =
Columns 1 through 6
1.4142
0.0000
0.7071
-0.7071
Columns 7 through 8
-0.0000
1.4142
0.7071
0.7071
Lab3.html[2015-01-27 7:32:05 PM]
0.0000
-1.4142
-0.7071
-0.7071
-1.4142
-0.0000
-0.7071
0.7071
Lab 3: Matrices and Vectors
Published with MATLAB 7.12
Lab3.html[2015-01-27 7:32:05 PM]