You are on page 1of 8

REVIEW ON MATLAB

Laboratory Experiment No.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.

Materials and Equipment

MATLAB software with Tool Box


Personal Computer

Introduction

Matlab is an interactive package for numerical analysis, matrix manipulation, control systems design,
linear system analysis and digital signal processing. The most recent application of matlab is for digital
filters, their design and application, using “toolboxes” specifically the DSP toolbox.

TO OPEN MATLAB

Go to start menu, programs and look for the matlab application and open it or double-click the matlab
icon on the desktop to access the matlab software. The matlab command window will appear. This is
where you enter commands at the >>prompt and where the matlab displays the numerical outputs.

TO EXIT MATLAB

Type Quit on the command prompt or select Exit matlab from the File menu.

ONLINE HELP

Help is always available every session of matlab. Matlab is case sensitive, meaning all commands and
variables must be entered in lower case. There are several ways to get help:

* The help commands >> help


Help is used if you know the syntax for the command but you do not know how to use the command,
matlab will give you a lecture for that command:
Example: >>help plot
This will give you lecture all about plot command

1
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

Formula:
1
f r=
2 π √ LC

Fr = 7.1176e+03 Hz

2. Solve for the total resistance of three resistors connected in parallel


R1 = 100 ohms
R2= 200 ohms
R3= 500 ohms
Formula:
1
RT =
1 1 1
+ +
R 1 R2 R 3
RT = 58.8235Ω

3. Solve for the roots of the equation

5x2 + 3x –5 = 0

a=5 b=3 c = -5

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

X1 = 0.7440

X2 = -1.3440

2
4. Solve for x

Formula:
√ 2 √16 √ x=2
3 3

X = 16

5. Solve for the half-power beam width

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


N=4 d = λ/2

Formula:
−1 λ
ϴh=2 cos (1−0.1398 )
Nd
ϴh = 43.0992°

Objective C and D

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

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

A=
1 2 3
4 5 6
7 8 9

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

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

Command: 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]

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 3 5 7 9; 11 13 15 17 19; 21 23 25 27 29]

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

Command: E = [1 1.5 2 2.5 3; 2 2.5 3.2 3.8 4.4; 5 5.1 5.2 5.3 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

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: G = [A(:,2), A(:,end),(B([2 3 5]).') , D(:,4), D(:,end)]

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 = [B(10):-0.5:5.5; B(7):1:16; (B(10)*(-5)):10:40]

G=
10.0000 9.5000 9.0000 8.5000 8.0000 7.5000 7.0000 6.5000 6.0000 5.5000
7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000
-50.0000 -40.0000 -30.0000 -20.0000 -10.0000 0 10.0000 20.0000 30.0000 40.0000
d. 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
4
Sin x 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.6570 0.9894 0.4121 -0.5440

Command: Sinx = [sin(1), sin(2), sin(3), sin(4), sin(5), sin(6), sin(7), sin(8), sin(9), sin(10)]

Command: Table = [X; Sin x]

Procedures
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

C=

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

D=

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

E=

1 8 3
1 9 3
1 9 3

5
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

Z1 =
6 -12 18
9 18 -27
3 -9 -21
6 -15 0
-3 27 -12

Observation:
The individual element inside matrix A is multiplied with the value of 3. Therefore 3*A
basically triples the value of each element enclosed in the matrix.

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

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

Z2 = Z2 =
83 0 -31 16 49 81
63 2 -24 4 16 49
18 -63 85 81 0 4

Observation:
C*C means that its multiplying both matrix which involves a complicated process, while C.*C
basically squares the value of each element inside the matrix since we are multiplying the
same matrix but if it were to different matrices then that would mean that each element
from the first matrix will get multiplied directly to the corresponding element on the second
matrix with respect to the individual element of each matrix.

c. Z3 = A element multiply with E

Command: Z3 = A.*E

Z3 =
-1 -6 -21
4 20 0
-3 54 36
Observation:
The individual elements in matrix A is multiplied directly and respectively to the individual
elements of matrix B.

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

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

Z4 =
-68462092 224966048 -107772456
-64765696 212817116 -101951824
3697903 -12148293 5819111

Observation:
Since all the input matrices are 3x3 the corresponding output has also a 3x3 dimension.
Otherwise the operations involved wouldn’t be possible.

e.
Z5 =¿ ¿

Command: Z5 = (((A*C'*B*D')^4)*(A'*D*E))/(((A*B*C)+(B*E))^1/3)

Z5 =
1.0e+16 *

-0.1994 1.0312 0.4014


-0.0069 0.0358 0.0139
-0.1865 0.9649 0.3755

Observation:
The value of the individual elements inside matrix Z 5 is evidently very large due to the fact
that it is multiplied with the scalar quantity 1x10 16.

Analysis and Conclusion

After doing the experiment, I got more familiar with the different expressions and operations that
involves matrices and arrays including basic indexing. Defining a matrix from another matrix widened my
perspective in the usage of matlab and I believe that this is only barely scratching the surface of the
software usage itself. Also, I noticed that matlab has two different types of arithmetic operations: array
operations and matrix operations. Matrix operations follow the rules of linear algebra. By contrast, array
operations execute element by element operations and support multidimensional arrays. The period
character (.) distinguishes the array operations from the matrix operations. However, since the matrix
and array operations are the same for addition and subtraction, the character pairs. +  and.-  are
unnecessary.

You might also like