How to convert sym formula to an array

5 vues (au cours des 30 derniers jours)
Payton Daugereau
Payton Daugereau le 4 Avr 2023
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);

Réponses (1)

Walter Roberson
Walter Roberson le 4 Avr 2023
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 commentaire
Walter Roberson
Walter Roberson le 4 Avr 2023
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()

Connectez-vous pour commenter.

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by