Basic Examples (3)
By default, Mathematica assumes that variables are complex-valued. Accordingly, none of the following expressions simplify by default:
To make an assumption or set of assumptions that will remain in effect, use:
Now, the expressions containing x and θ simplify:
(Note that Assume updates the built-in global variable $Assumptions.) Alternatively, we can assume a variable or set of variables are positive real numbers by using:
To display the assumptions currently in effect, use:
To remove assumptions for a variable or set of variables, use:
To remove all assumptions on all variables (resetting $Assumptions to the default value True), use:
At the top of code, it is useful to clear values for all variables in memory and also to clear assumptions (so that the code can then be evaluated cleanly). This can be done with the Restart command:
Now, the x and y variables have been cleared from memory:
To store the result of a calculation in a variable and then display the result as a framed image, use:
Since the answer has been stored to a variable, it can be referenced in further calculations:
For more complicated calculations, it is helpful to break into multiple lines:
Since the result has been stored to the dimension-ful variable energy, it can be easily converted to other units:
To store display and store multiple values at once, assign answers to a list of variables:
Scope (2)
Specific variants of the Assume command include AssumeReal, AssumePositive, and AssumeInteger:
If the result of a calculation is a matrix, then use the following variant of FrameAndStore command:
Again, since the variable is stored in memory, it can be referenced in further calculations:
To frame the result of a calculation and make it into a function for future use, include underscores in the arguments: