$假设多个变量 [英] $Assumption for multiple variables

查看:29
本文介绍了$假设多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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

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

推荐答案

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

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 *)] &;

然后,如果您创建了一个不想成为真实的新符号,那么您可以跟进类似 $Assumptions = Most[$Assumptions] 之类的内容.

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].

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

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.

这篇关于$假设多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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