Documentation |
The symbolic engine workspace associated with the MATLAB^{®} workspace is usually empty. The MATLAB workspace tracks the values of symbolic variables, and passes them to the symbolic engine for evaluation as necessary. However, the symbolic engine workspace contains all assumptions you make about symbolic variables, such as whether a variable is real, positive, integer, greater or less than some value, and so on. These assumptions can affect solutions to equations, simplifications, and transformations, as explained in Effects of Assumptions on Computations.
If you make an assumption about the nature of a variable, for example, using the commands
syms x assume(x,'real')
or
syms x assume(x > 0)
then clearing the variable x from the MATLAB workspace does not clear the assumption from the symbolic engine workspace. To clear the assumption, enter the command
syms x clear
For details, see Check Assumptions Set On Variables and Effects of Assumptions on Computations.
If you reset the symbolic engine by entering the command
reset(symengine)
MATLAB no longer recognizes any symbolic variables that exist in the MATLAB workspace. Clear the variables with the clear command, or renew them with the syms or sym command.
This example shows how the MATLAB workspace and the symbolic engine workspace respond to a sequence of commands.
Step | Command | MATLAB Workspace | MuPAD^{®} Engine Workspace |
---|---|---|---|
1 | syms x positive or syms x; assume(x > 0) | x | x > 0 |
2 | clear x | empty | x > 0 |
3 | syms x | x | x > 0 |
4 | syms x clear | x | empty |
To check whether a variable, say x, has any assumptions in the symbolic engine workspace associated with the MATLAB workspace, use the assumptions function in the MATLAB Command Window:
assumptions(x)
If the function returns an empty symbolic object, there are no additional assumptions on the variable. (The default assumption is that x can be any complex number.) Otherwise, there are additional assumptions on the value of that variable.
For example, while declaring the symbolic variable x make an assumption that the value of this variable is a real number:
syms x real assumptions(x)
ans = in(x, 'real')
Another way to set an assumption is to use the assume function:
syms z assume(z ~= 0); assumptions(z)
ans = z ~= 0
To see assumptions set on all variables in the MATLAB workspace, use assumptions without input arguments:
assumptions
ans = [ in(x, 'real'), z ~= 0]
Clear assumptions set on x and z:
syms x z clear
assumptions
ans = Empty sym: 1-by-0
Assumptions can affect many computations, including results returned by the solve function. They also can affect the results of simplifications. For example, solve this equation without any additional assumptions on its variable:
syms x solve(x^4 == 1, x)
ans = -1 1 -i i
Now solve the same equation assuming that x is real:
syms x real solve(x^4 == 1, x)
ans = -1 1
Use the assumeAlso function to add the assumption that x is also positive:
assumeAlso(x > 0) solve(x^4 == 1, x)
ans = 1
Clearing x does not change the underlying assumptions that x is real and positive:
clear x syms x assumptions(x) solve(x^4 == 1, x)
ans = [ 0 < x, in(x, 'real')] ans = 1
Clearing x with syms x clear clears the assumption:
syms x clear assumptions(x)
ans = Empty sym: 1-by-0