How to plot a step response of symbolic laplace and inverse laplace function

10 views (last 30 days)
Hello
I have a problem with drawing the esponse from the Laplace transform nad inverse laplace transform.
I want to determine the response of the system to the given signal, the response to the inverse transform and compare these responses in one graph
For example i have G(s) = 1/(s+1) nad step U = 1/s,
My code:
G = tf(1,[1 1])
[y t] = step(G) % i want to get t out of step first
syms s; clear G;
G = 1/(s+1)
U = 1/s
Gstep = G*U
Gistep = matlabFunction(ilaplace(Gstep))
ezplot(Gistep,t)
hold on
ezplot(Gstep,t)
ylim([0 2])
But I dont think thats correct

Answers (1)

Sam Chak
Sam Chak on 30 Mar 2022
Here is the MATLAB script:
clear all; clc
% Define symbolic variables
syms s t y(t) Y(s)
D1y = diff(y);
% Dynamical system
Eqn = D1y + y == heaviside(t)
% Perform Laplace Transform of Eqn
LEqn = laplace(Eqn);
% Substitute Laplace transform of y(t) for Y(s), and y(0) for the initial condition
LEqn = subs(LEqn, {laplace(y(t), t, s), y(0)}, {Y(s), 0});
% Isolate Y(s) in LEqn
LEqn = isolate(LEqn, Y(s))
% Perform inverse Laplace transform on the right-hand side of LEqn
y(t) = ilaplace(rhs(LEqn))
% Plot the solution
fplot(@(t) y(t), [0 10])
grid on
xlabel('Time, t')
ylabel('y(t)')
Result:
You can compare the above result with the step response of your transfer function:
G = tf(1, [1 1])
step(G, 10)
  1 Comment
Sam Chak
Sam Chak on 30 Mar 2022
Note that after isolating , you get
because
.
Also, since you are going to make a comparison with the step response step() and the function assumes the initial condition by default, then you need to make the substitution of this initial value.

Sign in to comment.

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!