Maple: Solving Equations, Inequalities, Differentiation, and Limits, Study notes of Computer Science

Examples of using maple to solve systems of equations and inequalities, handle symbolic differentiation and evaluation of derivatives, and compute limits. It covers various techniques and tools for solving equations and calculating derivatives and limits.

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-74z
koofers-user-74z 🇺🇸

10 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
(1.1.3)(1.1.3)
(1.1.2)(1.1.2)
Chapter 9 More Mathematical computation
Section 9.1 Solving multiple equations and/or inequalities
Maple can solve systems of equations by giving solve a set of equations and a set of variables.
One can also enter inequalities instead of equations.
fsolve can handle systems of equations, but it does not handle inequalities.
Maple's "firmest" solution power comes from the exact solution of systems of linear equations.
The solution, if one exists, will be described in full,. If NULL is returned as the answer from
solve, it means that no solution exists.
Exact solution of inequalities may not be successful even if there is a solution. That is, if Maple
returns NULL in this situation, it does not necessarily mean that there is no solution, it may only
mean that Maple couldn't find any solutions.
If Maple finds an approximate solution to a system of equations, it does not necessarily mean that
a solution exists, just that the approximation technique (which are not infallible) thinks that it's
found one. Even if a solution exists to a system, an approximate solution may or may not be close
to the exact solution, due to accumulated rounding errors resulting from the use of floating point
(limited precision) numbers. This limitation exists in most systems (e.g. Matlab, Fortran or C++)
packages that use floating point arithmetic to solve systems of equations.
Example 8.1.1 solve and fsolve with systems
of equalities or inequalities
Example Commentary
solve 3$xCy= 5, 4
K
y= 7$x,x,y
x=
K
1
4,y=23
4
fsolve 3$xCy= 5, 4
K
y= 7$x,x,y
x=
K
0.2500000000, y= 5.750000000
solve x Cy= 3, xCy= 4 , x,y
solve f x =y,f y =x,x,y
x=RootOf
K
f f _Z C_Z ,y
=f RootOf
K
f f _Z C_Z
To solve a system of equations, give solve a set
of equations and a set of variables. The result
can be a set of equations.
solve returns NULL if it can't any solution.
Maple may return expressions involving more
advanced mathematics in some cases. If you
get back an answer that you don't comprehend,
it's a sign that either you've asked the wrong
problem by mistake, or that you're going to
have to get more help in understanding the
situation.
solve π$r
2
= 10, rO0 , rWe are interested in finding the radius of a
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Maple: Solving Equations, Inequalities, Differentiation, and Limits and more Study notes Computer Science in PDF only on Docsity!

Chapter 9 More Mathematical computation

Section 9.1 Solving multiple equations and/or inequalities

Maple can solve systems of equations by giving solve a set of equations and a set of variables. One can also enter inequalities instead of equations.

fsolve can handle systems of equations, but it does not handle inequalities.

Maple's "firmest" solution power comes from the exact solution of systems of linear equations. The solution, if one exists, will be described in full,. If NULL is returned as the answer from solve, it means that no solution exists.

Exact solution of inequalities may not be successful even if there is a solution. That is, if Maple returns NULL in this situation, it does not necessarily mean that there is no solution, it may only mean that Maple couldn't find any solutions.

If Maple finds an approximate solution to a system of equations, it does not necessarily mean that a solution exists, just that the approximation technique (which are not infallible) thinks that it's found one. Even if a solution exists to a system, an approximate solution may or may not be close to the exact solution, due to accumulated rounding errors resulting from the use of floating point (limited precision) numbers. This limitation exists in most systems (e.g. Matlab, Fortran or C++) packages that use floating point arithmetic to solve systems of equations.

Example 8.1.1 solve and fsolve with systems of equalities or inequalities

Example Commentary

solve 3 $ x C y = 5, 4 K y = 7$ x , x , y

x = K

, y =

fsolve 3 $ x C y = 5, 4 K y = 7$ x , x , y x = K0.2500000000, y = 5. solve x C y = 3, x C y = 4 , x , y

solve f x = y , f y = x , x , y x = RootOf K _f f Z C _Z , y = f RootOf K _f f Z C _Z

To solve a system of equations, give solve a set of equations and a set of variables. The result can be a set of equations.

solve returns NULL if it can't any solution.

Maple may return expressions involving more advanced mathematics in some cases. If you get back an answer that you don't comprehend, it's a sign that either you've asked the wrong problem by mistake, or that you're going to have to get more help in understanding the situation.

solve π$ r^2 = 10, r O 0 , r We are interested in finding the radius of a

r =

π

eval 2 $π$ r , (1.1.4)

2 π 10 at 5 digits

circle whose area is 10. In order to discard negative roots of the quadratic equation, we put in the additional inequality that r is positive. We get a set back as the answer.

We can use the result from solve as is, to figure out the circumference of the specified circle, both exactly, and as a five digit approximation.

solve x C y O 5, x K y! 3 , x , y

x % 4, K x C 5! y , 4! x , x K 3 ! y

fsolve x C y O 5, x K y! 3 , x , y

Error, Got internal error in

Typesetting:-Parse :

"'_Inert_DELAYLESSTHAN' is not a

valid inert form"

fsolve x Cy O 5, x Ky! 3 , x, y

solve can handle systems of inequalities. Here, the solution is described as a sequence of two different sets.

fsolve can't handle inequalities. Inequalities aren't that easily handled through approximate calculations, because it's not uncommon for rounding error to seriously affect the accuracy of the results.

solve 3 $ x C y = 5, 4 K y = 2$ x , x , y

x = 1, y = 2

fsolve 3 $ x C y = 5, 4 K y = 2$ x , x , y

Error, (in fsolve) invalid

arguments

Lists of equations and variables sometimes work, too. But then the result comes back in a different form: a list of solutions. Each solution is expressed as a list of equations for the variables involved in the system.

fsolve doesn't accept lists of unknowns, at least in Maple 12. There's no strong reason why the design has to be this way, but that's Maple 12's fsolve rejects parameters of type list.

solve x^2 C 2 $ x K5 = 0, x O 0 , x

x = K 1 C 6

fsolve x^2 C 2 $ x K5 = 0, x O 0 , x

Error, (in fsolve) expecting an

equation or set or list of

equations, but received

inequality {x^2+2*x-5 = 0, 0 <

x}

Sometimes you can give extra constraints on the solution through the use of inequalities

fsolve doesn't work with inequalities

2 sin ω t C 5 cos ω t C 5 ω

diff posExpr , t , t

2 cos ω t C 5

2 ω

2 K2 sin ω t

C 5

2 ω

2

diff expr , t

0

simplify (1.2.5)

2 ω

2 2 cos ω t C 5

2 K 1

eval (1.2.2) , x = 3

4

eval (1.2.7) , t = 47.

2 ω

2 2 cos 47.0 ω C 5

2 K 1

respect to t.

Find the second derivative of the expression with respect to t. The result is the same as if we had taken the derivative of 1.2.4.

diff's second argument must be the variable of differentiation. Note that if the variable doesn't occur in the expression, the derivative (according to the mathematical definition) is zero. If you are surprised by getting a zero derivative, check that you are using the correct variable to differentiate with respect to.

simplify can reduce the size of the expression, although factor or expand sometimes work better. Sometimes additional trigonometric identities need to be applied, through simplify(. ... , trig).

This is a way to compute d d x

x^2 K 2 $ x C 5 x = 3

This is a way to compute d^2 d t^2

sin ω t C 5

2

t = 47

The result of

evaluation does not have to be a number even if a numeric value is being supplied for one of the variables in the expression being evaluated.

Example 8.2.2 Plotting a function and its derivative together

Example Commentary

f d a , b / sin a Ccos b

a , b /sin a Ccos b

g d α / f

α 2

α 3

α/ f

α,

α

plot g t , t = 0 ..

We're already used to functions that take one or two arguments. Note that unlike mathematical convention, in programming variable names often do have names that are more than one letter long. This is to increase intelligibility to readers looking at the programming. Although it seems minor, ease of comprehension can play an significant role

t

K 2

K 1

fderiv d diff g α , α 1 2

cos

α K

sin

α

plot g α , fderiv , α = 0 ..

K 2

K 1

in the cost of developing and using software, so is an important engineering concern.

In this example, we plot a "strange" function built out of trigonometric parts, and plot it and its derivative. Since g is a function g(t) will evaluate to the expression. Thus the plotting variable should be t rather than α or some other variable.

The value of fderiv is an expression involving alpha.

We plot two expressions involving the variable alpha on the same plot. The use of a set ({ } ) as a first argument to plot to do multiple plots was first explained in section 6.3.

We need to use α as the plotting variable here since the value of fderiv is an expression involving α.

Section 9.3 Calculus: limits

You can use the clickable interface to compute limits by selecting the appropriate item from the Expression palette and then filling in the template as needed. Maple uses calculus techniques (e.g. l'Hôpital's Rule) to compute limits symbolically.

Example 9.3.1 Clickable interface version of limits

Example Commentary

lim x / 3

x K 3 2 N

lim x /KN

sin x x 0

lim t / 0

t undefined

lim t / 0 K

t K N

x^ lim / a

sin x x sin a a

The result of limit can be an expression (possibly involving positive or negative infinity) as well as the symbol undefined.

Even though the limit exists as t approaches from the right or left, they do not agree, so there is no "two-sided" limit.

To take a one-sided limit, add a "+" or "-" superscript to the limit point.

Note that the value returned as the limit for x= a, while true for most values of a , is not really valid for a=0.

The textual version of taking limits involves the limit function. limit takes at least two arguments. The first argument is the expression that you wish to take the limit of. The second argument is an equation indicating the limit variable and the limiting value. If you supply a third argument, it indicates whether a "right sided", "left sided" limit is desired instead of a two-sided limit.

Example 9.3.1 Textual version of limits

Example Commentary

limit 1 / x K 3 ^2, x = 3 N

limit sin x / x , x = N 0

limit 1 / t , t = 0, left K N

The first argument is the expression that you wish to take the limit of. The second argument is an equation indicating the limit variable and the limiting value.

You can use "infinity" or "-infinity" as the way of specifying ∞ or -∞ textually without use of the palette.

The third optional third argument to limit can specify a one sided limit. This is the textual

diff zexpr , y , x

K

sin y x

x $cos y

differentiate w.r.t. x 1 2

cos y x differentiate w.r.t. y K

sin y x

expression. Since the expression describes a continuous function of x and y , we get the same results as when we took the partial derivatives in the reverse order.

This is one situation where the textual interface gives the answer faster than the clickable interface. However, the clickable interface does display the intermediate results.

Given that x^3 C y^2 $ x K3 = 0, find

dy dx

implicitdiff x^3 C y^2 $ x K3 = 0, y , x

K

3 x^2 C y^2 y x

Given y $ ex $sin 3$ z = 3$ z , compute

v v x

z and v v y

z through implicit differentiation.

y $ ex $sin 3$ z = 3$ z

implicit differentiation

K

ln e e x

y $ ex $sin 3$ z = 3$ z

implicit differentiation K

e y x

This is Example 3 from section 14.5 of Anton, Calculus 8th edition.

Not surprisingly, Maple has a built-in command to do implicit differentiation. You can read more about it by typing "implicit differentiation" or "implicitdiff" into Maple's on-line help.

This is problem 43 in section 14.5 of Anton.

The clickable interface lets us select what the dependent variable is, and which is the variable of differentiation. Here, we pick "z" and 'x".

Although the output does not show it, we picked "z" and "y" here. Using the textual version implicitdiff would clearly show that different things are being computed.

Find the directional derivative of

f x , y = x $ y $e y^ at P 1, 1 in the direction of the negative y -axis.

with Student MultivariateCalculus

ApproximateInt , ApproximateIntTutor , CenterOfMass , ChangeOfVariables , CrossSection , CrossSectionTutor , Del , DirectionalDerivative , DirectionalDerivativeTutor ,

This is problem 25 from section 14.6 of Alton, Calculus 8th edition.

This loads all the functions from the Student [MultivariableCalculus} package. You can read more about this by entering "directional derivative" into Maple's on-line help.

FunctionAverage , Gradient , GradientTutor , Jacobian , LagrangeMultipliers , MultiInt , Nabla , Revert , SecondDerivativeTest , SurfaceArea , TaylorApproximation , TaylorApproximationTutor

DirectionalDerivative x $ y $e y , x , y = 1, 1 , 0,K 1

K

e

With the package loaded in, we can use the DirectionalDerivative function. The second argument is the point where we are evaluating the derivative, and the third argument describes the direction. We need to express this direction as a "unit vector".

This 3-d graph describing the situation with the directional derivative of 1.4.8 was produced by selecting Tools->Tutors->Multivariable Calculus -> Directional Derivative in the Maple interface and supplying the information (in textual form) described in that problem.

Section 9.5 For the advanced: integration

This section can be skipped until you need to do integrals.

Maple can perform symbolic integrals about as well as most people can. Because it is indefatigably rigorous about doing algebra, it can often get an answer more reliably, at least for longer problems. We will discuss symbolic integration further in a few chapters, but will preview it here. You can read more about this by entering "integration" into Maple's on-line help. Next term we will work more with symbolic integration, but since we are introducing calculus in this chapter, we wanted to give a more complete picture of Maple's calculus capabilities.

Example 9.5.1 Symbolic Integration

sin

x 2

$ x^2 d x

0

π 4 ln x $ x d x

K

π

2 ln 2 C

π

2 ln π

Maple can handle do indefinite and definite integration symbolically using the integration item from the Expression palette.

Example 9.5.2 Numerical integration

0

π 4 tan x^2 d x

0

1 4 π tan x^2 d x

0

π 4 tan x^2 d x

at 10 digits

When Maple returns the same thing as what you entered, it means that it couldn't determine a simple expression for the integral.

However, it can determine that the area underneath the curve of tan x^2 between 0 and

evalf int tan x^2 , x = 0 ..

π 4

π 4

is approximately 0.1712. To do this, we

used the "approximate to 10 digits" item of the clickable interface.

This uses the textual version of the integration and numerical approximation commands to approximate the area to 20 digits.

Section 9.X Chapter summary

Example 9.1.1 Solving equations

Example Commentary

solve 3 $ x C y = 5, 4 K y = 7$ x , x , y

x = K

, y =

fsolve 3 $ x C y = 5, 4 K y = 7$ x , x , y x = K0.2500000000, y = 5.750000000 (1.6.2) solve x C y = 3, x C y = 4 , x , y

solve f x = y , f y = x , x , y x = RootOf K _f f Z C _Z , y = f RootOf K _f f Z C _Z

To solve a system of equations, give solve a set of equations and a set of variables. The result can be a set of equations.

solve returns NULL if it can't any solution.

Maple may return expressions involving more advanced mathematics in some cases. If you get back an answer that you don't comprehend, it's a sign that either you've asked the wrong problem by mistake, or that you're going to have to get more help in understanding the situation.

Example 9.1.2 Use of assuming

solve x^2 = 5$α, x O 0 , x

x = 5 α 0! 5 α

x = K 5 α 5 α! 0

otherwise

solve x^2 = 5$α, x O 0 , x assuming α O 0

We get a piecewise expression as the result of solve, if you don't put any restrictions on alpha.

Adding information that alpha is positive removes some of the pieces, and greatly

d^2 d t^2

sin ω t C 5

2

t = 47

The result of

evaluation does not have to be a number even if a numeric value is being supplied for one of the variables in the expression being evaluated.

Example 9.3.1 Clickable interface version of limits

Example Commentary

lim x / 3

x K 3 2 N (1.6.15)

lim x /KN

sin x x 0 (1.6.16)

lim t / 0

t undefined (1.6.17)

lim t / 0 K

t K N (1.6.18)

x^ lim / a

sin x x sin a a

The result of limit can be an expression (possibly involving positive or negative infinity) as well as the symbol undefined.

Even though the limit exists as t approaches from the right or left, they do not agree, so there is no "two-sided" limit.

To take a one-sided limit, add a "+" or "-" superscript to the limit point.

Note that the value returned as the limit for x= a, while true for most values of a , is not really valid for a=0.

Example 9.3.1 Textual version of limits

Example Commentary

limit 1 / x K 3 ^2, x = 3

N

limit sin x / x , x = N

The first argument is the expression that you wish to take the limit of. The second argument is an equation indicating the limit variable and the limiting value.

You can use "infinity" or "-infinity" as the way of specifying ∞ or -∞ textually without use of

limit 1 / t , t = 0, left K N

limit 1 / t , t = 0, right N

the palette.

The third optional third argument to limit can specify a one sided limit. This is the textual

way of specifying lim t / 0 K

t

. There is no simple

way of specifying this

This is the textual way of specifying lim t / 0 C

t