Define function for a transfer function

1 ビュー (過去 30 日間)
Vinit Dighe
Vinit Dighe 2021 年 4 月 21 日
回答済み: Divija Aleti 2021 年 4 月 26 日
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
  1 件のコメント
Paul
Paul 2021 年 4 月 23 日
What does "vector notation" mean?

サインインしてコメントする。

回答 (1 件)

Divija Aleti
Divija Aleti 2021 年 4 月 26 日
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

Community Treasure Hunt

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

Start Hunting!

Translated by