How to extract numerator and denominator coeficients from polynomial function to array

31 visualizaciones (últimos 30 días)
ahmed el 14 de Abr. de 2024
Respondida: Steven Lord el 14 de Abr. de 2024
I have numerator/denominator in form of 10s^6+9s^5+8s^4...+1
and when i try to plot this through command sys=tf(num,den) i get error that it needs to be cell arrays of vectors so i need command that will make array fom me from numerator, denominator like this.
I do not want to write it by hand, i need some command for script that will do that for me. Through symbolic variables i get TF, then i evaluate it for numerator and denominator, now i need to make array from that to use it with tf() command.
Thanks
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Karl el 14 de Abr. de 2024
You can extract a vector of the coefficients of a symbolic polynomial using sym2poly():
% Create example symbolic polynomial.
syms s
rng('default');
coeffs0 = randi([-10 10],1,5);
polynomial = poly2sym(coeffs0, s)
polynomial =
% Extract polynomial coefficients.
coefficients = sym2poly(polynomial)
coefficients = 1x5
7 9 -8 9 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
ahmed el 14 de Abr. de 2024
thanks!!!!

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord el 14 de Abr. de 2024
Do you have separate symbolic expressions for the numerator and denominator or do you have the fraction created by dividing numerator by denominator?
syms x
N = x^2+2*x+3
N =
D = x^3+3*x^2+6*x+10
D =
F = N./D
F =
If you have N and D, just use sym2poly as @Karl showed. If you only have F, though, you can use the numden function to extract the numerator and denominator.
[num, den] = numden(F)
num =
den =
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by