Table of Contents
Laplace transform and inverse Laplace transform ...................................................................................... 1
Solve an IVP using Laplace transforms ................................................................................................... 1
Laplace transform of the unit step and delta functions ................................................................................ 2
solve an IVP using Laplace transforms .................................................................................................... 2
Laplace transform and inverse Laplace trans-
form
% take the Laplace transform of f(t)
syms t s a
f(t) = exp(a*t);
laplace(f,t,s)
% take the inverse Laplace transform of F(s)
syms t s
F(s) = 1/(s*(s+1));
ilaplace(F,s,t)
% calculate the partial fraction expansion of F(s)
partfrac(F,s)
ans =
-1/(a - s)
ans =
1 - exp(-t)
ans(s) =
1/s - 1/(s + 1)
Solve an IVP using Laplace transforms
% define the independent and dependent variables
syms y(t) Y s
% define the differential equation
eqn = diff(y,t,2)-2*diff(y,t)-3*y==0;
% define the initial condition
y0 = 5; dy0 = 7;
% take the Laplace transform of the ODE
Leqn = laplace(eqn,t,s);
1
% insert the ICs and simplify the expression
Leqn = subs(Leqn,[laplace(y,t,s),y(0),subs(diff(y(t),t),t,0)],[Y,y0,dy0]);
% solve for Y(s)
Ysol = solve(Leqn,Y);
% find the solution by taking the inverse Laplace transform
ysol = ilaplace(Ysol,s,t)
ysol =
2*exp(-t) + 3*exp(3*t)
Laplace transform of the unit step and delta
functions
% define the symbolic variables
syms t s a
assume(a<0)
% specify the functions
u(t) = heaviside(t);
d(t) = dirac(t);
% calculate the Laplace transforms
Lu = laplace(u(t-a),t,s)
Ld = laplace(d(t-a),t,s)
Lu =
1/s
Ld =
solve an IVP using Laplace transforms
% define the independent and dependent variables and constants
syms q(t) Q s R C e0 a b
assume(a>0 & b>a)
% define the differential equation
eqn = R*diff(q,t)+1/C*q==e0*(heaviside(t-a)-heaviside(t-b));
% define the initial condition
q0 = 0;
% take the Laplace transform of the ODE
Leqn = laplace(eqn,t,s);
% insert the ICs and simplify the expression
Leqn = subs(Leqn,[laplace(q,t,s),q(0)],[Q,q0]);
% solve for Q(s)
Qsol = solve(Leqn,Q);
2
% find the solution by taking the inverse Laplace transform
qsol = ilaplace(Qsol,s,t);
% specify the constants and plot
qsol1 = subs(qsol,[R C e0 a b],[1 1 5 1 3]);
fplot(qsol1,[0 5])
xlabel('t'), ylabel('q'), ylim([0 5])
title('The charge in a capacitor in an RC circuit')
Published with MATLAB® R2024a