# How to simulate the forced response of a transfer function

49 views (last 30 days)
Ali Almakhmari on 15 Sep 2023
Answered: Sam Chak on 16 Sep 2023
I have a transfer function G(s) = (1-s)/(s^2 + 2s+ 1) that I want to simulate while being under a forced input of u(t) = 2*cos(3t), but I am not sure how. I hope someone can help.
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Accepted Answer

Star Strider on 15 Sep 2023
Use the lsim function —
s = tf('s');
G = (1-s)/(s^2 + 2*s + 1)
G = -s + 1 ------------- s^2 + 2 s + 1 Continuous-time transfer function.
t = linspace(0, 1E+1, 1E+3);
u = @(t) 2*cos(3*t);
Gu = lsim(G,u(t),t);
figure
plot(t, u(t), ':k', 'DisplayName','u(t)')
hold on
plot(t, Gu, '-r', 'DisplayName','G(u(t))')
hold off
grid
legend('Location','best')
.
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### More Answers (1)

Sam Chak on 16 Sep 2023
The 'lsim()' command is great when the Control System Toolbox is available. Here is an alternative approach to generate the time response G(s) subject to the forced input u(t) without using the Control System Toolbox. However, it requires the Symbolic Math Toolbox. Both toolboxes are bundled in the MATLAB and Simulink Student Suite.
You can also find examples at the following links:
syms F(s) u(t);
% Forced input function
u(t) = 2*cos(3*t)
u(t) =
U(s) = laplace(u)
U(s) =
% Plant transfer function
G(s) = (1 - s)/(s^2 + 2*s + 1)
G(s) =
% Convolution of two functions
F(s) = U*G
F(s) =
% Applying the inverse Laplace transform
f(t) = ilaplace(F, s, t)
f(t) =
% Plots
fplot(u, [0 10], ':k'), hold on, grid on
fplot(f, [0 10], 'LineWidth', 1.5), hold off
% Labels
xlabel('Time (seconds)')
ylabel('Amplitude')
legend('u(t)', 'f(t)')
title({'Time response of $G(s)$ due to input $u(t) = 2 \cos(3 t)$'}, 'Interpreter', 'LaTeX', 'FontSize', 12)
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Categories

Find more on Classical Control Design in Help Center and File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!