如何在mathematica中定义抽象奇函数? [英] How can I define a abstract odd function in mathematica?

查看:81
本文介绍了如何在mathematica中定义抽象奇函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何定义抽象奇数函数,例如f [x].

How can I define a abstract odd function, say f[x].

每当出现f [x] + f [-x]时,mathematica会将其简化为零.

Whenever f[x]+f[-x] appears, mathematica simplifies it to zero.

推荐答案

可以使用升值轻松完成

f[x_] + f[y_] /; x == -y ^:= 0

通常Mathematica会尝试将上述规则分配给 Plus ,这当然是行不通的,因为它受到了保护.通过使用 ^:= 而不是:= ,您可以将规则分配给 f .快速检查会产生:

Normally Mathematica would try to assign the above rule to Plus, which of course does not work since that's protected. By using ^:= instead of := you can assign the rule to f. A quick check yields:

In[2]:=   f[3]+f[-3]
Out[2]:=  0

但是,这仅适用于 Plus .最好使用更通用的内容,例如:

This, however, only works for Plus. It's probably better to use something more general, like:

f[x_?Negative] := -f[-x]

现在这也适用于类似的东西

Now this also works with things like

In[4]:=  -f[3] - f[-3]
Out[4]:= 0

如果您还希望该功能以符号方式工作,则可以添加以下内容:

If you also want the function to work symbolically, you could add something like:

f[-a_] := -f[a]

这篇关于如何在mathematica中定义抽象奇函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆