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

E N D

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

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

14. x and y are both symbolic variables

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

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

17. Workspace

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

19. Workspace

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

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

22. The variable ideal_gas_law has been assigned to an equation

23. The variable E as been assigned to an expression

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

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

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

27. Expanding and Factoring num is an expression

28. w is an equation

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

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

31. simplify used on an expression simplify used on an equation

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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