• Aucun résultat trouvé

Solving Equations and Inequalities with Reduce

Dans le document This page intentionally left blank (Page 171-176)

Graphics Primitives

2. Factor the following expressions and explain the differences in the resulting factorizations

4.3 Solving Equations and Inequalities with Reduce

The Reduce command provides another means for solving equations. The input syntax is like that used for Solve and NSolve, but the output is expressed in a very different way.

In[1]:= Reduce$x2m100, x(

Out[1]= xm 10««xm10

The values of x are given as equations rather than as replacement rules. The double vertical bar ||

stands for the word “or.” So the output here reads, “Either x is equal to 10, or x is equal to 10.”

The reason for the different output format is that Reduce is designed to consider special conditions on all parameters appearing in an equation, whereas Solve will ignore conditions on any parameter whose solution is not explicitly being sought. For example, the solution below only makes sense

Reduce takes into account the possibility that a could be zero:

Another point where Reduce and Solve differ arises when an equation has an infinite number of discrete solutions, such as cos+x/ 0. We all know that the cosine function is equal to zero when its argument is of the form 2kS ” S

2, where k is any integer. Solve will not attempt to display them all.

Rather it will send a warning message suggesting that you try Reduce instead:

In[4]:= Solve#Cos#x'm0, x'

Solve::ifun : Inverse functions are being used by Solve, so some

solutions may not be found; use Reduce for complete solution information.j

Out[4]= x‘ S

The output says precisely what it should, but we first need to understand the syntax. We said earlier that the solution set is comprised of all numbers 2kS ”S

2, where k is an integer. Reduce uses the generic name C[1] (rather than k) when it has to introduce a constant. It’s a rather unsightly name, but something like this is necessary. For instance, in an output where fifty such constants are needed, they will be called C[1], C[2], and so on; the numerical piece guarantees that the notation is capable of handling arbitrarily many such constants. Next, we see the symbol ±. This is standard mathematical notation; it reads “is an element of.” Hence the output above says: “C#1' is an element of the set of integers, and x 2SC#1'”S2.” The output concisely describes all of the roots of the cosine function.

Reduce is also effective at expressing inequalities:

In[6]:= Reduce$x21!0, x(

Out[6]= x 1««x!1

If you were asked to describe the natural domain (among all real numbers) for the function

f+x/ x27x3 and unhelpful. A careful inspection shows that Root simply writes the polynomial in the form of a pure function (see Section 8.4 page 403 for a discussion of these) for its first argument. The second argument gives an index number for the root in question. Essentially, Root objects are a means of cataloging roots of polynomials. What is important for us here is the fact that using N, we can numerically approximate any Root object with ease:

In[8]:= Reduce$x34x22x1!0, x( ssN

Out[8]= x!3.51155

If an exact answer is preferred, one can specify for cubic or quartic polynomials that an explicit expression in radicals be given (instead of Root objects); just set the option Cubics (or Quartics in the case of a polynomial of degree 4) to True:

In[9]:= Reduce$x34x22x1!0, x, Cubics‘True(

A plot is consistent with the result that x!3.51:

In[10]:= Plot% x27x3 from the field of mathematical logic. In this notation, the symbol  means “and” and the symbol Á means “or.” If you have experience with this notation, you may find it easier to read. A constant is also represented as c1 rather than C#1'. In all, it reads a bit more nicely. To get your output in this form, simply apply TraditionalForm to the output of Reduce.

4.3 Solving Equations and Inequalities with Reduce 159

In[11]:= Reduce#Cos#x'm0, x' ssTraditionalForm

Out[11]//TraditionalForm=

c1±=Ð xn2Sc1S

xn2Sc1S 2

Here is a more complicated example in which there are two constants. The symbol = denotes the set of integers, as is traditional in mathematical notation.

In[12]:= Reduce#Sin#1Cos#x''m1, x' ssTraditionalForm

Out[12]//TraditionalForm=

+c1«c2/±=Ð xn2Sc2cos1 1

2+4Sc1 S 2/ Îxncos1 1

2+4Sc1 S 2/ 2Sc2 While the output for Reduce reads very nicely, it is not obvious how one could work programmati-cally with it to perform some follow-up work. It is certainly possible to copy and paste portions of the output, but there are other ways. First note that just as you can extract parts from a List, you can extract parts from a logical expression like the one above:

In[13]:= Reduce#Sin#1 Cos#x'' 1, x'317

Out[13]= +C#1' «C#2'/±Integers

In[14]:= ans Reduce#Sin#1 Cos#x'' 1, x'327

Out[14]= xm ArcCos%1

2+2 S 4SC#1'/)2SC#2' ««xmArcCos%1

2+2 S 4SC#1'/)2SC#2' One can take this second part (or any other such logical combination of equations) and use ToRules to turn it into a list of replacement rules, suitable as input to other commands:

In[15]:= ToRules#ans'

Out[15]= x‘ ArcCos%1

2+2 S 4SC#1'/)2SC#2'!, x‘ArcCos%1

2+2 S 4SC#1'/)2SC#2'!!

Finally, one can replace the constants by numerical values, and hence obtain a usable list of replacement rules. Flatten is applied to this list to remove extra curly brackets.

In[16]:= rules Flatten#Table#ToRules#ans' s.C#1'‘0, C#2'‘k,k,1, 1', 1' f+x/ 1 shown as large points via the Epilog:

In[17]:= Plot$Sin#1 Cos#x'',x,10, 10, Epilog‘PointSize#.02', Point#x, 1' s. rules(

Out[17]=

As with Solve and NSolve, it may be the case that complex numbers are generated by Reduce.

In[18]:= Reduce$x3x2m0, x, Cubics‘True(

In the next section we discuss a means for dispensing with non-real output.

4.3 Solving Equations and Inequalities with Reduce 161

Exercises 4.3

1. Find the largest possible domain in the real numbers for the function f+x/ x35x24x5

x22x3

. Make a plot of fover a valid domain in the positive real numbers, along with the function

x48x320x234x58 . What do you notice?

2. Reduce can be used to solve systems of equations. A system of equations is a collection of several equations, each in several variables. A solution to such a system is a set of values for the variables for which all the equations are satisfied.

a. A system of equations can be entered in several ways. One can either type a list of equations, or an equation of lists like the input below. Type and enter this input.

Reduce$Cos$y(Cos$x Cos$y((,x Cos$x Cos$y((Sin$y( m0, 0,x, y , Reals(

b. The output is a bit intimidating at first. This is unavoidable for the simple reason that the solution set happens to be rather complex. If we regard a particular solution ,x0,y00 as a point in the x y plane, then this output is comprised of both discrete points and entire curves in the plane. Read the output carefully and identify the discrete points. ListPlot them in the plane.

c. Use ContourPlot to sketch the solutions of both equations.

3. We can also use Reduce to solve a single equation with more than one variable. Use Reduce to find the set of points in the plane that are solutions of 8x y2

,1y202 4x

1y2 and then use ContourPlot to graph the set of solutions.

Dans le document This page intentionally left blank (Page 171-176)