Numden on complex equation returns unexpected result
显示 更早的评论
I have the following complex symbolic equation
syms F_c M B w K;
eq = F_c/(- M*w^2 + B*w*1i + K);
Now I just want to get the numerator and denominator, so I thought using numden should do the trick
[n,d] = numden(eq);
% Numden should return this
> n = F_c;
> d = - M*w^2 + B*w*1i + K
% But instead returns this
> n = -F_c*1i;
> d = M*w^2*1i + B*w - K*1i
Seems like numden rewrote the equation for an unknown reason.
In this case, where's there's only one division sign, I know I could "fix" it like this
str2sym(strsplit(char(eq),'/'));
> [ F_c, - M*w^2 + B*w*1i + K]
But still the question remains, why does numden act like this? And is there a nicer way to seperate numerator and denominator?
采纳的回答
更多回答(1 个)
Devineni Aslesha
2019-10-31
The given input to numden function is a symbolic expression. However, as it involves a complex number, the numden function handles it in different way which leads to normal form.
Use the below code to get the expected result.
[n, d] = numden(subs(eq, 1i, sym('II')));
n = subs(n, sym('II'), 1i);
d = subs(d, sym('II'), 1i);
Here, in place of sym(‘II’), other symbols can also be used.
Refer to the below links for more information.
类别
在 帮助中心 和 File Exchange 中查找有关 Common Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!