Mathematica,剩余零
我正在努力如何从输出中删除 Mathematica 中几乎为零的表达式。 示例:
pVec = Table[{i, Exp[-i*0.03]}, {i, 0, 2.5, 1/2}];
pVec[[2, 2]] = p1;
pVec[[3, 2]] = p2;
pVec[[4, 2]] = p3;
pVec[[5, 2]] = p4;
pVec[[6, 2]] = p5;
qq = Interpolation[pVec, InterpolationOrder -> 1];
>> qq[0.5]
>> 0. (1 - p1) + p1
0*(1-p1)
显然为零,但我找不到摆脱它的方法? (我对 Mathematica 比较陌生...)Simplify 不起作用,N[ ]
也不起作用 FullSimplyfy[ ]
。
有什么建议吗?因为在使用此插值的大表达式中,这些零表达式会累积......并且我有 10 行答案而不是常数。
I'm struggling how to get rid of expressions that are trivially zero in Mathematica from the output.
Example:
pVec = Table[{i, Exp[-i*0.03]}, {i, 0, 2.5, 1/2}];
pVec[[2, 2]] = p1;
pVec[[3, 2]] = p2;
pVec[[4, 2]] = p3;
pVec[[5, 2]] = p4;
pVec[[6, 2]] = p5;
qq = Interpolation[pVec, InterpolationOrder -> 1];
>> qq[0.5]
>> 0. (1 - p1) + p1
the 0*(1-p1)
is obviously zero, but I couldnt find a way to get rid of it ? (I'm relatively new to Mathematica...) Simplify didnt work, N[ ]
didnt work FullSimplyfy[ ]
as well.
Any advice ? Because in a big expression using this interpolation, these zero-expressions accumulate... and i have 10 line answer instead of a constant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要的功能是
Chop
。从帮助中:“
Chop[expr]
用精确的整数 0 替换 expr 中接近零的近似实数”例如:
两者都给出输出:
p1
I think the function you require is
Chop
.From the Help: "
Chop[expr]
replaces approximate real numbers in expr that are close to zero by the exact integer 0"For example:
both give as output:
p1