MATLAB Tutor
Part 7: Symbolic Mathematics
If you are using the
Student Version of MATLAB, then you have access to the optional Symbolic Math
Toolbox. If you are using a professional (non-student) version, then you must
purchase this toolbox separately. If you do not know whether your version of
MATLAB is equipped with the toolbox or not, try a few of the following exercises.
If they work, you’ve got it. If not, you will have to skip over any exercise
that asks you to perform computations with variables that have not been assigned
numeric values and should be treated as symbols.
MATLAB’s Symbolic Math Toolbox
uses Maple, a powerful computer algebra system, to manipulate and solve symbolic
expressions.
- Whenever you want to use symbolic
mathematics, you must use the syms operator to alert MATLAB that you
are using a symbolic variable, and that it does not have a specific value.
Enter
syms x  % x is a symbolic variable
f = 3*x^2 - 5*x + 1 % sym expression
g = x^2 + 2*x % so is g
f + g
- Compare the result of step 1
to the one you get when you enter the following statements:
x = 5 % x has a numeric value
f
= 3*x^2 - 5*x + 1
- MATLAB has a plot command called
ezplot that will plot symbolic functions. Enter
syms x
f = 3*x^2 - 5*x + 1
ezplot(f, [- 3,2])
- To substitute a number or a
symbol into a symbolic expression, use the subs command. Enter
subs(f, x, - 2)
syms q
subs(f, x, q)
- Below we declare four symbolic
variables at once using the syms command and solve a quadratic equation using
the solve command. Enter
syms a b c t % Create symbolics
g = a*t^2 + b*t + c
solve(g, t) % Solve g = 0 for t
|
CCP Home |
Materials | Engineering Mathematics | Modu
le Contents | Back | Forward |