Inverse Laplace Transform Using MATLAB

Ammar Ali Oct 10, 2021
Inverse Laplace Transform Using MATLAB

This tutorial will discuss how to find the inverse Laplace transform using the ilaplace() function in MATLAB.

Find Inverse Laplace Transform Using the ilaplace() Function in MATLAB

We use inverse Laplace transform to convert the Laplace domain function into a time-domain function. In Matlab, we can use the ilaplace() function to convert a Laplace domain function into a time-domain function. The ilaplace() function excepts three input variables. The first variable is mandatory, which is the Laplace domain function, the second variable is optional, which is the independent variable of the Laplace domain. By default, Matlab will use the variable s as the independent variable, and the third variable is the transformation variable of the time domain. By default, Matlab will use the variable t as the transformation variable. For example, let’s find the inverse Laplace transform of a function using the ilaplace() function in Matlab. See the code below.

syms s
fun = 1/s^2;
Output = ilaplace(fun)

Output:

Output =
 
t

In the above code, as you can see, we only provided the function to the ilaplace() function. But if you want to change the transformation variable, you need to pass that variable as a second argument to the ilaplace() function. For example, let’s replace the transformation variable t with x. See the code below.

syms s
fun = 1/s^2;
Output = ilaplace(fun,x)

Output:

Output =
 
x

In the above code, as you can see, the transformation variable t is changed to x. Now consider another example where we will change the independent variable as well as the transformation variable. See the code below.

syms a s
Fun = 1/(s-a);
Output = ilaplace(Fun)

Output:

Output =
 
exp(a*t)

In the above code, we only provided the function to the ilaplace() function, so it will use the default values for the independent variable and the transformation variable. Now let’s change both of these variables, and instead, we will use a as an independent variable and x as a transformation variable. See the code below.

syms a s
Fun = 1/(s-a);
Output = ilaplace(Fun,a,x)

Output:

Output =
 
-exp(s*x)

In the above code, as you can see, the output and the variables in the output have been changed. So, if we change the independent variable, the result will change. We can also find the inverse Laplace transform of a matrix or an array using the ilaplace() function. We can define the independent and transformation variable as a matrix of the same dimension as the Laplace domain function matrix. The ilaplace() function will act element-wise if the arguments of the matrix are non-scalars. For example, let’s find the inverse Laplace transform of a matrix. See the code below.

syms a b c d w x y z
Matrix = [1/x 1; sin(y) i*z];
var = [w x; y z];
tVars = [a b; c d];
Output = ilaplace(Matrix,var,tVars)

Output:

Output =
 
[             dirac(a)/x,       dirac(b)]
[ ilaplace(sin(y), y, c), dirac(1, d)*1i]

The output of the matrix will also come in a matrix of the same dimension. Suppose we want to find the inverse Laplace transform of a polynomial, and we don’t want to write the whole equation in Matlab. In that case, we can write the polynomial coefficients of numerator and denominator only. And then, using the poly2sym() function, we can convert the polynomial coefficients into a symbolic polynomial. The poly2sym() function excepts two input arguments, the first argument is the polynomial coefficient vector, and the second argument is the symbol we want to add to the polynomial expression. For example, let’s find the inverse Laplace transform of a polynomial expression. See the code below.

syms s t;
numerator=[1 1];
denominator=[1 3 5];
numS=poly2sym(numerator,s);
denS=poly2sym(denominator,s);           
Fun=numS./denS

Output = ilaplace(Fun,s,t)
NumericOutput = vpa(Output)

Output:

Fun =
 
(s + 1)/(s^2 + 3*s + 5)
 
 
Output =
 
exp(-(3*t)/2)*(cos((11^(1/2)*t)/2) - (11^(1/2)*sin((11^(1/2)*t)/2))/11)
 
 
NumericOutput =
 
exp(-1.5*t)*(cos(1.6583123951776999245574663683353*t) - 0.30151134457776362264681206697006*sin(1.6583123951776999245574663683353*t))

The Fun is the polynomial expression in the above output, and the variable Output is its inverse Laplace transform. As you can see, the variable Output contains powers and division, which are not solved. To get a simplified numeric result, we can use the function vpa() to convert the result into a numeric form. In this example, the numeric result is store in the variable NumericOutput.

Author: Ammar Ali
Ammar Ali avatar Ammar Ali avatar

Hello! I am Ammar Ali, a programmer here to learn from experience, people, and docs, and create interesting and useful programming content. I mostly create content about Python, Matlab, and Microcontrollers like Arduino and PIC.

LinkedIn Facebook