| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Symbolic Math Toolbox |
| Contents | Index |
| Learn more about Symbolic Math Toolbox |
| On this page… |
|---|
In Symbolic Math Toolbox, symbolic variables are single complex variables by default. For example, if you declare z as a symbolic variable:
syms z
MATLAB assumes z is a complex variable. You can always check if a symbolic variable is assumed to be complex or real by entering conj command. If conj(x) == x returns 1, x is a real variable:
z == conj(z)
ans =
0The sym and syms commands allow you to set up assumptions for symbolic variables. For example, create the real symbolic variables x and y and the positive symbolic variable z:
x = sym('x', 'real');
y = sym('y', 'real');
z = sym('z', 'positive');or more efficiently
syms x y real; syms z positive;
There are two assumptions you can assign to a symbolic object within the sym command: real and positive. Together with the default complex property of a symbolic variable, it gives you three choices for an assumption for a symbolic variable: complex, real, and positive.
When you declare x to be real with the command
syms x real
you create a symbolic object x and the assumption that the object is real. Symbolic objects and their assumptions are stored separately. When you delete a symbolic object from the MATLAB workspace
clear x
the assumption that x is real stays in symbolic engine. If you declare a new symbolic variable x later, it inherits the assumption that x is real instead of getting a default assumption. If later you solve an equation and simplify an expression with the symbolic variable x, you could get incomplete results. For example, the assumption that x is real causes the polynomial x2+1 to have no roots:
syms x real; clear x; syms x; solve(x^2+1)
Warning: Explicit solution could not be found. > In solve at 81 ans = [ empty sym ]
The complex roots of this polynomial disappear because the symbolic variable x still has the assumption that x is real stored in the symbolic engine. To clear the assumption, enter
syms x clear
After you clear the assumption, the symbolic object stays in the MATLAB workspace. If you want to remove both the symbolic object and its assumption, use two subsequent commands:
To clear the assumption, enter
syms x clear
To delete the symbolic object, enter
clear x
For more information on clearing symbolic variables, see Clearing Assumptions and Resetting the Symbolic Engine.
![]() | Performing Symbolic Computations | Examples | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |