• Aucun résultat trouvé

Solving Transcendental Equations

Dans le document Second Edition (Page 192-200)

Three-Dimensional Graphics

6.2 Solving Transcendental Equations

A transcendental equation is one that is non-algebraic. Although Solve and NSolve can be used in a limited way to handle simple trigonometric or exponential equations, it was not designed to handle equa-tions involving more complicated transcendental funcequa-tions. The Mathematica command FindRoot is better equipped to handle these.

FindRoot uses iterative methods to find solutions. A starting value, sometimes called the initial guess, must be specified. For best results, the initial guess should be as close to the desired root as possible.

FindRoot[lhs  rhs, {x, x0}] solves the equation lhs = rhs using Newton’s method with starting value x0.

FindRoot[lhs  rhs,{x, {x0, x1}] solves the equation lhs = rhs using (a variation of) the secant method1 with starting values x0 and x1.

FindRoot[lhs  rhs,{x, x0, xmin, xmax}] attempts to solve the equation, but stops if the iteration goes outside the interval [xmin, xmax].

If a function is specified in place of the equation lhs  rhs, FindRoot will compute a zero of the function. A zero of f is a number x such that f(x) = 0.

EXAMPLE 16 The equation sin x = x2 – 1 has two solutions.

Plot[{Sin[x], x2 – 1}, {x, – o, o}]

–3 –2 –1 1 2 3

–2 –1 1 2 3 4

The graph of the two functions shows that they intersect near x = –1 and x = 1.

FindRoot[Sin[x]  x2 – 1, {x, –1}]

{x → –0.636733}

FindRoot[Sin[x]  x2 – 1, {x, 1}]

{x → 1.40962}

1Newton’s method uses the x-intercept of the tangent line to improve the accuracy of the initial guess. Thus, Newton’s method fails if the derivative of the function cannot be computed. The secant method, although a bit slower, uses the values of the function at two distinct points, computing the x-intercept of the secant line.

By default, 100 iterations are performed before FindRoot is aborted. The number of iterations per-formed before quitting is controlled by the option MaxIterations.

MaxIterations ã n instructs Mathematica to use a maximum of n iterations in the iterative process before aborting.

EXAMPLE 17 The equation e2x – 2ex+ 1 = 0 has x = 0 as its only root. However, because its multiplicity is 2, Newton’s method converges very slowly.

FindRoot[Exp[2 x] – 2 Exp[x] + 1  0,{x, 100}]

FindRoot õ cvmit : Failed to converge to the requested accuracy or precision within 100 iterations.  {x → 50.}

FindRoot[Exp[2 x] – 2 Exp[x] + 1  0, {x, 100}, MaxIterations ã 300]

{x → 4.54676 × 10–9}

FindRoot attempts to find real solutions. However, if a complex initial value is specified, or if the equation contains complex numbers, complex solutions will be sought. The equation in the next example has no real solutions.

EXAMPLE 18

FindRoot[x2 + x + 1  0,{x, 2}] FindRoot õ lstol:

The line search decreased the step size to within tolerance specifi ed by AccuracyGoal and PrecisionGoal but was unable to fi nd a suffi cient decrease in the merit function. You may need more than

MachinePrecision digits of working precision to meet these tolerances.  {x → –0.500002}

FindRoot[x2 + x + 1  0,{x, I}]

{x → –0.5 + 0.866025}

FindRoot[x2 + x + 1  0,{x, –I}]

{x → –0.5 – 0.866025 }

There are three options that control the calculation in FindRoot and other numerical algorithms.

WorkingPrecision is an option that specifies how many digits of precision should be main-tained internally in computation. The default is WorkingPrecision ã 16.

AccuracyGoal is an option that specifies how many significant digits of accuracy are to be obtained.

The default is AccuracyGoal ã Automatic, which is half the value of WorkingPrecision.

AccuracyGoal effectively specifies the absolute error allowed in a numerical procedure.

PrecisionGoal is an option that specifies how many effective digits of precision should be sought in the final result. The default is PrecisionGoal ã Automatic, which is half the value of WorkingPrecision. PrecisionGoal effectively specifies the relative error allowed in a numeri-cal procedure.

EXAMPLE 19 We wish to obtain a 10-decimal place approximation to the solution of the equation cos 100 1

Mathematica’s defaults are insufficient to give the required accuracy. By increasing WorkingPrecision, we can obtain the desired result.

FindRoot Cos 100 x

x

x + 1, {x, 5000}, Wo

⎡⎣⎢ ⎤

⎦⎥ rrkingPrecision28

⎣⎢

⎦⎥

{x → 5000.83319115955609589817}

Since AccuracyGoal is, by default, half the value of WorkingPrecision, only the first 14 significant digits can be trusted. Thus, x ≈ 5000.8331911595 (accurate to ten decimal places).

EvaluationMonitor can be used to show intermediate calculations to be performed and dis-played. The format is EvaluationMonitor  expression.

The symbol  can be found on the Basic Math Input palette or can be created by typing :>. This sym-bol is used instead of → to avoid expression being immediately evaluated. This technique is illustrated in the next two examples.

EXAMPLE 20 To see how quickly the sequence of approximations converges when we solve the equation e−x= x, we can use EvaluationMonitor to print the results of intermediate calculations.

n = -1;

EXAMPLE 21 To obtain a comparison between Newton’s method and the secant method, we can ask EvaluationMonitor to print the number of iterations needed to converge to 100 significant digits.

Newton’s Method n = 0;

FindRoot[Exp[–x]  x,{x, 1}, WorkingPrecision ã 100, AccuracyGoal ã 100, EvaluationMonitor  n++]

Print[n," iterations"]

{x → 0.5671432904097838729999686622103555497538157871865125081351310792230 457930866845666932194469617522946}

8 iterations Secant Method n = 0;

FindRoot[Exp[–x]  x,{x, 1, 2},WorkingPrecision ã 100, AccuracyGoal ã 100, EvaluationMonitor  n++]

Print[n," iterations"]

{x → 0.5671432904097838729999686622103555497538157871865125081351310792230 457930866845666932194469617522946}

24 iterations

If the equation to be solved has a root of multiplicity 2 or greater, Newton’s method may converge slowly or not at all. In this situation, convergence can sometimes be improved by a judicious choice of DampingFactor.

DampingFactor ã factor is an option that controls the behavior of convergence in Newton’s method. The size of each step taken in Newton’s method is multiplied by the value of factor. The default is DampingFactor ã 1.

EXAMPLE 22

FindRoot can also be used to determine the solution of simultaneous equations.

FindRoot[equations,{var1, a1},{var2, a2},...] attempts to solve equations using initial values a1, a2, . . . for var1, var2, . . . , respectively. The equations are enclosed in a list:

{equation1, equation2,...}. Alternatively, the equations may be separated by && (logical and).

Convergence of Newton’s method for functions of several variables is much more sensitive to choice of starting values than its counterpart for single variables. Therefore, a good graph of the functions involved is quite helpful.

EXAMPLE 23 Solve the system of equations e y

x y First we graph the equations.

ContourPlot[{Exp[x] + Log[y]  2, Sin[x] + Cos[y] 1}, {x, 0, 2}, {y, 0, 3},

It appears that there is only one solution. We use x = 1, y = 1 for our initial guess.

FindRoot[{Exp[x] + Log[y]  2, Sin[x] + Cos[y]  1}, {x, 1}, {y, 1}]

{x → 0.624295, y → 1.14233}

If the function in an equation is such that its evaluation is costly, particularly if high precision is desired, there is another procedure that may be beneficial.

InterpolateRoot[lhs  rhs, {x, a, b}] solves the equation lhs = rhs using initial values a and b.

Whereas FindRoot uses linear functions (straight lines) to approximate the root of the equation, InterpolateRoot uses polynomials of degree 3 or less. The result is that higher precision can be achieved with fewer function evaluations. InterpolateRoot is contained within the package FunctionApproximations` and must be loaded prior to use.

As with FindRoot, the equation may be replaced by a function, in which case its zero is computed.

EXAMPLE 24 This example computes the zero (between 2 and 3) of the Bessel function2 J0(x), using a working precision of 1000 significant digits. For comparison purposes, the Mathematica function Timing is used. The actual numerical approximation is suppressed to save space. As a result, the value Null is returned. Delete the semicolon and run the command to see the actual result of the calculation.

FindRoot[BesselJ[0, x], {x, 2}, WorkingPrecision ã 1000]; //Timing

{0.219, Null}

FunctionApproximations`

InterpolateRoot[BesselJ[0, x], {x, 2, 3}, WorkingPrecision ã 1000]; //Timing

{0.046,Null}

SOLVED PROBLEMS

6.12 Solve the equation 5cosx= −4 x3. Make sure you find all solutions.

SOLUTION

Since 5cosx= −4 x3 if and only if 5cosx− +4 x3=0, we introduce the function f x( )=5cosx− +4 x3 and look for x-intercepts. (Although we could look for the intersection of two curves, it is easier to approxi-mate where points intercept an axis.)

f[x_] = 5 Cos [x] – 4 + x3; Plot[f[x], {x, –1, 2}]

–1.0 –0.5 0.5 1.0 1.5 2.0

–2 –1 1 2

2J0(x) is a solution of the differential equation x2 y" + x y' + x2 y = 0.

It appears that there are three solutions, near –0.5, 0.8, and 1.6.

FindRoot[f[x], {x, –0.5}]

{x → –0.576574}

FindRoot[f[x], {x, 0.8}]

{x → 0.797323}

FindRoot[f[x], {x, 1.6}]

{x → 1.61805}

6.13 Find a solution of the equation sin x = 2. (This problem may be omitted by those unfamiliar with functions of a complex variable.)

SOLUTION

Since –1 ≤ sin x ≤ 1 for all real x, this problem has no real solutions. We can force FindRoot to search for a complex solution by using a complex initial guess.

FindRoot[Sin[x]  2,{x, I}]

{x → 1.5708 + 1.31696 }

6.14 Find a 20 significant digit approximation to the equation x +| sin (x − 1) |= 5.

SOLUTION

First we plot the function f(x) = x + | sin (x – 1) | – 5.

f[x_] = x + Abs[Sin[x – 1]] – 5;

Plot[f[x], {x, –10, 10}]

–10 –5 5 10

–10 –5 5

It appears that the only solution lies between 4 and 5.

FindRoot[f[x],{x,5}, AccuracyGoal ã 20, WorkingPrecision ã 25]

{x → 4.577640011987577295259374}

To 20 significant digits, the solution is 4.5776400119875772953 (last digit rounded up).

6.15 Find the points of intersection of the parabola y = x2+ x – 10 with the circle x2 + y2= 25.

SOLUTION

First, plot the two graphs.

g1 = Graphics[Circle[{0, 0}, 5], Axes ã True];

g2 = Plot[x2 + x – 10, {x, –5, 5}];

Show[g1, g2, AspectRatio ã Automatic, PlotRange ã {–10, 10}]

–4 –2 2 4

–10 –5 5 10

The parabola y = x2+ x + 1 intersects the circle x2+ y2= 25 at four points. Now solve for the intersection points.

Because of the complicated structure of the exact solution, we obtain a numerical approximation.

NSolve[y  x2 + x – 10 && x2 + y2  25]

{{y → –4.63752, x → 1.86907}, {y → 2.83654, x → –4.11753},

{y → –4., x → –3.}, {y → 3.80098, x → 3.24846}}

6.16 Find the points of intersection of the limacon r= −5 4 cosθ and the parabola y = x2. SOLUTION

First we plot both curves on the same set of axes.

limacon = PolarPlot[5 – 4 Cos[t], {t, 0, 2 o}];

parabola = Plot[x2, {x, –3, 3}];

Show[limacon, parabola, PlotRange ã All]

–8 –6 –4 –2 2

–6 –4 –2 2 4 6 8

We convert the equation of the limacon to rectangular coordinates:

The first intersection point appears to be near (2, 2):

FindRoot[{y x2,x2 +y2 5 x2+y2 – 4x},{x, 2 ,} {yy, 2 ]} {x → 1.53711, y → 2.3627}

The second point lies near (–3, 6):

FindRoot[{y x2,x2 +y2 5 x2+y2 – 4x},{x, –3 ,} {yy, 6 ]}

The graph shows three points of intersection that appear to be near (4, 6), (–8, 4), and (–9, –2). To convert the polar equation to rectangular, we use the transformations r= x2+y2 and θ =tan ( / )1 y x . However,

{x → 3.93476, y → 6.1289}

{x → –8.04703, y → 3.95785}

{x → –9.38786, y → –2.29668}

6.18 Find a solution of the system of equations x y z

x y z

e y

z

x

+ + =

+ + =

+ + =

6 1

1 5

sin cos tan

near the point (1, 2, 3).

SOLUTION

FindRoot[ x + y + z 6, Sin[x] + Cos[y] + Tan[z] 1, Ex

{ p

p[x] + Sqrt[y] + 1/z 5}, x, 1 , y, 2 , z, 3 ]{ } { } { } {x → 1.23382, y → 1.5696, z → 3.19658}

Dans le document Second Edition (Page 192-200)