0% found this document useful (0 votes)
25 views3 pages

Lab 3: Matrices and Vectors: Question 2a Question 2b

This lab document covers three questions on matrices and vectors. Question 1 generates a random vector and stores multiples of 3 in a new vector. Question 2 uses matrices to solve a system of equations by row reducing the matrix and inverting the matrix. Question 3 applies a rotation transformation to a series of points using a rotation matrix and plots the original and transformed points on a graph.

Uploaded by

Numair Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Lab 3: Matrices and Vectors: Question 2a Question 2b

This lab document covers three questions on matrices and vectors. Question 1 generates a random vector and stores multiples of 3 in a new vector. Question 2 uses matrices to solve a system of equations by row reducing the matrix and inverting the matrix. Question 3 applies a rotation transformation to a series of points using a rotation matrix and plots the original and transformed points on a graph.

Uploaded by

Numair Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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]

You might also like