符号运算时有些多项式的系数值接近于0,像这样
fun = 3.5753839759325595498222646101085e-49*x + 1.8367099231598242312011508394098e-40*y - 3.1684752276643959044089436923507e-34 + 555*z + 4*x*y
需要将其直接消掉,化简成这样
fun = 555*z + 4*x*y
解决方法可以这样,使用coeffs函数,具体doc一下。代码如下
clear clc syms x y z real fun = 3.5753839759325595498222646101085e-49*x + 1.8367099231598242312011508394098e-40*y - 3.1684752276643959044089436923507e-34 + 555*z + 4*x*y [c, f] = coeffs(fun,[x, y, z]); len = size(c, 2); for i =1:len if (c(i) < 0.0000000001) c(i) = 0; end end fun_new = c*f'
结果