$Assumption for multiple variables

℡╲_俬逩灬. 提交于 2019-12-06 06:35:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!