1.41k likes | 1.94k Views
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
E N D
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
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
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
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
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
This looks like a fairly complicated function of x If you expand it, it simplifies dramatically
However, when you simplify you may lose information Let x equal -3 When x is equal to -3, the equation is undefined
You can choose • MATLAB’s symbolic capability allows you perform the simplification, or to manipulate the numerator and denominator separately
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
MATLAB’s symbolic capability makes it easy to solve this problem
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
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)
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
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.
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')
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
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
Working with Equations and Expressions • Some MATLAB functions work on both expressions and equations • Others are limited in their scope
Extracting Numerators and Denominators • These functions work on expressions
The numden function extracts the numerator and denominator from an expression
You can combine symbolic variables using standard algebraic operators
Expanding and Factoring num is an expression
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
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
simplify used on an expression simplify used on an equation
Simple • The simple function is different from simplify • It tries all of the different simplification techniques, and chooses the result that is the shortest
All of the possibilities evaluated are reported, however there is only one actual answer Both simple and simplify work on expressions and equations
Hint • Use the poly2sym function as a shortcut to create a polynomial
Hint • Extract the coefficients from a polynomial, using the sym2poly function
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
You can define your expression or equation in the solve function
If x has previously been defined as a symbolic, the quotes aren’t necessary
The answer from the solve function is not necessarily a number You can specify what variable you want to solve for
Remember, if you have defined variables as symbolics previously – you can use them in expressions or equations without the single quotes
Example using solve Sometimes it’s useful to redefine a variable for latter use
Solving Systems of Equations This result is a structure array. These arrays are described in Chapter 11
There are several different approaches to find the actual values of x, y, and z
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
Assign individual variable names. Notice that x, y and z are symbolic variables
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
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.