Define function for a transfer function

6 次查看(过去 30 天)
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 个)

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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by