MATLAB Handout:
The Symbolic Toolbox
What is the Symbolic Toolbox?
MATLAB’s Symbolic Toolbox is a symbolic manipulator – it uses a special version of the Maple Kernel to
produce and display algebraic expressions rather than just performing the operations.
Definitions:
• Symbolic Expressions:
•
•
Symbolic Equations:
Symbolic Arithmetic:
MATLAB strings, or arrays of character strings, that can represent
numbers, functions, operators, and variables.
Symbolic expressions that contain an equal sign.
The practice of solving symbolic equations.
Declaring Symbolic Variables and Expressions
To declare symbolic variables, use the command: syms
To declare symbolic expressions and equations, use the command: sym()
MATLAB also assumes all strings may be manipulated as symbolic expressions or equations!
MATLAB Input
>> syms x y z
>> r = sqrt(x^2+y^2+z^2)
>> v = sym('x*cos(y)')
>> M = sym('[a,b;c,d]')
>> s = 'sqrt(x)'
Notes:
Declaration of symbolic variables x y and z
r is a symbolic variable since it was defined using at
least one symbolic variable.
The variable v contains the symbolic expression
“x*cos(y)”
Symbolic matrix
If properly formatted, any string may also be
manipulated as a symbolic expression
Abridged Command List
MATLAB Command
>> syms (by itself)
>> diff()
>> int()
>> jacobian()
>> determ() or det()
>> sum, prod, mean, std, del2,
conj, etc
>>
>>
>>
>>
subs(function,old,new)
simplify()
pretty()
eval()
Notes:
Lists all symbolic variables
Differentiate a symbolic expression
Integrate a symbolic expression
Find the Jacobian
Calculate the determinant of a symbolic matrix
Commands that operate on normal variables/vectors/arrays
will usually also operate symbolically on symbolic
variables/vectors/arrays
Replaces “old” with “new” in “function”
Collects terms
Prints out the expression in a “pretty” way
Evaluate a symbolic expression assuming all variables
have been defined in the workspace.
Examples
General Usage
Input
>> syms x y z
>> r = sqrt(x*x+y*y+z*z)
>> dr = diff(r,x)
>> pretty(dr)
>> dr2 =
subs(dr,'(x^2+y^2+z^2)^(1/2)','r')
>> pretty(dr2)
>>
>>
>>
>>
>>
x=3; y=4; z=12;
eval(r)
eval(dr)
eval(dr2)
r = eval(r); eval(dr2)
The Output
r = (x^2+y^2+z^2)^(1/2)
dr = 1/(x^2+y^2+z^2)^(1/2)*x
x
----------------2
2
2 1/2
(x + y + z )
dr2 = 1/r*x
x/r
ans
ans
ans
ans
=
=
=
=
13
0.230769230769231
3/(x^2+y^2+z^2)^(1/2)
0.230769230769231
Differentiation/Integration
Input
The Output
>>
>>
>>
>>
syms x a t
y = cos(t)
dy = diff(y)
Y = int(y)
y = cos(t)
dy = -sin(t)
Y = sin(t)
>>
>>
>>
>>
z = a*cos(x^2)+sin(t)
dz = diff(z)
dz = diff(z,t)
Z = int(z,t)
z = a*cos(x^2)+sin(t)
dz = -2*a*sin(x^2)*x (assumes dy2/dx!)
dz = cos(t)
Z = a*cos(x^2)*t-cos(t)
>> pretty(diff('1/exp(1+x^2)'))
x
-2 ----------2
exp(1 + x )
MATLAB Help
•
•
•
Type in “help sym” or “help syms” to get more information about the symbolic toolbox.
Type in “help <command>” to get more information about a specific command.
Type in “help sym/<command>” to get more information about a specific symbolic command that
has been overloaded from the non-symbolic command (ex. “diff”, “int”, etc).
Final Notes
•
•
The Symbolic Toolbox is very useful as a tool, but it will not error-check anything. It is best to check
everything by hand.
The Symbolic Toolbox manipulation is very slow! If you need a large number of derivatives for a
certain integrator, it is best to determine what those derivatives are and then hard-code the mathematical
expressions into the integrator rather than using symbolic tools to evaluate the symbolic expressions.
© Copyright 2026 Paperzz