$多个变量的假设

发布于 2024-10-05 08:25:46 字数 122 浏览 1 评论 0原文

我想将整个笔记本的变量限制在特定范围内,有没有一种方法可以一次性做到这一点,而无需为每个变量输入不同的 $asstitution 行?

编辑:我想定义笔记本中所有计算的变量域(谷歌搜索帮助我更好地构建了我的需求!)

I want to restrict my variables to certain ranges for my entire notebook, is there a way I can do that in one go without entering a different $assumption line for every variable?

Edit: I want to define the domain of variables for all calculations in my notebook (googling helped me frame my needs better!)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

莫多说 2024-10-12 08:25:47

如果您的所有变量都将是(例如)Real,那么您可以 拦截新符号的创建并将该假设添加到$Asminations。例如

$Assumptions = True;
$NewSymbol = If[#2 === "Global`",
    Print["Created new Global` variable named ", #1, ". It is assumed to be real."];
    $Assumptions = $Assumptions && Element[Symbol[#2 <> #1], Reals],
    Null (* other, probably a system symbol is created *)] &;

,如果您创建一个您不想成为真实的新符号,那么您可以使用类似 $Asminations = Most[$Asminations] 的内容。


注意:我不一定认为这种方法是个好主意......
最好只为您要使用的变量定义 $Asminations 。这可以使用 MapTable 等以编程方式完成。

If all of your variables are going to be (for example) Real, then you can intercept the creation of new symbols and add that assumption to $Assumptions. E.g.

$Assumptions = True;
$NewSymbol = If[#2 === "Global`",
    Print["Created new Global` variable named ", #1, ". It is assumed to be real."];
    $Assumptions = $Assumptions && Element[Symbol[#2 <> #1], Reals],
    Null (* other, probably a system symbol is created *)] &;

Then if you create a new symbol that you don't want to be real, then you could follow up with something like $Assumptions = Most[$Assumptions].


Note: I don't necessarily claim that this approach is a good idea...
It's probably best to just define the $Assumptions for the variables you are going to use. This can be done programmatically using Map, Table, etc.

囚你心 2024-10-12 08:25:46

全局定义如下

$Assumptions = b >= 0 && c >= 0 && {u11, u13, u14} \[Element] Reals

然后使用全局定义的变量如下

Simplify[expression  with global variables] 

Globally define as follows

$Assumptions = b >= 0 && c >= 0 && {u11, u13, u14} \[Element] Reals

then use globally defined variables as follows

Simplify[expression  with global variables] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文