1 / 130

Symbolic Mathematics Chapter 12

Symbolic Mathematics Chapter 12. Objectives. After studying this chapter you should be able to: Create and manipulate symbolic variables Factor and simplify mathematical expressions Solve symbolic expressions Solve systems of equations Determine the symbolic derivative of an expression

Télécharger la présentation

Symbolic Mathematics Chapter 12

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.


Presentation Transcript

  1. Symbolic MathematicsChapter 12

  2. Objectives After studying this chapter you should be able to: • Create and manipulate symbolic variables • Factor and simplify mathematical expressions • Solve symbolic expressions • Solve systems of equations • Determine the symbolic derivative of an expression • Integrate an expression symbolically

  3. MuPad • MATLAB’s symbolic capability is based on the MuPad software, • Originally produced by Sciface Software and purchased by the Mathworks in 2008. • Previous versions of MATLAB, before 2007b, used Maple as the symbolic engine

  4. Symbolic Manipulation • Available in the “Symbolic Math Toolbox” – which is an option in the professional version • Included with the Student Edition • There are some differences between the MuPad and Maple implementations of the symbolic toolbox • If you have Maple installed on your computer it has an interface to MATLAB, which may over-ride the default MuPad engine

  5. Capabilities • Manipulate symbolic expressions to • Simplify • Solve symbolically • Evaluate numerically • Take derivatives • Integrate • Perform linear algebraic manipulations • More advanced features include • LaPlace transforms • Fourier transforms • Variable precision arithmetic

  6. Notebook Environment

  7. Section 12.1Symbolic Algebra • Used regularly in math, engineering and science classes • Often preferable to manipulate equations symbolically before you substitute in values for variables Consider this equation

  8. This looks like a fairly complicated function of x If you expand it, it simplifies dramatically

  9. However, when you simplify you may lose information Let x equal -3 When x is equal to -3, the equation is undefined

  10. You can choose • MATLAB’s symbolic capability allows you perform the simplification, or to manipulate the numerator and denominator separately

  11. If we know k0 Q R T Its easy to solve for k It’s not easy to solve for T! Relationships are not always easy to solve

  12. MATLAB’s symbolic capability makes it easy to solve this problem

  13. Creating Symbolic Variables • Two approaches • Use the sym command to create • Single variable • Expression • Equation • Use the syms command to create • Single variables • Compose expressions and equations from the variables you’ve defined

  14. Here’s an example • Define x as a symbolic variable • x=sym('x') or • syms x • Use x to create a more complicated expression • y = 2*(x+3)^2/(x^2+6*x+9)

  15. x and y are both symbolic variables

  16. The syms command can create multiple variables • syms Q R T k0 • Use these variables to create another symbolic variables k=k0*exp(-Q/(R*T)) Notice that we used standard algebraic operators – the array operators (.*, ./ and .^) are not used in symbolic algebra

  17. Create an entire expression with the sym command • E=sym('m*c^2') • Since m and c have not been specifically defined as symbolic variables, they are not stored • E was set equal to a character string, defined by the single quotes inside the function.

  18. Workspace

  19. This is an assignment statement This is an algebraic equation Equations vs Expressions • We can create an entire equation, and give it a name • ideal_gas_law=sym('P*V=n*R*Temp')

  20. Workspace

  21. Reserved Variable Names One idiosyncrasy of the implementation of MuPad inside MATLAB is that a number of commonly used variables are reserved. They can be overwritten, however it you try to use them inside expressions or equations you may run into problems. D, E, I, O, beta, zeta, theta, psi, gamma, Ci, Si, Ei

  22. Manipulating Symbolic Expressions and Equations • Equations are set equal to something • Expressions are not • Both expressions and equations can be assigned a name, using the MATLAB assignment operator

  23. The variable ideal_gas_law has been assigned to an equation

  24. The variable E as been assigned to an expression

  25. Working with Equations and Expressions • Some MATLAB functions work on both expressions and equations • Others are limited in their scope

  26. Extracting Numerators and Denominators • These functions work on expressions

  27. The numden function extracts the numerator and denominator from an expression

  28. You can combine symbolic variables using standard algebraic operators

  29. Expanding and Factoring num is an expression

  30. w is an equation

  31. The factor function used with an expression, den The factor function used with an equation, w The collect function is similar, and collects common terms

  32. Simplifying • The expand, factor and collect functions can be used to “simplify” an expression and sometimes an equation • What constitutes a simplification is not always obvious • The simplify function uses a set of built in rules

  33. simplify used on an expression simplify used on an equation

  34. Simple • The simple function is different from simplify • It tries all of the different simplification techniques, and chooses the result that is the shortest

  35. All of the possibilities evaluated are reported, however there is only one actual answer Both simple and simplify work on expressions and equations

  36. Hint • Use the poly2sym function as a shortcut to create a polynomial

  37. Hint • Extract the coefficients from a polynomial, using the sym2poly function

  38. Section 12.2Solving Equations and Expressions • Use the solve function • Automatically sets expressions equal to 0 and solves for the roots • Uses the equality specified in equations • Solves for the variables in systems of equations

  39. You can define your expression or equation in the solve function

  40. If x has previously been defined as a symbolic, the quotes aren’t necessary

  41. The answer from the solve function is not necessarily a number You can specify what variable you want to solve for

  42. Remember, if you have defined variables as symbolics previously – you can use them in expressions or equations without the single quotes

  43. Example using solve Sometimes it’s useful to redefine a variable for latter use

  44. Solving Systems of Equations This result is a structure array. These arrays are described in Chapter 11

  45. There are several different approaches to find the actual values of x, y, and z

  46. Give the result a name, such as answer, and then specify the field name inside the structure array to retrieve the values for x, y, and z

  47. Assign individual variable names. Notice that x, y and z are symbolic variables

  48. If you need to use the value of x, y or z in a function that needs a double as input, you’ll need to change the variable type from symbolic to double

  49. Hint • Using the solve function for multiple equations has both advantages and disadvantages over using the linear algebra techniques described in chapter 9. • In general, if a problem can be solved using matrices the matrix solution will take less computer time. • However, linear algebra is limited to first order equations. • The solve function may take longer, but it can solve non-linear problems and can solve problems with symbolic variables.

More Related