Define function for a transfer function

8 Ansichten (letzte 30 Tage)
Vinit Dighe
Vinit Dighe am 21 Apr. 2021
Beantwortet: Divija Aleti am 26 Apr. 2021
I have a transfer function given by: .
s = tf('s');
sys_closed = 8/(1*s^3+2*s^2+10*s+8);
t = linspace(0,10,400);
y = step(sys_closed,t);
plot(t,y)
Then, for the above transfer function, my coefficients are: a = 1, b = 2, c = 10 and d = 8. I would like to define a function, which returns the values of y for different values of coefficients. To this aim, I defined a function file (named uq_dynamic):
function V = uq_dynamic(X)
a = X(1);
b = X(2);
c = X(3);
d = X(4);
s = tf('s');
sys_closed = d./((a.*(s.^3))+(b.*(s.^2))+(c.*s)+d);
t = linspace(0,10,400);
y = step(sys_closed,t);
V = y;
My main working file requires me to define the transfer function (line 7) in vector notation (since I am coupling Matlab to a third-party toolbox: UQLab). I believe the syntax is incorrect, which returns an error. Could someone please help me to rectify the above transfer function in vector notation/correct syntax. Thank you.
Best,
Vinit

Antworten (1)

Divija Aleti
Divija Aleti am 26 Apr. 2021
Hi Vinit,
From my understanding, 'X' is a vector containing 'a', 'b', 'c', 'd' which are scalars. As these are scalars, you do not need to use the dot operator('.') while performing arithmetic operations. Have a look at the following example code where the function is called with X = [1,2,10,8] as the input:
X = [1,2,10,8];
uq_dynamic(X);
function V = uq_dynamic(X)
a = X(1);
b = X(2);
c = X(3);
d = X(4);
s = tf('s');
sys_closed = d/((a*(s^3))+(b*(s^2))+(c*s)+d); %This is the line which differs from your code
t = linspace(0,10,400);
y = step(sys_closed,t);
V = y;
end
This function returns the values of 'y', for different values of 'X'.
Hope this helps!
Regards,
Divija

Kategorien

Mehr zu Get Started with Control System Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by