symbolic math toolbox
DESCRIPTION
Math Review with Matlab:. Symbolic Math Toolbox. Simplification. S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan. Symbolic Simplifications. Pretty Command Factor Command Collect Command Expand Command Simplify Command Simple Command. P r e t t y. - PowerPoint PPT PresentationTRANSCRIPT
S. Awad, Ph.D.
M. Corless, M.S.E.E.
E.C.E. Department
University of Michigan
Math Review with Matlab:
Simplification
Symbolic Math Toolbox
U of M-Dearborn ECE DepartmentMath Review with Matlab
2
Symbolic Toolbox: Simplifications and Substitutions
Symbolic Simplifications Pretty Command Factor Command Collect Command Expand Command Simplify Command Simple Command
U of M-Dearborn ECE DepartmentMath Review with Matlab
3
Symbolic Toolbox: Simplifications and Substitutions
Pretty Command
The pretty command can be used to display symbolic expression in a format that resembles type-set mathematics
Pretty
pretty(s) prints the symbolic expression s
pretty(s,n) prints s using screen width n instead of the default 79
U of M-Dearborn ECE DepartmentMath Review with Matlab
4
Symbolic Toolbox: Simplifications and Substitutions
Pretty Examples» syms x» f=x^3 - 6*x^2 + 21*x -6;
» g=(x-1)*(x-2)*(x-3);» pretty(g) (x - 1) (x - 2) (x - 3)
» h=x*(x*(x-6)+11)-6;» pretty(h) x (x (x - 6) + 11) - 6
Product Polynomial
Nested Products
Polynomial» pretty(f) 3 2 x - 6 x + 21 x - 6
U of M-Dearborn ECE DepartmentMath Review with Matlab
5
Symbolic Toolbox: Simplifications and Substitutions
Factor Command The factor(f) command factors f into polynomial
products
» f = x^3 -6*x^2 +11*x -6;» y = factor(f)y =(x-1)*(x-2)*(x-3)
» y = factor(x^5-1)y =(x-1)*(x^4+x^3+x^2+x+1)
)3)(2)(1(116 623 xxxxxx
)1)(1(1 2345 xxxxxx
U of M-Dearborn ECE DepartmentMath Review with Matlab
6
Symbolic Toolbox: Simplifications and Substitutions
Collect Command The collect command collects coefficients of a
symbolic expression and rewrites it as powers of a polynomial
collect(s,v) s is a symbolic expression matrix
v is the independent polynomial variable
If v is omitted, collect uses rules to determine a default variable
U of M-Dearborn ECE DepartmentMath Review with Matlab
7
Symbolic Toolbox: Simplifications and Substitutions
Collect Examples Create symbolic
expression f(x,t)=(1+x)t+xt
» syms x t» f=(1+x)*t+x*tf =(1+x)*t+x*t
Specify collecting the x terms
Specify collecting the t terms
Unspecified independent variable collects the x variable
» f_col_x = collect(f,x)f_col_x =2*x*t+t
» f_col_t = collect(f,t)f_col_t =(1+2*x)*t
» f_col = collect(f)f_col =2*x*t+t
U of M-Dearborn ECE DepartmentMath Review with Matlab
8
Symbolic Toolbox: Simplifications and Substitutions
Expand Command The expand(s) command writes each element of the
symbolic expression s as a product of its factors
Types of expandable expressions include:
Polynomial expressions Trigonometric expressions Exponential expressions Logorithmetic expressions
This is the inverse of the collect command
U of M-Dearborn ECE DepartmentMath Review with Matlab
9
Symbolic Toolbox: Simplifications and Substitutions
Expand Examples
» syms a x y» expand(a*(x+y)) ans = a*x+a*y
» expand(exp(x+y))ans =exp(x)*exp(y)
Polynomial Expansion
Exponential Expansion
ayaxyxa
yxyx eee )(
Polynomial and exponential expansion examples
U of M-Dearborn ECE DepartmentMath Review with Matlab
10
Symbolic Toolbox: Simplifications and Substitutions
Involved Expand Example Given the following function of x:
xxf 1cos3cos)(
1) Expand f(x) by hand to get a polynomial function of x
2) Verify the result using the symbolic expand command
U of M-Dearborn ECE DepartmentMath Review with Matlab
11
Symbolic Toolbox: Simplifications and Substitutions
Expansion Approach To expand f(x) by hand, represent the inverse cosine
portion as a new function z
xxf 1cos3cos)(
xz 1cos
Expand cos(3z) in terms of z Once cos(3z) is expanded, substitute back in z=cos-
1(x)
Let:
zxf 3cos)( Thus:
U of M-Dearborn ECE DepartmentMath Review with Matlab
12
Symbolic Toolbox: Simplifications and Substitutions
Expand cos(3z) Term
zzxf
zzzz
zzzz
zzzz
zzzz
zzzzz
zzzz
zz
zxf
cos3cos4)(
cos2cos2coscos2
cos2cos2coscos2
coscos12coscos2
cossincoscos2
cossin2sincos1cos2
2sinsincos2cos
2cos
3cos)(
3
33
33
23
23
2
Begin by expanding f(x) in terms of z
U of M-Dearborn ECE DepartmentMath Review with Matlab
13
Symbolic Toolbox: Simplifications and Substitutions
Substitute and Simplify From the previous work:
zzxf cos3cos4)( 3 )(cos 1 xz
Substitute:
Simplify:
xxxf 113 coscos3coscos4)(
xxxf 34)( 3
U of M-Dearborn ECE DepartmentMath Review with Matlab
14
Symbolic Toolbox: Simplifications and Substitutions
Expand Verification
This is easily verified in Matlab
» expand( cos(3*acos(x)) )ans =4*x^3-3*x
xxxxf 34cos3cos)( 31
U of M-Dearborn ECE DepartmentMath Review with Matlab
15
Symbolic Toolbox: Simplifications and Substitutions
» syms x» f1=sin(x)^2 + cos(x)^2 + log(x);» f1_smplfy = simplify(f1) f1_smplfy = 1+log(x)
Simplify Command The simplify(s) command performs algebraic,
trigonometric, and logarithmic identities and relationships to simplify each element of the the symbolic matrix s
Trigonometric Identity:
1)(cos)(sin 22 xx
U of M-Dearborn ECE DepartmentMath Review with Matlab
16
Symbolic Toolbox: Simplifications and Substitutions
» syms a b» f=exp(a*log(b));» f_smplfy=simplify(f)f_smplfy =b^a » f_expnd = expand(f)f_expnd = b^a
Simplify Example Simplify the expression:
a
b
bbaf
ebafa
),(
),( ln
baebaf ln),(
Expand gives the same result
U of M-Dearborn ECE DepartmentMath Review with Matlab
17
Symbolic Toolbox: Simplifications and Substitutions
Example Methods for Simplification: Collect Similar Terms Trigonometric Identities Log/Complex Number Relations
Simple Command r = simple(s) tries different algebraic simplifications
and looks for the shortest form of the entire symbolic matrix s. If the result r is not specified, all intermediate steps are displayed to the screen.
[r,how] = simple(s) does not display intermediate simplifications, but returns the shortest form, as well as a string describing the simplification method used
U of M-Dearborn ECE DepartmentMath Review with Matlab
18
Symbolic Toolbox: Simplifications and Substitutions
Simplify Example Use the simple command to simplify the function f from the
previous example and show intermediate steps
» f=exp(a*log(b));» f_smpl=simple(f)simplify:b^a
radsimp:exp(a*log(b))
combine(trig):exp(a*log(b))
convert(sincos):exp(a*log(b))
convert(tan):exp(a*log(b))
collect(b):exp(a*log(b)) f_smpl =b^a
abxf )(
factor:exp(a*log(b))
expand:b^a
combine:exp(a*log(b))
convert(exp):exp(a*log(b))
U of M-Dearborn ECE DepartmentMath Review with Matlab
19
Symbolic Toolbox: Simplifications and Substitutions
Best Simplify Method Perform the
simplification again but show only the result
» [f_smpl]=simple(f) f_smpl =b^a
Recall from a previous example that the expand and simplify methods gave the same results
Also show which simplification was used » [f_smpl,how]=simple(f)
f_smpl =b^a how =expand
U of M-Dearborn ECE DepartmentMath Review with Matlab
20
Symbolic Toolbox: Simplifications and Substitutions
Simple Example
» f=sym( '(1+1/2*2^(1/2))^2+1+1/2*2^(1/2)') f =(1+1/2*2^(1/2))^2+1+1/2*2^(1/2) » f_smpl=simple(f)f_smpl =5/2+3/2*2^(1/2)
The simple command can also be used to simplify symbolic mathematical expressions without dependent variables
U of M-Dearborn ECE DepartmentMath Review with Matlab
21
Symbolic Toolbox: Simplifications and Substitutions
Summary The pretty command can be used to display symbolic
expressions in mathematical type-set form
The factor, collect, expand, and simplify commands can be used to reduce a symbolic expression to shorter forms
The simple command implements multiple simplification methods to simplify a symbolic expression to its shortest form
The simple command can also return the best simplification method used to reduce the symbolic expression