1 / 21

Symbolic Math Toolbox

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.

Télécharger la présentation

Symbolic Math Toolbox

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Symbolic Simplifications • Pretty Command • Factor Command • Collect Command • Expand Command • Simplify Command • Simple Command

  3. 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

  4. 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

  5. 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)

  6. 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

  7. 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

  8. 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

  9. 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)

  10. 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

  11. 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)

  12. Expand cos(3z) Term • Begin by expandingf(x) in terms of z

  13. Substitute and Simplify • From the previous work: • Substitute: • Simplify:

  14. Expand Verification • This is easily verified in Matlab » expand( cos(3*acos(x)) ) ans = 4*x^3-3*x

  15. 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)

  16. 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

  17. 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

  18. 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

  19. 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

  20. 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)

  21. 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

More Related