8. Symbolic Toolbox
Algebraic operations
A selection of commands in “Maple”:
simplify | performs algebraic and other functional simplifications |
simple | tries a number of simplification techniques including trigonometric identities; may need using twice |
collect | collects like terms |
factor | attempts to factor the expression |
expand | expands all terms |
poly2sym | converts array of polynomial coefficients in \mat into a symbolic expression in ‘‘Maple" with x as the variable |
sym2poly | converts symbolic polynomial in ‘‘Maple" into coefficient array in MATLAB |
At the simplest level, enter factor(28809).
Example 1: Suppose p(x) = x2(x + 4)2 − 8x(x + 1)2 + 13x − 6. Expand and factor in “Maple”, convert into an equivalent Matlab array, find the roots numerically, re-assemble the polynomial coefficients from the roots and then change back into a symbolic form.
clear all % file available in M-files folder as file5.m
syms x
p=x^2*(x+4)^2-8*x*(x+1)^2+13*x-6;
p=expand(p)
p=factor(p)
P=sym2poly(p) % change into MATLAB array P
polyroots=roots(P) % numerically find roots in \mat
Q=poly(polyroots) % re-assemble polynomial from its roots
q=poly2sym(Q) % change back to Maple expression
You will notice that the coefficients of x3 and x2 in q(x) are not exactly zero but are infinitesimally small due to tiny round-off errors introduced when numerically solving for the roots in MATLAB.
Example 2: Using trigonometric identities you should be able to show that
sin x/cos x − sin x + sin x/ cos x + sinx is equivalent to tan 2x.
Use simple in “Maple” to check this.
clear all % file available in M-files folder as file6.m
syms x
y=sin(x)/(cos(x)-sin(x))+sin(x)/(cos(x)+sin(x));
pretty(y)
y=simple(y)