0% found this document useful (0 votes)
26 views

Matlab Experiment

The document discusses MATLAB and provides examples of using MATLAB to perform matrix operations and solve equations. It defines several matrices, extracts elements from matrices, and uses MATLAB commands to multiply matrices, take powers and roots of matrices, and perform other operations on matrices to solve equations.

Uploaded by

makicastle
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)
26 views

Matlab Experiment

The document discusses MATLAB and provides examples of using MATLAB to perform matrix operations and solve equations. It defines several matrices, extracts elements from matrices, and uses MATLAB commands to multiply matrices, take powers and roots of matrices, and perform other operations on matrices to solve equations.

Uploaded by

makicastle
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/ 8

MACY J.

CASTILLO
Review on MatLab
Laboratory Experiment No. __

Performance Objectives

A. To familiarize ourselves with MATLAB


B. To be able to use it’s 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.

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 command >> 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

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
MACY J. CASTILLO

1. Solve for the resonance frequency

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

Formula:

Fr = 7117.6 Hz

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


R1 = 100 ohms
R2= 200 ohms
R3= 500 ohms

Formula:
RT = 58.8235 ohms

3. Solve for the roots of the equation

5x2 + 3x –5 = 0

a=5 b=3 c = -5

Formula:

X1 = -1.344

X2 = 0.744

4. Solve for x

Formula:

X = 16

5. Solve for the half-power beamwidth

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


2
MACY J. CASTILLO
N=4 d = λ/2

Formula:

Θh = 43.10 deg

Objective C and D
1. Define the matrices given below. Write the command that you used to define those matrices.

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

A=
1 2 3
4 5 6
7 8 9

Command: B= 1:15;

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

Command: v = [2 4 6 8 10];
C = diag(v);

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];

3
MACY J. CASTILLO

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([4 7]) A(4) D([10 13]) ; A([5 8]) D([4 11 14]); A([6
9 5]) D([12 15])];

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: H = [10:-0.5:5.5; 7:-0.5:16; -50:10:40];

H =

Columns 1 through 6

10.0000 9.5000 9.0000 8.5000 8.0000 7.5000


-50.0000 -40.0000 -30.0000 -20.0000 -10.0000 0

Columns 7 through 10

7.0000 6.5000 6.0000 5.5000

4
MACY J. CASTILLO
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
Sin x
0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794 0.657 0.9894 0.4121 -0.54
40

Command: X = [1:10];

Command: Y= sin(X);

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

5
MACY J. CASTILLO

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

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

z =

3 -9 -21
6 -15 0
-3 27 -12

Observation: They simply multiplied the matrix A with 3.

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

Command:
z2=c*c

z2 =

6
MACY J. CASTILLO
83 0 5
63 2 4
54 -63 85

z2=c.*c

z2 =

16 49 81
4 16 49
81 0 4

Observation: For the first command, we used a multiplication operator. In the second
command, we used an element wise operator which multiplies each element by C.

c. Z3 = A element multiply with E

Command: Z3 = A.*E

z3 =

1 -24 -21
2 -45 0
-1 81 -12

Observation: We multiplied the A matrix elements to the respective elements of the E


matrix.

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

Command: Z4 = (a*b*c)+(2*b*e*d)^3-(4*a*c);

Z4 =

-68462092 224966048 -107772152


-64765696 212817116 -101951920
3697903 -12148293 5819523

7
MACY J. CASTILLO

e.

Command: Z5 = (((a*c'*b*d')^4)*(a'*d*e))/(((a*b*c) + b*e)^(1/3));

Z5 =

1.0e+15 *

-0.2566 + 0.0000i 2.6132 + 0.0000i 1.0734 - 0.0000i


-0.0407 + 0.0000i 0.4148 + 0.0000i 0.1704 - 0.0000i
-0.3547 + 0.0000i 3.6119 + 0.0000i 1.4836 - 0.0000i

You might also like