step response from an equation

13 views (last 30 days)
Juan Jose Ortiz Torres
Juan Jose Ortiz Torres on 21 Sep 2018
Hello guys.
I am makig a program to plot the step response of a transfer function. But my program starts defining the numerator and the denominator of the transfer function like the following:
if true
syms s
num_planta=1; %numerator of the transfer function
den_planta=s*(s+2); %denominator of the transfer function
end
Then I make the fraction
if true
transfer_fnc=num_planta/den_planta
end
Then with that variable I make a code works, but the code does not plot anything. So I decided to do it possible. So I use some techniques but nothing work. I am gonna explain the techniques, so if you can guide me, I will be grateful.
1. Using step(transfer_fcn)
if true
aux_transfer_fcn=transfer_fcn
SS=tf('s')
subs(transfer_fcn,s,SS)
step(aux_transfer_fcn)
end
But matlab says that I cannot substitute a "symbolic" variable to a "tf" variable
2. Making with matrix
if true
[num_transfer_fcn,den_transfer_fcn]=numden(transfer_fcn)
coefs_num_transfer_fcn=coeffs(num_transfer_fcn,s,'all')
coefs_den_transfer_fcn=coeffs(den_transfer_fcn,s,'all') %%so it will be [1, 2, 0]
system=tf(coefs_num_transfer_fcn,coefs_den_transfer_fcn)
end
But matlab does no accept matrices like [1,2,3] only [1 2 3], so I was looking up how to convert but I failed lot of times.
Could you please guide me?

Answers (1)

Dimitris Kalogiros
Dimitris Kalogiros on 21 Sep 2018
Use this:
clear; clc;
close all;
% sympolic math toolbox
syms s,
num_planta=sym(1); %numerator of the transfer function
den_planta=s*(s+2); %denominator of the transfer function
transfer_fnc=num_planta/den_planta
%%extract coeffs of num and denum
nump=sym2poly(num_planta)
denp=sym2poly(den_planta)
%%create transfer function using control toolbox
H=tf(nump, denp);
step(H) % step function
If you run this, you should get:
  2 Comments
Juan Jose Ortiz Torres
Juan Jose Ortiz Torres on 21 Sep 2018
Thank you very much! it works!!!
Dimitris Kalogiros
Dimitris Kalogiros on 21 Sep 2018
...then "accept" the answer :-)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!