Mathematica 中最佳的字符分配方法
遇到以下示例代码的问题,我希望有解决方法。
假设我已经定义了一个函数:
f[x_,y_,z_] = x + y + z + x Log[x] + y Log[y] +z Log[z]
并且我要进行赋值
f[x_,y_,z_] = x + y + z + x Log[x] + y Log[y] +z Log[z]//.x->1//.y->1//.z->0
,但是我不想让 Mathematica 将 z 替换为 0,我只是希望忽略 z 来给出结果 f[x_,y_] = 2
,而不必定义一个新函数。将上述代码输入 Mathematica 会产生明显的不确定
解决方案
非常感谢帮助这位新手。
Running into a problem with the following example code for which I hope there is a way around.
Say I have defined a function:
f[x_,y_,z_] = x + y + z + x Log[x] + y Log[y] +z Log[z]
and I was to assign
f[x_,y_,z_] = x + y + z + x Log[x] + y Log[y] +z Log[z]//.x->1//.y->1//.z->0
But rather than have Mathematica replace z with 0 I just want z to be ignored to give the result f[x_,y_] = 2
without having to define a new function. Entering the above code into Mathematica results in an obvious Indeterminate
solution
Helping this novice out is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您希望对
z
描述的处理也适用于x
和y
,您可以这样做:辅助函数
g
显式处理零情况。这些定义产生如下结果:Assuming that you want the treatment you describe for
z
to apply tox
andy
as well, you could do this:The helper function
g
handles the zero case explicitly. These definitions yield results like these:首先,函数应用是通过调用函数来实现的:
其次,为什么不使用 limit 引入一个新函数呢?
这应该给你
2
,虽然我现在不在mathematica前面所以我还没有检查First, function application occurs by calling the function:
Second, why not introduce a new function using limit?
That should give you the
2
, though I'm not in front of mathematica now so i havent checked