Document (6)
Document (6)
(EL-2004)
LABORATORYMANUAL
Fall 2023
LAB10
Laplace & Inverse Laplace Transforms on
MATLAB
Arslan Ahmed
______________________________________
LABENGINEERSIGNATURE&DATE
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,
simplifying the analysis. Laplace transform 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 the above
exponential sinusoid.
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 that is associated with the exponential variation. If its value is negative, the function
decays as t increases and its value is positive, the function grows with time. The imaginary part of S is
the familiar radian frequency associated with the sinusoidal variation.
Laplace Transform:
Given below is a brief table containing all the pairs for Laplace and inverse Laplace of various
kind of signals in time and frequency domain.
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
To convert the signal back into time domain, inverse Laplace is used.
This formula is seldom used since each pair of transform pair and its time-varying function is
unique, so can be easily found from the previously given table.
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.
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
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.
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.
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-2, … a1 and then Laplace transform table can be used to find out
inverse transform easily.
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
Software Used:
For functions with higher-order polynomials in their denominators, the 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.
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 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.
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
• The Getting Started link leads to the MATLAB tutorial system. Inexperienced users are
encouraged to go through the tutorials in the order in which they are presented.
MATLAB is an interpreted environment. In other words, you give a command and MATLAB
executes it right away. The syntax of variable assignment is:
Exampl
e 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 us 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 four decimals in the result of the calculations, however
some examples of the different formats together with the resulting outputs are given.
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
>> format short >> x=-163.6667 format
long>> x= -1.636666666666667e+00
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.
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 influence 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,
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 plain text file. This command is useful, for example in the
process of preparing homework or lab submission.
Declaring Polynomial:
Declaring a polynomial in MATLAB is quite easy. You must declare the vector and can convert it
into symbolic representation by using the poly2sym () command. Getting back in the form of an array
using sym2poly() command
Example 4:
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
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
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 must 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
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].
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
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 zero or a constant.
vector k occurs because of conversion of improper fraction to proper rational fraction. Note that if
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:
F (s) =−4s + 8 / s2 + 6s + 8
We write coefficients of numerator and denominator polynomial using row matrix form.
The roots of denominator which are poles of rational fraction can also be obtained by invoking the
function
>>roots (a)
-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
>> 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. >>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 an extensive 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 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.
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
Lab Tasks:
Task 1:
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
𝑥2 + (𝑦 - 𝑧)
Create a file with your name and implement all these commands.
a.
b. 𝑒-𝑢𝑡
𝑧 = (56 ∗ 7) - (2 ∗ 3)
c. 1⁄𝑥2
d.
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
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:
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
H (s) =
H (t) =
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
T (z) =
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
T (t) =
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
G (z) =
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
G (t) =
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
Task 4:
1. F(t) = 5e−6t
F(s) =
3. 𝑆(𝑡) = 𝑇𝑒−𝑎𝑡
A(s) =
S(s) =
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
F(s) = Task 5:
Find the inverse Laplace of the following functions:
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
F (t) =
F (t) =
Laplace & Inverse Laplace Transforms on MATLAB LAB: 10
Task 6 (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.