Lab 04 Laplace and Inverse Laplace Transforms On Matlab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Electrical Network Analysis

( EL-324 )
LABORATORY MANUAL
Spring 2021

LAB 3
Laplace & Inverse Laplace Transforms on
MATLAB
Engr. Muhammad Adan
Engr. Rabia Fazaldad
________________________________________ __________ ___ __________
STUDENT NAME ROLL NO SEC DATE

______________________________________
LAB ENGINEER SIGNATURE & DATE

MARKS AWARDED: /10


________________________________________________________________
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (NUCES), ISLAMABAD

Prepared by: Engr. Rabia Fazaldad Version: 1.2


Last Edited by: Engr. Muhammad Adan Date: 7 june, 2021
Verified by: Dr Durdana Date: 7 june, 2021

Lab Objective:

 Understanding the Concept of complex frequency


 Introduction to Matlab
 Laplace transform for time varying functions on Matlab
 Residue method for inverse Laplace transform on Matlab
Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Basics of Complex Frequency:

When faced with time-varying sources, or a circuit with switches installed, we have several choices
with respect to the analysis approach. Unfortunately, not all sources are sinusoidal, and there are times
when both transient and steady-state responses are required. In such instances, the complex frequency
allows us to manipulate both periodic and non-periodic time-varying quantities in parallel, greatly
simplifying the analysis. Laplace transfer proves to be a highly valuable tool to transform the signals
from time domain to frequency domain.

To give an idea about complex frequency, we consider an exponentially varying sinusoid.


V(t) = Vm eσt cos (ωt + θ)

Here V(m) is the amplitude of sinusoid with angular frequency w and phase shift of θ. σ is a constant
representing exponential delay or rise. Three general cases can be obtained from above exponential
sinusoid.

Case 1: If we set σ = ω = 0 then a constant V(t)= Vm cos θ = V0 is obtained.


Case 2: If σ=0, we obtain a general sinusoidal voltage v(t)= Vm cos(ωt + θ).
Case 3: If ω = 0, we have the exponential voltage v(t) = Vm cos θ eσt = V0eσt.

Fig 1 (a): Exponential Sinusoid Fig 1 (b): case 1 constant dc signal

Fig 1 (c): case 3 sinusoid Fig 1 (d): case 4 exponential

Introduction to Matlab NUCES, ISLAMABAD Page 2 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Further extending the equation using Euler identity we get.


V(t) = Vm eσt cos (ωt + θ)
V(t)=1/2*Vm*eσt [e j(ωt+θ) + e− j(ωt+θ)]
v(t) = ½*Vm*e jθ e j(σ+ jω)t + ½*Vm*e− jθ e j(σ− jω)t

The term S = σ + jω in the above equation is known as complex frequency. There are conjugate
complex pair of frequencies as s1 = σ + jω and s2 = σ – jω. The real part of S is σ which is the Neper
frequency associated with the exponential variation. If its value is negative, the function decays as t
increases and for positive value, the function rises. The imaginary part of S is Ω which is the radian
frequency describing the sinusoidal variation.

Laplace transform:

It is an integral transform that converts a function of a time (real variable ) to a function of a complex
frequency. The transform has many applications in science and engineering because it is a tool for
solving differential equations. In particular, it transforms integral differential equations into algebraic
equations and convolution into multiplication. Usually integration is done from 0 to infinity for single
sided transform.

Given below is a brief table containing all the pairs for Laplace and inverse Laplace of variou kind of
signals in time and frequency domain.

Introduction to Matlab NUCES, ISLAMABAD Page 3 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Fig 2: Laplace transform table of various time varying signals

Inverse Laplace Technique for Rational Functions and Method of Residues:

To convert the signal back into time domain, inverse Laplace is used.

In analyzing circuits with multiple energy storage elements, we will often encounter s-domain
expressions that are ratios of s-polynomials of the form
V(s) = N(s)/D(s)

Where N (s) and D (s) are polynomials in S, The values of s which lead to N(s) = 0 are referred to as
zeros of V(s), and those values of s which lead to D(s) = 0 are referred to as poles of V(s).

It is often possible to decompose these expressions using the method of residues into simpler terms
whose inverse transforms are already known. The criterion for this is that V(s) must be a rational
function for which the degree of the numerator N(s) must be less than that of the denominator D(s). If
it is not, we must first perform a simple division step.

In employing the method of residues, it is first necessary to factor the s-polynomial that comprises
D(s) into a product of binomial terms. The roots of D(s) may be any combination of distinct or
repeated roots, and may be real or complex. However, that complex roots always occur as
conjugate pairs provided that the coefficients of D(s) are real.

For distinct real poles, fraction in s is written as


V(s) = 1/(s + α)(s + β)

The denominator has been factored into two distinct roots, −α and −β. Using partial-fraction
expansion, we can split the given transform into the sum of two simpler transforms and can use
linearity theorem to obtain inverse transform very easily.

V(s) = A/(s + α) + B/(s + β) where A and B are residues and alpha and beta are the poles.

For Repeated Poles, consider the function


V(s) = N(s)/(s − p)n which we want to expand into

V(s) = an/(s − p)n +an−1/(s − p)n−1 +···+a1/(s − p). Solving through partial fraction expansion gives
values of residues an, an-1, an-1,…..a1 and then Laplace transform table can be used to find out
inverse transform easily.

Software Used:

For functions with higher-order polynomials in their denominators, method of residues is somewhat
complex. In these instances MATLAB can also be of assistance, as it contains several useful functions
for the manipulation of polynomial expressions. Also Laplace transform can be directly obtained using
matlab.

Introduction to Matlab NUCES, ISLAMABAD Page 4 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3
About MATLAB:

 Double-click on the MATLAB shortcut icon on your Windows desktop. 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 is where you type in Matlab commands. These can be simple
equations you want evaluated, or more complex expressions involving Matlab scripts or
functions.

 The Command History Window shows the commands you have entered in the past. You can
repeat any of these commands by double-clicking on them, or by dragging them from the
Command History Window into the Command Window.

 The Workspace shows the list of variables that are currently defined, and what type of
variable each is. (i.e. a simple scalar, a vector, or a matrix, and the size of all arrays.)
Depending on the size (i.e. type ) of the variable, its value may also be shown.

 The Current Directory Window shows the contents of the current working directory.

 The Help menu also provides a wide variety of useful sources of help.

 The Getting Started link leads to the Matlab tutorial system. New users are encouraged to go
through the tutorials in the order in which they are presented.

Fig 3: Graphical Interface of MATLAB window

Introduction to Matlab NUCES, ISLAMABAD Page 5 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Declaring Variables:
You can enter a command at the >> command window.

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
x= 5

Always declare variable of syms type, if you do not want to assign the value.

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

Let’s suppose you want to calculate the expression, 1 + 2×3. You type it in command window as

>> 1+2*3
ans =7

If you do not specify an output variable, MATLAB uses a default variable ans, short for answer,
to store the results of the current calculation. You may assign a value to a variable or output argument
name.

For example,

>> x = 1+2*3
x =7

MATLAB by default displays only 4 decimals in the result of the calculations however some
examples of the different formats together with the resulting outputs are given

>> format short


>> x=-163.6667
format long>> x= -1.636666666666667e+00

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

Example 2:
x=9 % assign the value 9 to x

Introduction to Matlab NUCES, ISLAMABAD Page 6 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3
You can also write a block of comments using the block comment operator’s % {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
xyz

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.

The command clear or clear all removes all variables from the workspace. This frees up system
memory.

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

Declaring Polynomial: 

Declaring a polynomial in Matlab is very easy. You have to declare the vector and can convert  it in
symbolic representation by using the poly2sym ( ) command. Getting back in the form of an array
using sym2poly() command

Example 4: 
Write x2 − 3x + 34 

>> x = [1 -3 34] 
>> answer = poly2sym (x) 
answer = x^2-3*x+34 
>> answer1 = sym2poly (answer)

answer1 =

     1    -3    34
These two representations are not equal in MATLAB; they are two distinct concepts.
Introduction to Matlab NUCES, ISLAMABAD Page 7 of 17
Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

In Matlab we can declare polynomial with different variable t using poly2sym (x, t)
Example 5: 
Write x5 − 3x + 44 

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

Example 6:

To find the roots of a given polynomial, you have to use the command “roots ()”.
For example 
>> z = roots(x); %x is the matrix 
>> ans=  
-2.1917 + 0.000i 
-0.6100 + 2.0646i 
0.61100 – 2.0646i 
1.7059 + 1.1922i 
1.7059 – 1.1922i

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. 

vector k occurs because of conversion of improper fraction to proper rational fraction. Note that as
long as the order of the numerator polynomial is less than the order of the denominator polynomial,
the vector k(s) will always be empty.

Example 7: 

Introduction to Matlab NUCES, ISLAMABAD Page 8 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3
F (s) =−4s + 8 / s2 + 6s + 8

We write coefficients of numerator and denominator polynomial using row matrix form.

>> b= [-4 8]; 


>> a= [1 6 8]; 

The roots of denominator which are poles of rational fraction can also be obtained by invoking the
function
>>roots (a)

Partial fraction can be obtained as:


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

You can write this in the partial fraction expansion form as: 

Now we can convert(take inverse laplace) the partial fraction form to time domain easily as follows: 

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

>> [b, a] = residue (r, p, k) 


b =  
-4 8 
a =  
168

The MATLAB command to plot a graph is plot(x,y). Axis can be labeled out using x label, y label
command. Title can be mentioned.

>> x = 0:pi/100:2*pi;
>> y = sin(x);
>> plot(x,y)

Row matrix, Column Matrix, identity matrix, null matrix can be written and generated in matlab
using brackets, semi colon and coma. Transpose, inverse and indexing can be obtained. We can
multiply, add and subtract them.
Introduction to Matlab NUCES, ISLAMABAD Page 9 of 17
Laplace & Inverse Laplace Transforms on MATLAB LAB: 3
>>inv([1 2;3 4]

On the other hand, array arithmetic operations other than matrix operation, are done element by
element.
>> C = A.*B

With matrix notation, a system of simultaneous linear equations is written Ax=b. The result is
x=A−1b.

Script file is an external file that contains a sequence of MATLAB statements. Script files have a
filename extension .m and are often called M-files. File→ New→ M-file

MATLAB offers if-else statements, for loop and while loop and switch commands.

There is a long list of mathematical functions that are built into MATLAB. Many standard
mathematical functions, such as sin(x), Cos(x), tan(x), exp, log(x), min, max, avg, inv, are evaluated
by in MATLAB.

Laplace transform using matlab:

Calculating the Laplace F(s) transform of a function f (t) is quite simple in Matlab.
Define the variables using syms function and write function in time domain and use laplace
command.

F(t)=-1.25+3.5te-2t+1.25e-2t
>> syms t s
>> f=-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t);
>> F=laplace(f,t,s)
>> simplify(F)
>> pretty(ans)
It gives ans = (s-5)/s*(s+2)2
To make the expression more readable one can use the commands, simplify and pretty.

Inverse Laplace using matlab:

Introduction to Matlab NUCES, ISLAMABAD Page 10 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

ilaplace command can be used directly or method of residues can be used.

Task 1:
Create a file of your name and implement all these commands.
a. 𝑥2 + (𝑦 - 𝑧)
b. 𝑒-𝑢𝑡
c. 1⁄𝑥2
d. 𝑧 = (56 ∗ 7) - (2 ∗ 3)

Task 2:
Using the above mentioned commands declare the polynomials and find roots.
a. 512v6 + 99v4
b. 3x3 − 34
c. 7q8 + 3q2

Task 3: 
Do the partial fraction expansion of the following expressions: 

 
H (s) = 

H (t) =  

Introduction to Matlab NUCES, ISLAMABAD Page 11 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

T (z) = 

T (t) =  

G (z) =  

G (t) =  

Calculate the partial fraction and inverse laplace manually of all the above fractions, and compare
theresult.
Calculation:

Introduction to Matlab NUCES, ISLAMABAD Page 12 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Task 4: 
1. F(t) = 5e−6t 

F(s) = 

2. 𝐴(𝑡) = 𝑆𝑖𝑛 (𝑎𝑡)

A(s) = 

3. 𝑆(𝑡) = 𝑇𝑒−𝑎𝑡 

S(s) =  

4. 𝑓(𝑡) = −1.25 + 3.5𝑡𝑒−2𝑡 + 1.25𝑒−2t 

F(s) =

Calculate the Laplace of all the above fractions manually, and compare the result.
Calculation:

Introduction to Matlab NUCES, ISLAMABAD Page 13 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Introduction to Matlab NUCES, ISLAMABAD Page 14 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Task 5: 
Find the inverse Laplace of the following functions: 

F (t) = 

F (t) =  

Calculate the inverse Laplace of all the above fractions manually, and compare the result.
Calculation:

Introduction to Matlab NUCES, ISLAMABAD Page 15 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Introduction to Matlab NUCES, ISLAMABAD Page 16 of 17


Laplace & Inverse Laplace Transforms on MATLAB LAB: 3

Task 6(Optional):
a. Compute the Laplace transform of the function f(t) = 2u(t − 3) by integrating the
function.
b. Given the function G(s) = (7/s) − 31/(s + 17), obtain inverse Laplace using Laplace table

Task 7(Optional):
a. Calculate the inverse transform of F(s) = 2(s+2)/s first converting it into proper fraction.
b. Calculate inverse transform of p(s) = (7s+5)/(s2+s) using poles and residue method. What
nature of poles did you get from above rational fraction. Write code in MATLAB for this
question and verify the results.

Task 8(Optional):
a. Find Laplace transform of function f(t)=4-4e-2tcos(t)+2e-2tsin(t) using laplace command.
b. Find inverse Laplace transform using ilaplace command and residue method on matlab
only for a function in s domain as 3/s3+5s2+8s+4

Introduction to Matlab NUCES, ISLAMABAD Page 17 of 17

You might also like