Collect function doesn't work as intended

syms z w K
% Previous steps executed, expresion directly copied from workspace
GzSFDen = 1.0*z^2 + (0.36788*K - 1.3679)*z + 0.26424*K + 0.36788;
GzSFDen = vpa(GzSFDen)
GzSFDen = 
% Substitution of z with (w+1)/(w-1)
Gw = subs(GzSFDen,z,(w+1)/(w-1))
Gw = 
% Obtained answer, coefficient of w^2 should only be 31606 K
incorrect = collect(Gw,w)
incorrect = 
% Expected answer, numerically close, num and den divided by 5
% Manually obtained
correct = (6141*K*w^2 + (12642 - 4924*K)*w - 1217*K + 27358)/(10000*w^2 - 20000*w + 10000);
correct = collect(correct,w)
correct = 

5 commentaires

Torsten
Torsten le 1 Nov 2022
Modifié(e) : Torsten le 1 Nov 2022
The -1 comes from -1.3679*w^2 + 0.36788*w^2 (numerator of the third and fourth term of your sum). So it is correct.
Shouldn't it be canceled with the 1*w^2 from the (w+1)^2/(w-1)^2
Almost. But
rest = 50000*(1 - 1.3679 + 0.36788);
equals
rest
rest = -1.0000
is there a way to avoid that? Or there is a way to get rid of small values?
Sure.
Replace
GzSFDen = 1.0*z^2 + (0.36788*K - 1.3679)*z + 0.26424*K + 0.36788;
by
GzSFDen = 1.0*z^2 + (0.36788*K - 1.36788)*z + 0.26424*K + 0.36788;

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Produits

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by