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.
Core Syntax
Section titled “Core Syntax”The primary function for finding the Laplace Transform is laplace.
% Basic syntaxF = 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)Syntax Explained
Section titled “Syntax Explained”F = laplace(f): Computes the Laplace Transform off. MATLAB assumesfis a function oftand the resulting transformFwill be a function ofs.F = laplace(f, transVar): Computes the transform off(a function oft) but expresses the result in terms of a different variabletransVarinstead ofs.F = laplace(f, var, transVar): The most explicit form. Computes the transform off, which is a function ofvar, and expresses the resultFas a function oftransVar.
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 TransformF = laplace(f);
% 4. Display the result in a readable formatpretty(F)How it works:
- We declare
t,s, andaas symbolic variables, allowing MATLAB to perform algebraic manipulations. - We define our function
fin terms oftanda. - We call
laplace(f). Since we didn’t specify the variables, MATLAB correctly uses the defaults:tas the independent variable andsas 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 + aExample 2: Transform of a Sine Wave
Section titled “Example 2: Transform of a Sine Wave”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 ssyms w positive
% 2. Define the sine functionf = sin(w * t);
% 3. Compute the Laplace TransformF = laplace(f);
% 4. Display the resultpretty(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 2s + wExample 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 variablessyms t s asyms w positive
% 2. Define the damped cosine functiong = 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 resultdisp('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) + wPractical Application: Solving an ODE
Section titled “Practical Application: Solving an ODE”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 variablessyms y(t) t s a
% 2. Define the differential equation% Use diff(y, t) for the derivativeODE = 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 conditionsyms 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)Further Learning and Best Practices
Section titled “Further Learning and Best Practices”- 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)) withsyms. 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.