• Aucun résultat trouvé

Solving General Equations

Dans le document This page intentionally left blank (Page 197-200)

Manipulating Trigonometric Expressions

4.7 Solving General Equations

The Solve and NSolve commands are built for polynomials. They will also work for equations involving rational functions, and they will sometimes work with equations involving other types of functions. Reduce is even more inclusive, and can sometimes be used to describe solutions to equations when Solve fails. These are the commands to start with when you need to solve an equation. However, there are still a few things you can do if you don’t get the answer you desire.

Often Solve and NSolvecan be effectively used to solve equations involving powers that are rational numbers. For instance, since raising a quantity to the power 1

2 is the same as taking its square root, equations involving square roots fall into this category:

In[1]:= Solve% 1xx2 m2, x) ssGrid inside a logarithm or as an exponent:

In[3]:= xs. Solve$400Log#10, x'm2, x(

Out[3]= 101s200

In[4]:= xs. Solve$200+1r/xm300, 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]= does by default), or over the reals where we see that the solution above is indeed unique:

4.7 Solving General Equations 183

In[5]:= Reduce$200+1r/xm300, x(

Out[5]= C#1'±Integers && 1rœ0 && Log#1r'œ0 && xm

2Ç SC#1'Log%3

2) Log#1r'

In[6]:= Reduce$200+1r/xm300, x, Reals(

Out[6]= Log#1r'œ0 && r! 1 && xm Log%3

2) Log#1r'

On occasion these solving commands may come up empty, even when a unique solution exists:

In[7]:= Solve$Sin#x'm2x2, x(

Solve::tdep :

The equations appear to involve the variables to be solved for in an essentially nonalgebraic way.j

Out[7]= Solve$Sin#x'm2x2, x(

In[8]:= NSolve$Sin#x'm2x2, x(

Solve::tdep :

The equations appear to involve the variables to be solved for in an essentially nonalgebraic way.j

Out[8]= NSolve$Sin#x'm2x2, x(

In[9]:= Reduce$Sin#x'm2x2, x(

Reduce::nsmet : This system cannot be solved with the methods available to Reduce.j

Out[9]= Reduce$Sin#x'm2x2, x(

There are powerful numerical techniques for approximating solutions to equations such as this.

FindRoot is the final equation-solving command that we introduce. It is your last line of defense. It is very robust, and adapts its methodology according to the problem it is fed. It’s tenacious, but it’s also old-school. To use it you must give it a numerical value as a starting point. Like a hound dog it will hunt down a single solution from this starting point, iteratively using its current position to zero in on it. It is likely to hone in to the solution nearest the starting point, so choosing a good starting point is key. A plot is helpful in this endeavor. A simple approach is to Plot two functions, the left side and right side of the equation you wish to solve. The solutions are the x coordinates of the points where the curves intersect. For instance, here’s a view of the functions in the equation above:

In[10]:= Plot$Sin#x', 2x2 ,x,2, 2(

Out[10]=

2 1 1 2

2 1 1 2

We expect solutions near x 1.6 and x 1. To zero in on a solution once you know roughly where it is, use the FindRoot command like this:

In[11]:= FindRoot$Sin#x'm2x2,x,1.6(

Out[11]= x‘ 1.72847

In[12]:= FindRoot$Sin#x'm2x2,x, 1(

Out[12]= x‘1.06155

The first argument of the FindRoot command is an equation, the second is a list whose first mem-ber is the variable to be solved for, and whose second memmem-ber is a rough guess at the true root. To have all internal calculations performed with n-digit precision you can use the optional argument WorkingPrecision:

In[13]:= xs. FindRoot$Sin#x'm2x2,x, 1, WorkingPrecision‘400(

Out[13]= 1.06154977463138382560203340351989934205887417838924148608498893580932536g 58078013681605147722169795200205523517584438182489915752386795185105198g 01898497141789694624781317887368590739943328390244768652889979635131820g 54066331171612084604692146632416602626438286949734162187208102212531109g 55046026055069360793013098705252533458512558323397412062383035427145357g 98284624484729386618537019854165883676711994

This technique of first estimating a solution with a plot and then using FindRoot to zero in on it is very robust in that it will work on almost any equation you wish to solve (provided that a solution exists). It does have several drawbacks, however. First, it is a strictly numerical command; it cannot be used when there are more variables than there are equations. For instance, it won’t be able to solve xy 1 for x; the solution must a number (or a list of numbers if there are several equations).

Second, it may be tedious to find an appropriate domain for a plot, one in which a point of intersec-tion resides. Third, it is often difficult to discern whether or not other intersecintersec-tion points might be present to the left or right of those you have already found. And finally, for some equations the algorithm will fail altogether. For instance, FindRoot relies at times on a well-known algorithm, the Newton-Raphson method, to produce its solutions. It is also well known that this method doesn’t work for all combinations of equations and initial guesses, even when a unique solution exists:

4.7 Solving General Equations 185

In[14]:= FindRoot$200+1.05/xm300,x, 2700(

FindRoot::cvmit : Failed to converge to the requested accuracy or precision within 100 iterations.j

Out[14]= x‘650.407

The output here is not correct (so the warning message is welcome). You can usually avoid this sort of thing if you make a reasonable initial guess. This sort of problem is unlikely if you follow our advice and make a few plots first, using the plots to generate reasonable initial guesses for FindRoot.

In[15]:= Plot$200+1.05/x, 300 ,x, 0, 15(

Out[15]=

2 4 6 8 10 12 14

250 300 350 400

In[16]:= FindRoot$200+1.05/xm300,x, 8(

Out[16]= x‘8.31039

Let’s look at another example: solve the equation log+x/ x3x:

In[17]:= Solve$Log#x'mx3x, x(

Solve::tdep :

The equations appear to involve the variables to be solved for in an essentially nonalgebraic way.j

Out[17]= Solve$Log#x'm xx3, x(

In[18]:= NSolve$Log#x'mx3x, x(

Solve::tdep :

The equations appear to involve the variables to be solved for in an essentially nonalgebraic way.j

Out[18]= NSolve$Log#x'm xx3, x(

In[19]:= Reduce$Log#x'mx3x, x(

Reduce::nsmet : This system cannot be solved with the methods available to Reduce.j

Out[19]= Reduce$Log#x'm xx3, x(

Dans le document This page intentionally left blank (Page 197-200)