ACT2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

ECE120L – INTRODUCTION TO MATLAB

LABORATORY ACTIVITY #2
MATRICES

Name: Consuegra, Carlo C. Date: 11/12/2018


Section: A23 Laboratory Instructor: M. I. Alipio

I. Learning Outcomes:
At the end of the laboratory activity, the students should be able to:
1. Use MATLAB in creating and manipulating matrices
2. Solve linear systems of equation using MATLAB

II. Laboratory Activity:


1.
a. Problem: Create the following matrices using matrix shortcuts

b. MATLAB Codes:
a. >>x=eye(5,4)
b. >> ones(6,3)
c. >> zeros(4,5)
d. >> rand(4,4)
e. >> randn(3,5)
ans =

-0.4326 0.2877 1.1892 0.1746 -0.5883


-1.6656 -1.1465 -0.0376 -0.1867 2.1832
0.1253 1.1909 0.3273 0.7258 -0.1364

c. Answer:
a. x =

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0
b. ans =

1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
c. ans =

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
d. ans =

0.8147 0.6324 0.9575 0.9572


0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
e. ans =

-0.4326 0.2877 1.1892 0.1746 -0.5883


-1.6656 -1.1465 -0.0376 -0.1867 2.1832
0.1253 1.1909 0.3273 0.7258 -0.1364

2.
a. Problem: If A = magic (24), what is the value in row 21, column 22?

b. MATLAB Codes: >>A=magic(24)

c. Answer:

3.
a. Problem: Create the matrix X = diag ([3:3:15])

b. MATLAB Codes: >> x=diag([3:3:15])

c. Answer: x=

3 0 0 0 0
0 6 0 0 0
0 0 9 0 0
0 0 0 12 0
0 0 0 0 15
4.
a. Problem: Using magic square of 5, write the values in lower triangular

b. MATLAB Codes: >>x=tril(magic(5))

c. Answer: 17 0 0 0 0
23 5 0 0 0
4 6 13 0 0
10 12 19 21 0
11 18 25 2 9

5.
a. Problem: Using magic square of 4, write the values in upper triangular.

b. MATLAB Codes: >>x=triu(magic(4))

c. Answer: 16 2 3 13
0 11 10 8
0 0 6 12
0 0 0 1

6.
a. Problem: Determine the determinant of the matrix.

a. MATLAB Codes: >>a=[1 3 6; -2 5 9; 7 -2 23];


>>X=det(a)

b. Answer: x =274

7.
a. Problem: Determine the determinant and coefficients w, x, y, z

b. MATLAB Codes: >>a=[1 -12 13 -7; 2 15 16 12; 4 -10 1 17; 3 2 -3 2];


>> x=det(a)

c. Answer: x=28495
8.
a. Problem: Define the matrices below: (use shortcuts if applicable)

b. MATLAB Codes: >>8a=[1 2 3 4; 6 8 1 5; 9 4 2 7; 9 4 7 2];


>>8b=ones(4);
>>8c=[16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1];
>>8d=diag(1:2:7);
>>8e=[1 0 0 0; 0 1 0 0; 0 0 0 1; 1 0 0 0];
>>8f=[3 6 9 12; 18 24 3 15; 27 12 6 21; 27 12 21 6]

c. Answer:
8a= 1 2 3 4 8b= 1 1 1 1
6815 1111
9427 1111
9472 1111
8c= 8d= 8e=
16 2 3 13 1000 3 6 9 12
5 11 10 8 0300 18 24 3 15
9 7 6 12 0050 27 12 6 21
4 14 15 1 0007 27 12 21 6

9.
a. Problem: Using the matrices of #8, solve the following:

b. MATLAB Codes: >>9a=(3.*a)+(4.*f)


>>9b=(a.*b.*c)/(4.*f)
>>9c=2.*(d.*e.*f)+(4.*b)
>>9d=(f.*e.*b)./2.*(c.*d)
>>9e=((2.*b)-(3.*d)).*(2.*(a.*b.*c))

c. Answer: 9a=15 30 45 60
90 120 15 75
135 60 30 105
135 60 105 30

9b=0.6250 -0.2309 0.5045 -0.2719


0.2778 1.0856 -0.4505 -0.0264
0.2083 -0.1858 1.0788 -0.2281
0.9861 0.3374 -1.0925 1.0913

9c=10 4 4 4
4 148 4 4
4 4 4 4
4 4 4 4

9d= 0.0938 0 0 0 9e=-32 16 36 208


0 0.3636 0 0 120 -1232 40 160
0 0 0 1.5000 324 112 -312 336 0
0.8438 0 0 0 144 224 420 -76

10.
a. Problem: Using the matrices of #8, solve the following:

b. MATLAB Codes: :>> x=[a 1+b e+3; f-2 c d]

c. Answer: x=
1 2 3 4 2 2 2 2 4 3 3 3
6 8 1 5 2 2 2 2 3 4 3 3
9 4 2 7 2 2 2 2 3 3 3 4
9 4 7 2 2 2 2 2 4 3 3 3
1 4 7 10 16 2 3 13 1 0 0 0
16 22 1 13 5 11 10 8 0 3 0 0
25 10 4 19 9 7 6 12 0 0 5 0
25 10 19 4 4 14 15 1 0 0 0 7

You might also like