5. symbolic math toolbox - kau

34
41 5. Symbolic Math Toolbox Symbolic Math Toolbox software lets you to perform symbolic computations within the MATLAB numeric environment. It provides tools for solving and manipulating symbolic math expressions and performing variable-precision arithmetic. The toolbox contains hundreds of symbolic functions that leverage the MuPAD engine for a broad range of mathematical tasks such as: a) Differentiation b) Integration c) Linear algebraic operations d) Simplification e) Transforms f) Variable-precision arithmetic g) Equation solving 5.1 Direct Simple Examples The sym command creates symbolic variables and expressions. For example, the commands x = sym('x') a = sym('alpha') create a symbolic variable x with the value x assigned to it in the MATLAB workspace and a symbolic variable a with the value alpha assigned to it. An alternate way to create a symbolic object is to use the syms command: syms x alpha a=alpha You can use sym or syms to create symbolic variables. Here are some examples: syms abcx f = a*x^2 + b*x + c; D = diff(f) % Differentiate f with respect to x D = 2*a*x+b Da = diff(f,a) % Differentiate f with respect to a Da = x^2 I = int(f) % Integrate with respect to x I = 1/3*a*x^3+1/2*b*x^2+c*x

Upload: others

Post on 18-Dec-2021

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 5. Symbolic Math Toolbox - kau

41

5. Symbolic Math ToolboxSymbolic Math Toolbox software lets you to perform symbolic computations within theMATLAB numeric environment. It provides tools for solving and manipulating symbolicmath expressions and performing variable-precision arithmetic. The toolbox containshundreds of symbolic functions that leverage the MuPAD engine for a broad range ofmathematical tasks such as:

a) Differentiationb) Integrationc) Linear algebraic operationsd) Simplificatione) Transformsf) Variable-precision arithmeticg) Equation solving

5.1 Direct Simple Examples

The sym command creates symbolic variables and expressions. For example, thecommands

x = sym('x')a = sym('alpha')

create a symbolic variable x with the value x assigned to it in the MATLAB workspaceand a symbolic variable a with the value alpha assigned to it. An alternate way tocreate a symbolic object is to use the syms command:

syms x alphaa=alpha

You can use sym or syms to create symbolic variables. Here are some examples:

syms a b c xf = a*x^2 + b*x + c;D = diff(f) % Differentiate f with respect to xD =2*a*x+bDa = diff(f,a) % Differentiate f with respect to aDa =x^2

I = int(f) % Integrate with respect to xI =1/3*a*x^3+1/2*b*x^2+c*x

Page 2: 5. Symbolic Math Toolbox - kau

42

I = int(f,0,1) % Integrate with respect to x from 0 to 1I =1/3*a+1/2*b+c

h = finverse(sqrt(x+1)) % find the inverse functionh =

-1+x^2

clear % clear the workspace

syms x; g=3*x^2+5*x-4; h=subs(g,x,2)h =

18

n=sym2poly(g) %extract the numerical coefficient vectorn =

3 5 -4

p = poly2sym(n) % recreate the polynomial in xp =3*x^2+5*x-4

S = dsolve('Dy=1+y^2') % find the general solutionS =

tan(t+C1)

dsolve('Dy=1+y^2,y(0)=1') % add an initial conditionans =

tan(t+1/4*pi)

dsolve('D2y-2*Dy-3*y=0') % solve a 2ed ODE.

y = dsolve('D2y-2*Dy-3*y=0','y(0)=0','y(1)=1')y =1/(exp(-1)-exp(3))*exp(-t)-1/(exp(-1)-exp(3))*exp(3*t)

pretty(y)exp(-t) exp(3 t)

---------------- - ----------------exp(-1) - exp(3) exp(-1) - exp(3)

ezplot(y,[-6,2]) % plot the result in an interesting region

[f,g]=dsolve('Df=3*f+4*g, Dg=-4*f+3*g') % solve a system of ODEf =exp(3*t)*(C1*sin(4*t)+C2*cos(4*t))

g =-exp(3*t)*(-C1*cos(4*t)+C2*sin(4*t))

Page 3: 5. Symbolic Math Toolbox - kau

43

syms('a','b','c','d'); M=[a,b;c,d] % create a symbolic matrix

M =[ a, b][ c, d]

Differentiation

To illustrate how to take derivatives using Symbolic Math Toolbox software, first createa symbolic expression:

syms xf = sin(5*x)

The command

diff(f) % differentiates f with respect to x:

ans =5*cos(5*x)

As another example, let

g = exp(x)*cos(x)

where exp(x) denotes , and differentiate g:

diff(g)ans =exp(x)*cos(x) - exp(x)*sin(x)

To take the second derivative of g, enter

diff(g,2)ans =(-2)*exp(x)*sin(x)

You can get the same result by taking the derivative twice:

diff(diff(g))ans =(-2)*exp(x)*sin(x)

Page 4: 5. Symbolic Math Toolbox - kau

44

The diff function can also take a symbolic matrix as its input. In this case, thedifferentiation is done element-by-element. Consider the example

syms a xA = [cos(a*x),sin(a*x);-sin(a*x),cos(a*x)]which returns

A =[ cos(a*x), sin(a*x)][ -sin(a*x), cos(a*x)]The command

diff(A)returns

ans =[ -a*sin(a*x), a*cos(a*x)][ -a*cos(a*x), -a*sin(a*x)]

A table summarizing diff and jacobian follows.

Mathematical Operator MATLAB Command

diff(f) or diff(f,x)

diff(f,a)

diff(f,b,2)

= ( , )( , ) J = jacobian([r;t],[u;v])

Limits

Symbolic Math Toolbox software enables you to calculate the limits of functions

directly. For example to find lim→syms x a t h;limit(sin(x)/x) => 1

Page 5: 5. Symbolic Math Toolbox - kau

45

One-Sided LimitsYou can also calculate one-sided limits with Symbolic Math Toolbox software. Forexample, you can calculate the limit of /| |, as x approaches 0 from the left or from theright.

limit(1/x,x,0,'right') => Inflimit(1/x,x,0,'left') => -Inf

Since the limit from the left does not equal the limit from the right, the two- sided limitdoes not exist. In the case of undefined limits, MATLAB returns NaN (not a number).For example,

limit(x/abs(x),x,0)returnsans =NaN

More examples are:limit((sin(x+h)-sin(x))/h,h,0) => cos(x)v = [(1 + a/x)^x, exp(-x)];limit(v,x,inf)

Observe that the default case, limit(f) is the same as limit(f,x,0). Explore theoptions for the limit command in this table, where f is a function of the symbolicobject x.

Mathematical Operation MATLAB Commandlim→ ( ) limit(f)lim→ ( ) limit(f,x,a) or limit(f,a)lim→ ( ) limit(f,x,a,'left')lim→ ( ) limit(f,x,a,'right')

Integration

If f is a symbolic expression, then int(f) attempts to find another symbolic expression, F,so that diff(F) = f. That is, int(f) returns the indefinite integral or antiderivative off (provided one exists in closed form). Similar to differentiation, int(f,v) uses thesymbolic object v as the variable of integration, rather than the variable determined bysymvar. See how int works by looking at this table.

Page 6: 5. Symbolic Math Toolbox - kau

46

Mathematical Operation MATLAB Command

∫ = log( ) if = −1otherwise int(x^n) or int(x^n,x)

∫ sin(2 ) = 1/ int(sin(2*x),0,pi/2) or

int(sin(2*x),x,0,pi/2)= cos( + )∫ ( ) = ( ) g = cos(a*t + b) int(g) or int(g,t)

∫ ( ) = − ( ) int(besselj(1,z)) orint(besselj(1,z),z)

Symbolic Summation

You can compute symbolic summations, when they exist, by using the symsumcommand. For example, the p-series

1 + 12 + 13 +⋯sums to /6, while the geometric series 1 + + +⋯ sums to 1/(1 – x), provided| | < 1. These summations are demonstrated below:

syms x ks1 = symsum(1/k^2,1,inf)s2 = symsum(x^k,k,0,inf)

s1 =pi^2/6

s2 =piecewise([1 <= x, Inf], [abs(x) < 1, -1/(x - 1)])

Taylor Series

The statements

syms xf = 1/(5+4*cos(x))T = taylor(f,8)return

Page 7: 5. Symbolic Math Toolbox - kau

47

T =(49*x^6)/131220 + (5*x^4)/1458 + (2*x^2)/81 + 1/9

These commands

syms xg = exp(x*sin(x))t = taylor(g,12,2);

generate the first 12 nonzero terms of the Taylor series for g about x = 2.

t is a large expression; enter

size(char(t))

ans =1 99791

Optimizing Nonlinear Functions

To find the minimum of a function of one variable within a fixed interval use fminbndcommand, as in the following examples:

x = fminbnd(@cos,3,4) % Computes to a few decimal places.

The argument fun can also be a function handle for an anonymous function. Forexample, to find the minimum of the function − 2 − 5 on the interval (0,2), createan anonymous function

f = @(x)x.^3-2*x-5;ORf = inline('x.^3-2*x-5')

Then invoke fminbnd with

x = fminbnd(f, 0, 2)

The result is

x =0.8165

The value of the function at the minimum is

Page 8: 5. Symbolic Math Toolbox - kau

48

y = f(x)

y =-6.0887.

Maximizing Functions

If you have a maximization problem, that is, a problem of the form max ( ) then define( ) = – ( ), and minimize . For example, to find the maximum of tan(cos( )) near= 5, evaluate:

[x , fval] = fminbnd(@ (x)-tan(cos(x)),3,8)x =

6.2832

fval =-1.5574

The maximum is 1.5574 (the negative of the reported fval), and occurs at x = 6.2832.This answer is correct since, to five digits, the maximum is tan(1) = 1.5574, whichoccurs at = 2 = 6.2832.To find more go to Function Reference

Substituting in Symbolic Expressions (subs Command)

You can substitute a numeric value for a symbolic variable or replace one symbolicvariable with another using the subs command. For example, to substitute the value =2 in the symbolic expression

syms xf = 2*x^2 - 3*x + 1

enter the command

subs(f,2)ans =

3

Here an example for more than one variable

syms x yf = x^2*y + 5*x*sqrt(y)subs(f, x, 3)ans =9*y + 15*y^(1/2)

Page 9: 5. Symbolic Math Toolbox - kau

49

You also can substitute one symbolic variable for another symbolic variable

subs(f, y, x)ans = x^3 + 5*x^(3/2)

5.2 Calculus Example

This example describes how to analyze a simple function to find its asymptotes,maximum, minimum, and inflection point. The section covers the following topics:

Let ( ) =To create the function, enter the following commands:

syms xnum = 3*x^2 + 6*x -1;denom = x^2 + x - 3;f = num/denom

This returns

f =(3*x^2 + 6*x - 1)/(x^2 + x - 3)

You can plot the graph of by entering ezplot(f)

This displays the following plot.

-6 -4 -2 0 2 4 6-4

-2

0

2

4

6

8

x

(3 x2 + 6 x - 1)/(x2 + x - 3)

Page 10: 5. Symbolic Math Toolbox - kau

50

Finding the Asymptotes

To find the horizontal asymptote of the graph of , take the limit of as approachespositive infinity:

limit(f, inf)ans =3

The limit as x approaches negative infinity is also 3. This tells you that the line y = 3 is ahorizontal asymptote to the graph.

To find the vertical asymptotes of , set the denominator equal to 0 and solve by enteringthe following command:

roots = solve(denom)

This returns to solutions to: = ∓√roots =

13^(1/2)/2 - 1/2- 13^(1/2)/2 – 1/2

This tells you that vertical asymptotes are the lines = ∓√You can plot the horizontal and vertical asymptotes with the following commands:

ezplot(f) hold on % Keep the graph of f in the figure% Plot horizontal asymptoteplot([-2*pi 2*pi], [3 3],'g')% Plot vertical asymptotesplot(double(roots(1))*[1 1], [-5 10],'r')plot(double(roots(2))*[1 1], [-5 10],'r')title('Horizontal and Vertical Asymptotes')hold off

Page 11: 5. Symbolic Math Toolbox - kau

51

Finding the Maximum and Minimum

You can see from the graph that f has a local maximum somewhere between the points= –2 and = 0, and might have a local minimum between = –6 and = –2. Tofind the x-coordinates of the maximum and minimum, first take the derivative of f:

f1 = diff(f)This returns

f1 =(6*x+6)/(x^2+x-3) - ((2*x+1)*(3*x^2+6*x-1))/(x^2+x-3)^2

To simplify this expression, enter

f1 = simplify(f1)f1 =-(3*x^2 + 16*x + 17)/(x^2 + x - 3)^2

Next, set the derivative equal to 0 and solve for the critical points:

crit_pts = solve(f1)crit_pts =

13^(1/2)/3 - 8/3- 13^(1/2)/3 - 8/3

It is clear from the graph of that it has a local minimum at = (−8 − √13)/3 and alocal maximum at = (−8 + √13)/3.

-6 -4 -2 0 2 4 6-4

-2

0

2

4

6

8

x

Horizontal and Vertical Asymptotes

Page 12: 5. Symbolic Math Toolbox - kau

52

You can plot the maximum and minimum of f with the following commands:

figure(2)ezplot(f)hold onplot(double(crit_pts), double(subs(f,crit_pts)),'ro')title('Maximum and Minimum of f')text(-5.5,3.2,'Local minimum')text(-2.5,2,'Local maximum')hold off

This displays the following figure.

Finding the Inflection Point

To find the inflection point of , set the second derivative equal to 0 and solve.

f2 = diff(f1);inflec_pt = solve(f2);double(inflec_pt)

ans =-5.2635-1.3682 - 0.8511i-1.3682 + 0.8511i

To plot the inflection point, enter

ezplot(f, [-9 6])hold onplot(double(inflec_pt), double(subs(f,inflec_pt)),'ro')title('Inflection Point of f')text(-7,2,'Inflection point')

-6 -4 -2 0 2 4 6-4

-2

0

2

4

6

8

x

Maximum and Minimum of f

Local minimum

Local maximum

Page 13: 5. Symbolic Math Toolbox - kau

53

hold off

The extra argument, [-9 6], in ezplot extends the range of x values in the plot sothat you see the inflection point more clearly, as shown in the following figure.

5.3 Creating Plots of Symbolic Functions

You can create different types of graphs including:

Plots of explicit functions Plots of implicit functions 3-D parametric plots Surface plots

Explicit Function Plot

The simplest way to create a plot is to use the ezplot command:

syms xezplot(x^3 - 6*x^2 + 11*x - 6);hold on;xlabel('x axis');title('Explicit function: x^3 - 6*x^2 + 11*x - 6');grid on;hold off

-8 -6 -4 -2 0 2 4 6

-2

0

2

4

6

8

x

Inflection Point of f

Inflection point

Page 14: 5. Symbolic Math Toolbox - kau

54

Implicit Function Plot

You can plot implicitly defined functions. For example, create a plot for the followingimplicit function over the domain – 1 < < 1:syms x y;f = (x^2 + y^2)^4 - (x^2 - y^2)^2;ezplot(f, [-1 1]);hold on;xlabel('x axis');ylabel('y axis');title('Implicit function: f =(x^2 + y^2)^4 - (x^2 - y^2)^2');grid on;hold off

3-D Plot

3-D graphics is also available in Symbolic Math Toolbox . To create a 3-D plot, use theezplot3 command. For example:

-6 -4 -2 0 2 4 6

-500

-400

-300

-200

-100

0

100

x axis

Explicit function: x3 - 6*x2 + 11*x - 6

-1 -0.5 0 0.5 1-1

-0.5

0

0.5

1

x axis

y ax

is

Implicit function: f = (x2 + y2)4 - (x2 - y2)2

Page 15: 5. Symbolic Math Toolbox - kau

55

syms tezplot3(t^2*sin(10*t),t^2*cos(10*t), t);

Surface Plot

If you want to create a surface plot, use the ezsurf command. For example, to plot aparaboloid z = x2 + y2, enter:

syms x yezsurf(x^2 + y^2);hold on;zlabel('z');title('z = x^2 + y^2');hold off

-40-20

020

40

-50

0

500

2

4

6

8

x

x = t2 sin(10 t), y = t2 cos(10 t), z = t

y

z

-50

5

-5

0

50

20

40

60

80

x

z = x2 + y2

y

z

Page 16: 5. Symbolic Math Toolbox - kau

56

5.4 Solving Equations

You can solve different types of symbolic equations including: Algebraic equations with one symbolic variable Algebraic equations with several symbolic variables Systems of algebraic equations

Non-linear equation in one variable

You can find the values of variable for which the following expression is equal to zero:

syms xS = solve(x^3 - 6*x^2 + 11*x - 6)S =123

syms xS1 = solve('x^3 - 6*x^2 + 11*x - 5 = 1')S1 =123

syms x, s = solve(2^x -5*x + 2); s=double(s)

s =0.73224.2768

Also we can use fzero that find zero of a function of one variable for instance

x = fzero('2^x -5*x + 2',2)x =

0.7322

Note that fzero here gives only one solution that is near 0, which we declared.

Algebraic Equations with Several Symbolic Variables

If an equation contains several symbolic variables, you can designate a variable for whichthis equation should be solved. For example, you can solve the multivariable equation:

syms x y

Page 17: 5. Symbolic Math Toolbox - kau

57

f = 6*x^2 - 6*x^2*y + x*y^2 - x*y + y^3 - y^2;solve(f,y) %with respect to a symbolic variable y

ans =1

2*x(-3)*x

Systems of Algebraic Equations

You also can solve systems of equations. For example:

syms x y z[x,y,z] = solve('z = 4*x', 'x = y', 'z = x^2 + y^2')

x =02

y =02

z =08

A second example is

S = solve('x + y = 1','x - 11*y = 5'); y=S.y, x=S.x

y = -1/3, x =4/3

System of non-linear equations

Here some examples

syms x yf1 = sin(x+y)-exp(x-y);f2 = cos(x+6)-x^2*y^2;[x,y]=solve(f1,f2)

x = 0.37431309936308903796730912802326y = 2.6660119905883936377175405750553

Page 18: 5. Symbolic Math Toolbox - kau

58

A = solve('a*u^2 + v^2', 'u - v = 1', 'a^2 - 5*a + 6')A =

a: [4x1 sym]u: [4x1 sym]v: [4x1 sym]

A.a =3223

u = A.u; u=double(u)u =

0.2500 + 0.4330i0.3333 + 0.4714i0.3333 - 0.4714i0.2500 - 0.4330i

v = A.v; v=double(v)

v =-0.7500 + 0.4330i-0.6667 + 0.4714i-0.6667 - 0.4714i-0.7500 - 0.4330i

5.5 Introduction to MuPAD

MuPAD notebooks provide a new interface for performing symbolic calculations,variable-precision calculations, plotting, and animations.

Symbolic Math Toolbox functions allow you to copy variables and expressionsbetween the MATLAB workspace and MuPAD notebooks..

You can call MuPAD functions and procedures from the MATLAB environment.For more information, see Calling MuPAD Functions at the MATLAB CommandLine.

Desktop Overview

A MuPAD notebook has three types of regions: input regions, output regions, and textregions.

Page 19: 5. Symbolic Math Toolbox - kau

59

Example Using a MuPAD NotebookThis example shows how to use a MuPAD notebook to calculate symbolically the meanand variance of a normal random variable that is restricted to be positive.

The density function of the normal and positive random variable is

( ) = / 2/ if > 00 otherwise1. At the MATLAB command line, enter the command

mupad

2. A blank MuPAD notebook opens. You perform calculations by typing in the inputarea, demarcated by a left bracket.

Page 20: 5. Symbolic Math Toolbox - kau

60

3. In the input area, type

f := exp(-x^2/2)*sqrt(2/PI)

and press Enter.

The MuPAD notebook displays results in real math notation.

Your notebook appears as follows.

Page 21: 5. Symbolic Math Toolbox - kau

61

4. The mean of the random variable is

mean =To calculate the mean of the random variable, type

mean :=

a. To place an integral in the correct syntax, click the integral button in the right-hand command bar, and select definite limits as shown.

b. The correct syntax for integration appears in the input area.[ mean := int(#f, #x=#a..#b)

c. Replace #f with x*f, #x with x, #a with 0, and #b with infinity. Use the Tab key to select the replaceable fields #f, #x, etc. Use Ctrl+space to autocomplete inputs; e.g., enter infi followed by

Ctrl+space to enter infinity.

Once your input area reads

mean := int(x*f, x=0..infinity)

press Enter.

Page 22: 5. Symbolic Math Toolbox - kau

62

5. The variance of the random variable is

variance = (mean − )To calculate the variance of the random variable, type

variance := int((x-mean)^2*f, x=0..infinity)

and press Enter.

6. The result of evaluating variance is a complicated expression. Try to simplify itwith the simplify command. Type

simplify(variance)

and press Enter. The result is indeed simpler.

Page 23: 5. Symbolic Math Toolbox - kau

63

7. Another expression for the variance of the random variable is

variance = −meanTo calculate the variance of the random variable using this definition, type

variance2 := int(x^2*f, x=0..infinity) - mean^2

and press Enter.

The two expressions for variance, variance and variance2, are obviouslyequivalent.

Performing Computations Computing with Numbers

Differentiation

Integration

Linear Algebra

Solving Equations

Manipulating Expressions

Computing with Integers and RationalsWhen computing with integers and rational numbers, MuPAD returns integer results

[ 2 + 2

[ 4

Computing with Special Mathematical Constants

Page 24: 5. Symbolic Math Toolbox - kau

64

You can perform exact computations that include the constants = exp(1) = 2.718…and = 3.1415. ..Approximating Numerically

By default, MuPAD performs all computations in an exact form. To obtain a floating-poing approximation to an expression, use the float command. For example:

The accuracy of the approximation depends on the value of the global variable DIGITS.The variable DIGITS can assume any integer value between 1 and . For example:

Working with Complex Numbers

In the input regions MuPAD recognizes an uppercase I as the imaginary unit √−1. In theoutput regions, MuPAD uses a lowercase i to display the imaginary unit:

Derivatives of Single-Variable Expressions

Page 25: 5. Symbolic Math Toolbox - kau

65

To compute the derivative of a mathematical expression, use the diff command. For example:

Partial DerivativesYou also can compute a partial derivative of a multivariable expression:

Second- and Higher-Order DerivativesTo find higher order derivatives, use a nested call of the diff command

or, more efficiently:

You can use the sequence operator $ to compute second or higher order derivatives:

Indefinite IntegralsTo compute integrals use the int command. For example, you can compute indefinite integrals:

The int command returns results without an integration constant.

Definite IntegralsTo find a definite integral, pass the upper and lower limits of the integration interval to the intfunction:

Page 26: 5. Symbolic Math Toolbox - kau

66

You can use infinity as a limit when computing a definite integral:

Numeric ApproximationIf MuPAD cannot evaluate an expression in a closed form, it returns the expression. For example:

You can approximate the value of an integral numerically using the float command. For example:

You also can use the numeric::int command to evaluate an integral numerically. For example:

Linear AlgebraWe will learn how to Creating a Matrix, Operating on Matrices, and Linear Algebra Library

Creating a MatrixTo create a matrix in MuPAD, use the matrix command:

Page 27: 5. Symbolic Math Toolbox - kau

67

You also can create vectors using the matrix command:

You can explicitly declare the matrix dimensions:

You also can create a diagonal matrix:

Operating on MatricesTo add, substract, multiply and divide matrices, use standard arithmetic operators. For example,to multiply two matrices, enter:

Page 28: 5. Symbolic Math Toolbox - kau

68

If you add number x to a matrix A, MuPAD adds x times an identity matrix to A. For example:

You can compute the determinant and the inverse of a square matrix:

Linear Algebra LibraryThe MuPAD library 'linalg' contains the functions for handling linear algebraic operations. Usingthis library, you can perform a wide variety of computations on matrices and vectors. Forexample, to find the eigenvalues of the square matrices G, F, and (A*B), use thelinalg::eigenvalue command:

To see all the functions available in this library, enter info(linalg) in an input region. You canobtain detailed information about a specific function by entering ? function name. For example, toopen the help page on the eigenvalue function, enter ? linalg::eigenvalues

Page 29: 5. Symbolic Math Toolbox - kau

69

Solving EquationsYou can solve different types of equations, including:

Equations with one variable Equations with parameters Systems of equations Ordinary differential equations Inequalities

If MuPAD cannot solve an equation or a system of equations symbolically, you can use thenumeric solver to find an approximate numeric solution. For more in-depth information onsolving equations and inequalities, see the solve function help page.

Solving Equations with One VariableTo solve a simple algebraic equation with one variable, use the solve command:

solve(x^5 + 3*x^4 - 23*x^3 - 51*x^2 + 94*x + 120 = 0, x)

Solving Equations with ParametersYou can solve an equation with symbolic parameters:

If you want to get the solution for particular values of the parameters, use the assumingcommand. For example, you can solve the following equation assuming that a is positive:

For more information, see Using Assumptions.

Page 30: 5. Symbolic Math Toolbox - kau

70

Solving Systems of EquationsYou can solve a system of equations:

or you can solve a system of equations containing symbolic parameters:

Solving Ordinary Differential EquationsYou can solve different types of ordinary differential equations:

Solving InequalitiesAlso, you can solve inequalities:

Page 31: 5. Symbolic Math Toolbox - kau

71

If you want to get the result over the field of real numbers only, assume that x is a real number:

You can pick the solutions that are positive:

Manipulating ExpressionsYou can transform mathematical expressions by applying simplification functions. For example,you can:

Transform and simplify polynomial expressions. Transform and simplify trigonometric expressions. Simplify particular parts of expressions.

Transforming and Simplifying Polynomial ExpressionsThere are several ways to present a polynomial expression. The standard polynomial form is asum of monomials. To get this form of a polynomial expression, use the expand command:

You can factor this expression using the factor command:

For multivariable expressions, you can specify a variable and collect the terms with the samepowers in this variable:

For rational expressions, you can use the partfrac command to present the expression as a sum offractions (partial fraction decomposition). For example:

Page 32: 5. Symbolic Math Toolbox - kau

72

MuPAD also provides two general simplification functions: simplify and Simplify.

For the following expression the two simplification functions give different forms of the samemathematical expression:

Note that there is no universal simplification strategy, because the meaning of the simplestrepresentation of a symbolic expression cannot be defined clearly. Different problems requiredifferent forms of the same mathematical expression. You can use the general simplificationfunctions simplify and Simplify to check if they give a simpler form of the expression you use.

Transforming and Simplifying Trigonometric ExpressionsYou also can transform and simplify trigonometric expressions. The functions for manipulatingtrigonometric expressions are the same as for polynomial expressions. For example, to expand atrigonometric expression, use the expand command:

You can use the general simplification functions on trigonometric expressions:

Simplifying Particular Parts of ExpressionsYou can simplify the expression containing particular functions and not simplify any otherexpressions. For example, you can use the simplification command without options:

Page 33: 5. Symbolic Math Toolbox - kau

73

Or you can specify the target function of simplification and leave all other functions in the sameform:

Exercise

1. Evaluate

a. ∫ tanh/b.

c. ∫ √ d. ln(sec ) + cos√e. lim→ sin( ) f. lim→ ( ) ( )

2. Factor −3. Expand ( − 2)( − 3)4. Collect ( + )( + 2)5. Transforms − 6 + 11 − 6 into its Horner, or nested, representation.

6. For this system of two equations= cos , + − = 2,a. Plot the two equations, in two dimension, and observe two intersections that occur

near = 2 and = −1.b. Substitute from the first equation. into the second getting equation. In only x

Solve this equation for the values then find .

7. Find a root for the equation ln( − 1) + cos( − 1) = 0.8. Find the value of x that produces the point on the graph of y = 1/ x that is closest to

(2, 1).

9. Find the maximum of the function − 2 − 5 on the interval (−2,0).10. Let ( ) = , and ( ) = ∫ ( ) .

a. find the maximum and minimum of the second derivative of .

Page 34: 5. Symbolic Math Toolbox - kau

74

b. Plotc. lim→ ( )d. lim→ ( )

11. Read the help pages for the commands solve and ezplot. Let be the cubic( ) = + 6 + 9 + 2. Solve the equation ( ) = 0, and plot a graph of . Itshould be clear from the graph that the cubic has three real roots.

12. Use hep to find Taylor and Maclaurin series of order 5 for ln about = 1 and =0.13. Find the th Taylor polynomial centred at .

a. ( ) = / , = 4, = 0b. ( ) = 1/ , = 5, = 1c. ( ) = cos , = 3, =

14. Solve the IVP

a. = + + , (0) = 1 b. = , (0) = 215. Solve The following IVP+ 2 − − 2 = , (0) = 1, (0) = 2, (0) = 0.16. Solve the following system of ODES( ) = ( ) − ( ) + 1, (0) = 1,( ) = 3 , (0) = 1,( ) = ( ) + , (0) = −1.17. Use MuPAD notebook to solve all above exercises.