How to convert sym formula to an array

I'm trying to create an array from a symbolic formula like the one shown below to make it compatible with the transfer function input format:
input:
K/(s*(s + 1)*(s + 5))
Output:
[K]
[1 6 5 0]
OR
[K; 1 6 5 0]
I have tried separating the numerator and denominator but a problem arises when I have no s term in either one of the terms, so using sym2poly, for example, would return an array of [1 0] for the numerator instead of just [K]. Is there a function that would be able to seperate the K value regardless of if it includes an s value, i.e. just recognize k as a constant?
clc,clear;
%declare symbolic
syms K s;
%control inputs
Gc= K / (s+1);
G= 1 / (s*(s+5));
%multiplies inputs
tfxn= Gc*G;
%seperates numerator and denominator
[num,den]=numden(tfxn);
%converts sym formula to array
den=sym2poly(den);
num=sym2poly(num);
%does not accept correct values
sys=tf(num,den);

답변 (1개)

Walter Roberson
Walter Roberson 2023년 4월 4일

1 개 추천

num = sym2poly(num, s);
However you would end up with symbolic K in num and tf() cannot accept symbolic variables. It is not possible to construct a tf() with a symbolic variable

댓글 수: 1

In short, if you need to use the optional second parameter to sym2poly then the output is likely to be something you cannot use with tf()

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2022a

태그

질문:

2023년 4월 4일

댓글:

2023년 4월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by