Define function for a transfer function

조회 수: 6 (최근 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

카테고리

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