220 likes | 546 Views
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.
E N D
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
Pretty Pretty Command • The pretty command can be used to display symbolic expression in a format that resembles type-set mathematics pretty(s) prints the symbolic expression s pretty(s,n) prints s using screen width n instead of the default 79
Pretty Examples » syms x » f=x^3 - 6*x^2 + 21*x -6; Polynomial » pretty(f) 3 2 x - 6 x + 21 x - 6 Product Polynomial » g=(x-1)*(x-2)*(x-3); » pretty(g) (x - 1) (x - 2) (x - 3) Nested Products » h=x*(x*(x-6)+11)-6; » pretty(h) x (x (x - 6) + 11) - 6
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)
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
Collect Examples » syms x t » f=(1+x)*t+x*t f = (1+x)*t+x*t • Create symbolic expression f(x,t)=(1+x)t+xt • Specify collecting the x terms » f_col_x = collect(f,x) f_col_x = 2*x*t+t • Specify collecting the t terms » f_col_t = collect(f,t) f_col_t = (1+2*x)*t • Unspecified independent variable collects the x variable » f_col = collect(f) f_col = 2*x*t+t
Expand Command • The expand(s) command writes each element of the symbolic expression s as a product of its factors • This is the inverse of the collect command • Types of expandable expressions include: • Polynomial expressions • Trigonometric expressions • Exponential expressions • Logorithmetic expressions
Expand Examples • Polynomial and exponential expansion examples Polynomial Expansion » syms a x y » expand(a*(x+y)) ans = a*x+a*y Exponential Expansion » expand(exp(x+y)) ans = exp(x)*exp(y)
Involved Expand Example • Given the following function of x: 1) Expand f(x) by hand to get a polynomial function of x 2) Verify the result using the symbolic expand command
Expansion Approach • To expand f(x) by hand, represent the inverse cosine portion as a new function z Let: Thus: • Expandcos(3z) in terms of z • Once cos(3z) is expanded, substitute back in z=cos-1(x)
Expand cos(3z) Term • Begin by expandingf(x) in terms of z
Substitute and Simplify • From the previous work: • Substitute: • Simplify:
Expand Verification • This is easily verified in Matlab » expand( cos(3*acos(x)) ) ans = 4*x^3-3*x
Trigonometric Identity: Simplify Command • The simplify(s) command performs algebraic, trigonometric, and logarithmic identities and relationships to simplify each element of the the symbolic matrix s » syms x » f1=sin(x)^2 + cos(x)^2 + log(x); » f1_smplfy = simplify(f1) f1_smplfy = 1+log(x)
Expand gives the same result Simplify Example • Simplify the expression: » syms a b » f=exp(a*log(b)); » f_smplfy=simplify(f) f_smplfy = b^a » f_expnd = expand(f) f_expnd = b^a
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. • Example Methods for Simplification: • Collect Similar Terms • Trigonometric Identities • Log/Complex Number Relations • [r,how] = simple(s) does not display intermediate simplifications, but returns the shortest form, as well as a string describing the simplification method used
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)) factor: exp(a*log(b)) expand: b^a combine: exp(a*log(b)) convert(exp): 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
Best Simplify Method » [f_smpl]=simple(f) f_smpl = b^a • Perform the simplification again but show only the result • Also show which simplification was used » [f_smpl,how]=simple(f) f_smpl = b^a how = expand • Recall from a previous example that the expand and simplify methods gave the same results
Simple Example • The simple command can also be used to simplify symbolic mathematical expressionswithout dependent variables » 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)
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