问题
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!)
回答1:
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.
回答2:
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]
来源:https://stackoverflow.com/questions/4314225/assumption-for-multiple-variables