Introduction To Matlab

You might also like

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

INTRODUCTION TO MATLAB

LABORATORY EXPERIMENT 1

Presented to
The Faculty of the College of Engineering and Technology
University of St. La Salle
Bacolod City

In Partial Fulfillment
Of the Requirements for the Degree in
Bachelor of Science in Electronics Engineering

JAN IRENEO B. TAN

February 6, 2024

1
Performance Objectives

A. To familiarize ourselves with MATLAB


B. To be able to use its operators
C. To be familiar with different operations that can be done using matrices.
D. To write a program that uses MATLAB operators and matrices.

Objective A and B

I. Computing for variables using formulas


A. Define all the variables that are listed below. These variables are needed to solve some
formulas.
B. After assigning values on the variables, solve the formulas by typing it to the command
window. Don’t use the semi colon so that you will be able to see the answer. Fill up all
the blanks with your answers.

1. Solve for the resonance frequency

L = 5mH; % inductance
C = 0.1µF %capacitance

1
Formula: fr =
2π LC

L = 5e-03;
C = 1e-07;

Fr = 1/(2*pi*(L*C)^(1/2))

Fr = 7.1176e+03 Hz

2
2. Solve for the total resistance of three resistors connected in parallel
R1 = 100 ohms
R2 = 200 ohms
R3 = 500 ohms
1
Formula: RT =
1 1 1
+ +
R1 R 2 R3

RT = 1/((1/100)+(1/200)+(1/500))

RT = 58.8235 ohms

3. Solve for the roots of the equation

5x2 + 3x –5 = 0

a=5 b=3 c = -5

− b ± b 2 − 4ac
Formula: x=
2a

a = 5;
b= 3;
c = -5;

X1 = (-b + sqrt(b^2 - 4*a*c))/(2*a)


X1 = 0.7440

X2 = (-b - sqrt(b^2 - 4*a*c))/(2*a)


X2 = -1.3440

X1 = 0.7440

X2 = -1.3440

3
4. Solve for x

3
Formula: 2 ⋅ 3 16 ⋅ x = 2

X = ((2^3/2)^3/16)^2

X = 16

5. Solve for the half-power beamwidth

f = 3GHz c = 3 x 108 m/s


N=4 d = λ/2

 λ 
Formula: Θ h = 2 cos −1 1 − 0.1398 
 Nd 

f = 3e09
c = 3e08
N=4
lambda = c/f
d = lambda/2

omega = 2*acos(1 - 0.1398 *(lambda/(N*d)))

Θh = 0.7522

4
Objective C and D

1. Define the matrices given below. Write the command that you used to define those
matrices.

Command: A = [1 : 1 : 3; 4 : 1 : 6; 7 : 1 : 9]

A=
1 2 3
4 5 6
7 8 9

Command: B = [1 : 1 : 15]

B=
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Command: C = [ 2 : 2 : 10];
C = diag(C, 0)

C=
2 0 0 0 0
0 4 0 0 0
0 0 6 0 0
0 0 0 8 0
0 0 0 0 10

Command: D = [1 : 2 : 9; 11 : 2 : 19; 21 : 2 : 29]

D=
1 3 5 7 9
11 13 15 17 19
21 23 25 27 29

Command: E = [1 : 0.5 : 3; 2 : 0.6 : 4.4; 5 : 0.1 : 5.4]

E=
1.0000 1.5000 2.0000 2.5000 3.0000
2.0000 2.6000 3.2000 3.8000 4.4000
5.0000 5.1000 5.2000 5.3000 5.4000

5
2. Now, create the matrices given using commands that will extract elements of reference
matrices. Take note: you must not define those matrices; the elements must be
extracted using the lecture discussed above. Write the command that you used on the
space given below.

a. Command: F = [E(1,:); D(3,:); C(5,:)]

F=
1.0000 1.5000 2.0000 2.5000 3.0000
21.0000 23.0000 25.0000 27.0000 29.0000
0 0 0 0 10.0000

b. Command: Y = [A(:,2) A(:,3) E(:,3) D(:,4) D(:,5)];


G = round(Y)

G=
2 3 2 7 9
5 6 3 17 19
8 9 5 27 29

c. Now, create a matrix that has the required conditions:


- first row is from 10 to 5.5 with a decrement of 0.5
- second row if from 7 to 16
- third row is –50 to 40 with an increment of 10

Command: G = [10 : -0.5 : 5.5; 7 : 1 : 16; -50 : 10 : 40]

6
Define a table of sine values from sin 0 to sin 10 using matrices. Fill up the table
below and write the commands you used.

X 1 2 3 4 5 6 7 8 9 10
Sin x 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.6570 0.9894 0.4121 -0.5540

Command: x = (1:10); y = sin(x);


Command: I=[x;y]

Procedure:
1. Define all the matrices given below

A = [1 -3 -7; 2 -5 0; -1 9 -4] B = [-1 2 3; 2 -4 6; 3 6 -9]

1 -3 -7 -1 2 3
2 -5 0 2 -4 6
-1 9 -4 3 6 -9

C = [4 -7 9; 2 -4 7; 9 0 -2]

4 -7 9
2 -4 7
9 0 -2

D = [ 0 -1 -2; -3 8 -4; -1 9 -3]

0 -1 -2
-3 8 -4
-1 9 -3

E = [1 8 3; 1 9 3; 1 9 3]

1 8 3
1 9 3
1 9 3

7
2. Solve the following equations and give observations on your result. Write also the
command you used to solve the equation. Compare the MATLAB result from the
computational result.

a. Z1 = 3A

Command: Z1=3*(A)

Observation:
Each element of matrix A was multiplied by 3.

b. Z2 = C2 (Use both * and .* then observe the difference.)

Command: Z2 = C*C
Command: Z2 = C.*C

Observation:
When using C*C, MATLAB performed the standard operation of multiplying two
matrices while in using C.*C, MATLAB multiplied each corresponding element of
each matrix (therefore each element was squared).

8
c. Z3 = A element multiply with E

Command: Z3 = A.*E

Observation:
MATLAB multiplied each element of matrix A to each corresponding element of
matrix E.

d. Z4= ABC + (2BED)3 – 4AC

Command: Z4 = A*B*C + (2*B*E*D)^3 - 4*A*C

Observation:
MATLAB performed all the necessary matrix operations based on the formula that
the user inputted. In addition, MATLAB performs the operations based on the rule of
GEMDAS.

9
 ( AC ' BD')4 ⋅ ( A' DE ) 
Z 5 =  
e. 3
ABC + BE 
 
Command: Z5 = (((A*C'*B*D')^4)*(A'*D*E))/((A*B*C + B*E)^(1/3))

Observation:
MATLAB performed all the necessary matrix operations based on the formula that
the user inputted. In addition, MATLAB performs the operations based on the rule of
GEMDAS.

Conclusion:

MATLAB allows the user to perform different types of operations very quickly which is
useful when one needs to calculate complex equations at a short amount of time. The only
downside is the user must correctly input the operations and label the variables properly or
else MATLAB will either give an error or perform unwanted operations. Regardless of this,
MATLAB has been a useful tool especially in the field of engineering. It allows us to define
matrices and perform matrix operations and as well as calculations related to our engineering
field.

10

You might also like