Skip to content

MATLAB - Laplace Transform

MATLAB - The Laplace Transform: A Modern Approach

Section titled “MATLAB - The Laplace Transform: A Modern Approach”

The Laplace Transform is a fundamental tool in engineering and applied mathematics, allowing us to solve complex linear ordinary differential equations (ODEs) by converting them into simpler algebraic problems. It’s the cornerstone of classical control theory, signal processing, and circuit analysis.

In essence, the transform converts a function of time, f(t), into a function of a complex frequency variable, s. This process, moving from the ‘time domain’ to the ‘s-domain’ or ‘frequency domain’, makes operations like differentiation and integration become simple multiplication and division.

MATLAB’s Symbolic Math Toolbox provides the powerful laplace function to perform this transformation analytically. This tutorial will guide you through its usage with modern best practices.

The primary function for finding the Laplace Transform is laplace.

% Basic syntax
F = laplace(f)
% Specifying the transform variable (default is 's')
F = laplace(f, transVar)
% Specifying both the independent and transform variables (default are 't' and 's')
F = laplace(f, var, transVar)
  • F = laplace(f): Computes the Laplace Transform of f. MATLAB assumes f is a function of t and the resulting transform F will be a function of s.
  • F = laplace(f, transVar): Computes the transform of f (a function of t) but expresses the result in terms of a different variable transVar instead of s.
  • F = laplace(f, var, transVar): The most explicit form. Computes the transform of f, which is a function of var, and expresses the result F as a function of transVar.

Practical Examples with the laplace Function

Section titled “Practical Examples with the laplace Function”

Let’s explore how to use the laplace function with clear, practical examples. The first step is always to declare your symbolic variables using syms.

Example 1: Transform of a Decaying Exponential

Section titled “Example 1: Transform of a Decaying Exponential”

The function f(t) = e^(-at) is fundamental in system analysis, representing a basic first-order decay.

% 1. Define symbolic variables for time (t), the transform domain (s), and a constant (a)
syms t s a
% 2. Define the function f(t)
f = exp(-a * t);
% 3. Compute the Laplace Transform
F = laplace(f);
% 4. Display the result in a readable format
pretty(F)

How it works:

  • We declare t, s, and a as symbolic variables, allowing MATLAB to perform algebraic manipulations.
  • We define our function f in terms of t and a.
  • We call laplace(f). Since we didn’t specify the variables, MATLAB correctly uses the defaults: t as the independent variable and s as the transform variable.
  • The pretty() command formats the symbolic output to be more like typeset math, making it easier to read.

Expected Output:

1
-----
s + a

Let’s find the transform of f(t) = sin(ωt), a pure sinusoidal signal. Note the correction from the original tutorial’s flawed logic; this is the direct and correct method.

% 1. Define symbolic variables. We assume omega is a positive real number.
syms t s
syms w positive
% 2. Define the sine function
f = sin(w * t);
% 3. Compute the Laplace Transform
F = laplace(f);
% 4. Display the result
pretty(F)

How it works: By declaring w as positive, we help the symbolic engine make simplifying assumptions that are valid in most physical systems (frequency is positive).

Expected Output:

w
---------
2 2
s + w

Example 3: Applying the Frequency Shift Theorem

Section titled “Example 3: Applying the Frequency Shift Theorem”

The s-domain shift theorem states that the Laplace Transform of e^(-at) * f(t) is F(s+a). Let’s verify this with a damped cosine wave, g(t) = e^(-at) * cos(ωt).

% 1. Define symbolic variables
syms t s a
syms w positive
% 2. Define the damped cosine function
g = exp(-a * t) * cos(w * t);
% 3. Compute the Laplace Transform. We use the default variables (t, s).
G = laplace(g, t, s);
% 4. Display the result
disp('Laplace transform of the damped cosine wave:')
pretty(G)

How it works: This example demonstrates a more complex transform that is extremely common in second-order systems (like RLC circuits or mass-spring-dampers). The result shows the ‘s’ from the cosine transform s/(s^2 + w^2) being replaced by (s+a).

Expected Output:

Laplace transform of the damped cosine wave:
s + a
-------------
2 2
(s + a) + w

The true power of the Laplace Transform is solving differential equations. Let’s solve a simple first-order ODE: y'(t) + 2y(t) = e^(-3t) with initial condition y(0) = 5.

% 1. Define symbolic function y(t) and variables
syms y(t) t s a
% 2. Define the differential equation
% Use diff(y, t) for the derivative
ODE = diff(y, t) + 2*y == exp(-3*t);
% 3. Take the Laplace transform of the entire ODE
% The transform of y'(t) becomes s*Y(s) - y(0)
L_ODE = laplace(ODE, t, s);
% 4. Substitute the transform of y(t), Y(s), and the initial condition
syms Ys % This is the placeholder for the Laplace transform of y(t)
L_ODE = subs(L_ODE, laplace(y,t,s), Ys);
L_ODE = subs(L_ODE, y(0), 5);
% 5. Solve the algebraic equation for Y(s)
Ys_sol = solve(L_ODE, Ys);
% 6. Compute the inverse Laplace transform to get y(t)
y_sol(t) = ilaplace(Ys_sol, s, t);
disp('The solution to the ODE is:')
disp(y_sol(t))

Expected Output:

The solution to the ODE is:
6*exp(-2*t) - exp(-3*t)
  • Inverse Transform: The function ilaplace() is used to convert from the s-domain back to the time domain, as shown in the ODE example.
  • Common Pitfalls: Always declare all your variables (including the function itself, like y(t)) with syms. Forgetting this is a common source of errors.
  • Control System Toolbox: For more complex system analysis, the Control System Toolbox offers higher-level tools like the tf() (transfer function) object, which builds upon these principles for designing and analyzing control systems.