Você está na página 1de 13

CIRCUIT ANALYSIS-II

(EL-217)

LABORATORY MANUAL
Spring 2016

(Lab#12)
Introduction to MATLAB

ENGR.M Ibrar Khan

Student Name:
Roll No: Section:

Date performed: , 2016


MARKS AWARDED: / 10

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, ISLAMABAD

Prepared by: Engr. Sana Saleh Version: 1.0


Verified by: Engr. Azhar Rauf, Dr. Tehseen Updated: Spring 2016
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

Lab # 12: Introduction To Matlab

Learning Objective:
 To Familiarized student with MATLAB software.
 Learning commands for declaring polynomial, taking Laplace transform and inverse Laplace transform.

Equipment Required:
 MATLAB Software.

Introduction:
Starting Matlab
When you start MATLAB, a special window called the MATLAB desktop appears. The desktop is a window
that contains other windows. The major tools within or accessible from the desktop are:
 The Command Window
 The Command History
 The Workspace
 The Current Directory
 The Help Browser
 The Start button

Page 2 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

Declaring variables
You can enter commands at the >> command prompt.
MATLAB is an interpreted environment. In other words, you give a command and MATLAB executes it right
away. The syntax of variable assignment is:
variable name = a value (or an expression)

Example 1:
>>x=5
Output
>> x= 5

Always declare variable before using of syms type, if it value is not assigned.

>> syms x y z;

Once a variable has been created, it can be reassigned. In addition, if you do not wish to see the intermediate results, you
can suppress the numerical output by putting a semicolon (;) at the end of the line. Then the sequence of commands
looks like this:

>> t = 5;
>> t = t+1
>> t =6

The percent symbol (%) is used for indicating a comment line.

Example 2:

x = 9 % assign the value 9 to x

You can also write a block of comments using the block comment operators % { and % }.
The MATLAB editor includes tools and context menu items to help you add, remove, or change the format of comments.
MATLAB is case-sensitive. The who command displays all the variable names you have used. while, whos will give more
details which include size, space allocation, and class of the variables.To clear the Command Window, type clc

Example
3: >>who
Output
>> x y z

The contents of the workspace persist between the executions of separate commands. Therefore, it is possible for
the results of one problem to have an effect on the next one. To avoid this possibility, it is a good idea to issue a
clear command at the start of each new independent calculation.

>> clear

It is possible to keep track of everything done during a MATLAB session with the diary command “>> diary” or give a
name to a created file,

>> diary FileName

where FileName could be any arbitrary name you choose.


The function diary is useful if you want to save a complete MATLAB session. They save all input and output as they
appear in the MATLAB window. When you want to stop the recording, enter diary off. If you want to start recording

Page 3 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

again, enter diary on. The file that is created is a simple text file. This command is useful, for example in the process
of preparing a homework or lab submission.

TASK 1:
Create a file of your name and implement all these commands.
2
  x +(y-z)
  e-ut
2
 1/x 
 z=(56*7)-(2*3)

Declaring Polynomial
Declaring polynomial in matlab is very easy. You have to declare the vector and can convert it in symbolic
representation by using poly2sym() command.

Example 4:
2
Write x -3x+34.
>> x = [1 -3 34]
>> answer=poly2sym(x)
>>answer = x^2 - 3*x + 34

In matlab we can declare polynomial with different variable using poly2sym(x,t)

Example 5:
5
Write x -3x+44.
>>syms t;
>> x = [1 0 0 0 -3 44]
>> answer=poly2sym(x,t)
>>answer = t^5 - 3*t + 44

To find the roots of a given polynomial, you have to use command “roots()”.
For above example
>>z=roots(x); % x is the matrix >>ans
=

-2.1917 + 0.0000i
-0.6100 + 2.0646i
-0.6100 - 2.0646i
1.7059 + 1.1922i
1.7059 - 1.1922i

TASK 2:
Using the above commands declare the polynomials and find roots.
6 4
1. 512v + 99v
3
2. 3x -34
8 2
3. 7q +3q

Page 4 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

Partial Fraction Expansion

[r,p,k] = residue(b,a)command in matlab finds the residues, poles, and direct term of a Partial Fraction Expansion of the
ratio of two polynomials, where the expansion is of the form

The inputs to residue are vectors of coefficients of the polynomials b = [bm ... b1 b0] and a = [an ... a1
a0]. The outputs are the residues r = [rn ... r2 r1], the poles p = [pn ... p2 p1], and the polynomial k.
For most textbook problems, k is 0 or a constant.

Example:

b = [-4 8];
a = [1 6 8];
[r,p,k] = residue(b,a)
r = -12
8
p =
-4
-2
k =
[]

This represents the partial fraction expansion

We can convert this in time domain manually as follow:


-4t -2t
>> -12e U(t)+8e U(t)

We can convert [r,p,k] form back in fraction form by using residue


command. [b,a] = residue(r,p,k)
b = -4 8
a=
1 6 8
2
F(s)=(-4x+8)/x +6x+8

Page 5 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

TASK 3:
Do the partial fraction expansion of following expansions:

1.

H(s)=_______________________________

H(t)=_______________________________

2.

X(z)=________________________________________

X(t)=_________________________________________

3.

T(z)=________________________________

T(t)=________________________________

4.

G(z)=____________________________

G(t)=____________________________

Practically perform the partial fraction of last two fractions, and compare the results.

Page 6 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

CALCULATIONS:

Page 7 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

Laplace Transform
Calculating the Laplace F(s) transform of a function f(t) is quite simple in Matlab. First you need to specify that
the variable t and s are symbolic ones.
This is done with the
command >> syms t s
Next you define the function f(t). The actual command to calculate the transform
is >> F=laplace(f,t,s)
To make the expression more readable one can use the commands, simplify and pretty

TASK 4:
-6t
1. F(t)=5e

F(s)=______________________

2.

F(s)=_____________________

3. A(t)=Sin(at)

A(s)=______________________
-at
4. S(t)=Te

S(s)=_____________________
Page 8 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

Inverse Laplace Transform

The command one uses now is ilaplace. One also needs to define the symbols t and s. Lets calculate the inverse of the
previous function F(s),

TASK 5:
Find the inverse laplace of following functions.

Page 9 of 7 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

CALCULATIONS:

Page 10 of 13
National University Roll No:

Lab #
(EL217)
of Computer and Emerging Sciences
Islamabad Spring 2016
12
Submission Declaration by the Student:
In submitting this lab write-up to the Lab Engineer/Instructor, I hereby declare that:
I have performed all the practical work myself
I have noted down actual measurements in this writeup from my own
working I have written un-plagarised answers to various questions
I have/have not obtained the desired objectives of the lab.
Reasons of not obtaining objectoves (if applicable):

Student’s signature and Date

Student Evaluation by the Lab Engineer:


The Lab Engineer can separate this page from the writeup and keep it for his/her own record.
It must be signed by the student with date on it.
Lab Work: objectives achieved (correctness of measurements, calculations, answers to
questions posed, conclusion) /30
Lab Writeup: Neatness, appropriateness, intime submission /10

Troubleshooting: Were the student able to troubleshoot his/her work when it was purposedly
changed? /10
TOTAL: /5

Feedback on student behaviour:


Encircle your choice. -2 means poorest/worst/extremely inadequate/irrevlevant, 0 gives an
average score, and +2 means best/most relevant/most adequate.

Did the student join the lab at the start/remained in lab? -2 -1 0 1 2


 Did the student remain focused on his/her work during lab? -2 -1 0 1 2
 Rate student's behaviour with fellows/staff/Lab Engineer? -2 -1 0 1 2
 Did the student cause any distraction during the Lab? -2 -1 0 1 2
 Was the student found in any sort of plagiarism? -2 -1 0 1 2

Additional comments(if any) by the Lab Engineer:

Lab Engineer’s signature

Student's feedback:[Separate this page; fill it; drop in the Drop Box.] Page 11 of
13
National University Roll No:

Lab #
(EL217)
of Computer and Emerging Sciences
Islamabad Spring 2016
12
Providing feedback for every lab session is optional. No feedback means you are satisified
The Lab Committee will consider only duly filled forms submitted within one week after the
lab
This feedabck is for LAB session: LAB Number: , Date:
General (to provide feedback on a persistent practice/ocurrence in LABs).
Your current CGPA is in the range 4.00 to 3.00/2.99 to 2.00/1.99 to 1.00/0.99 to 0.00

This feedback is:


For a Particular
Who conducted the LAB?
Actual Start time: Total Duration of Lab:
Instruction Duration: Practical Duration:

LAB writeup available before LAB?Yes/No with the Photocopier/in LAB/in SLATE
Had the theory related to lab been covered in theory class?Yes/No

Encircle your choice. -2 means poorest/worst/extremely inadequate/irrevlevant, 0 gives


an average score, and +2 means best/most relevant/most adequate.

Was duration of instruction session adequate? -2 -1 0 +1 +2


Instruction How much did you understand about the practical? -2 -1 0 +1 +2
Session How much content was irrelevant to the practical? -2 -1 0 +1 +2
Did the instructor allowed Q/A and discussion? -2 -1 0 +1 +2
Practical Did you get sufficient time for practical? -2 -1 0 +1 +2
Presence in lab at all time? -2 -1 0 +1 +2
Ability to convey? -2 -1 0 +1 +2
Lab Readiness to help during practical? -2 -1 0 +1 +2
Engineer Readiness to discuss theoretical aspects? -2 -1 0 +1 +2
Helps in troubleshooting? -2 -1 0 +1 +2
Guides hows & whys of troubleshooting? -2 -1 0 +1 +2
How friendly was the lab staff? -2 -1 0 +1 +2
Staff Presence of staff throughout the lab session?
Impact of availability of staff on your practical? -2 -1 0 +1 +2
-2 -1 0 +1 +2
Performance of Electronic Instruments? -2 -1 0 +1 +2
Equipment Performance of Breadboard/experiment kit?
Performance of circuit components esp. ICs? -2 -1 0 +1 +2
-2 -1 0 +1 +2
Overall Your overall rating for the whole lab session? -2 -1 0 +1 +2

Other comments:

Page 12 of 13
National University
of Computer and Emerging Sciences
Roll No:
12
(EL217) Islamabad Spring 2016

Page 13 of 13

Você também pode gostar