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
2023-4-4
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 个评论
Walter Roberson
2023-4-4
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()
类别
在 帮助中心 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!