• Aucun résultat trouvé

Exact Solutions of Equations

Dans le document Getting Started (Page 94-103)

Two Words of Caution

2.4 Solving Equations

2.4.1 Exact Solutions of Equations

Mathematica can find exact solutions to many equations and systems of equations, including exact solutions to polynomial equations of degree four or less. Because a single equals sign “=” is used to name objects and assign values in Mathematica, equations in Mathematica are of the form

left-hand side==right-hand side.

The “double-equals” sign “==” between the left-hand side and right-hand side specifies that the object is an equation. For example, to represent the equation

3x7 4in Mathematica, type3x+7==4. The commandSolve[lhs==rhs,x]

solves the equationlhs rhsforx. If the only unknown in the equation lhs rhsisxand Mathematica does not need to use inverse functions to solve forx, the commandSolve[lhs==rhs] solves the equation lhs rhsforx. Hence, to solve the equation 3x7 4, both the commands Solve[3x+7==4]+ and Solve[3x+7==4,x]+ return the same result.

EXAMPLE 2.4.1: Solve the equations3x74,x21

x1 0, andx3x2 x10.

SOLUTION: In each case, we useSolveto solve the indicated equa-tion. Be sure to include the double equals sign “==” between the left and right-hand sides of each equation. Thus, the result of entering

In[188]:= Solve3x7 4 Out[188]= x 1

means that the solution of3x74isx 1and the result of entering In[189]:= Solvex21

x1 0 Out[189]= x 1

means that the solution of x21

x1 0isx 1. On the other hand, the equationx3x2x10has two imaginary roots. We see that entering

In[190]:= Solvex3x2x1 0 Out[190]= x 1,x ,x

yields all three solutions. Thus, the solutions ofx3x2x1 0are x 1andx !i. Remember that the Mathematica symbolIrepresents the complex number i

1. In general, Mathematica can find the exact solutions of any polynomial equation of degree four or less.

Observe that the results of aSolvecommand are alist. Lists and tables are discussed in more detail in Chapter 4.

Mathematica can also solve equations involving more than one variable for one variable in terms of other unknowns.

EXAMPLE 2.4.2: (a) Solve the equationv Πr2/ hforh. (b) Solve the equationa2b2c2fora.

SOLUTION: These equations involve more than one unknown so we must specify the variable for which we are solving in theSolve com-mands. Thus, entering

In[191]:= Solvev Πr2 h , h Out[191]= hΠr2

v

solves the equation v Πr2/ h for h. (Be sure to include a space or * betweenΠandr.) Similarly, entering

In[192]:= Solvea2b2 c2, a Out[192]= a

b2c2,a

b2c2 solves the equationa2b2c2fora.

If Mathematica needs to use inverse functions to solve an equation, you must be sure to specify the variable(s) for which you want Mathematica to solve.

EXAMPLE 2.4.3: Find a solution ofsin2x2 sinx30.

SOLUTION: When the commandSolve[Sin[x]ˆ2-2Sin[x]-3==0]

is entered, Mathematica solves the equation forSin[x]. However, when the command

Solve[Sin[x]ˆ2-2Sin[x]-3==0,x]

is entered, Mathematica attempts to solve the equation for x. In this case, Mathematica succeeds in finding one solution. In fact, this equa-tion has infinitely many soluequa-tions of the formx 124k1Π,k0,!1,

!2, ...;sinx3has no solutions.

In[193]:= SolveSinx22 Sinx 3 0 Out[193]= Sinx 1,Sinx 3 In[194]:= SolveSinx22 Sinx 3 0, x Solve ifun

Inverse functions are being used by

Solve,so some solutions may not be found.

Out[194]= x Π

2,xArcSin3

The example indicates that it is especially important to be careful when dealing with equations involving trigonometric functions.

EXAMPLE 2.4.4: Let fΘ sin 2Θ2 cosΘ,0 Θ 2Π. (a) Solvef%Θ 0.

(b) Graph fΘand f%Θ.

SOLUTION: After defining fΘ, we useDto compute f%Θand then useSolveto solve f%Θ 0.

D[f[x],x]computes f%x;D[f[x],{x,n}] computesfnx. Topics from calculus are discussed in more detail in Chapter 3.

In[195]:= fΘ Sin2Θ 2 CosΘ Out[195]= 2 CosΘ Sin2 Θ In[196]:= df DfΘ,Θ

Out[196]= 2 Cos2 Θ 2 SinΘ In[197]:= Solvedf 0,Θ

Solve "ifun" "Inversefunctionsarebeingused bySolve, sosomesolutionsmaynotbefound."

Out[197]= Θ Π

2,Θ Π

6,Θ 5 Π

6

Notice thatΠ/2is not between0and2Π. Moreover,Π/6and5Π/6arenot the only solutions of f%Θ 0between0and2Π. Proceeding by hand, we use the identitycos 2Θ 12 sin2Θand factor:

2 cos 2Θ 2 sinΘ 0 12 sin2Θ sinΘ 0 2 sin2Θ sinΘ 10 2 sinΘ 1sinΘ 1 0

sosinΘ 1/2orsinΘ 1. Because we are assuming that0 Θ 2Π, we obtain the solutionsΘ Π/6,5Π/6, or3Π/2. We perform the same steps

with Mathematica. expression /. x->y

replaces all occurrences ofx inexpressionbyy.

In[198]:= s1 TrigExpanddf

Out[198]= 2 CosΘ22 SinΘ 2 SinΘ2 In[199]:= s2 s1/. CosΘˆ2> 1SinΘˆ2 Out[199]= 2 SinΘ 2 SinΘ22 1SinΘ2 In[200]:= Factors2

Out[200]= 2 1SinΘ 12 SinΘ

Finally, we graph fΘ and f%Θ with Plotin Figure 2-28. Note that the plot is drawn to scale because we include the option AspectRatio->Automatic.

In[201]:= PlotfΘ, df,Θ, 0, 2Π,

PlotStyle>GrayLevel0, GrayLevel0.3, AspectRatio> Automatic

We can also useSolveto find the solutions, if any, of various types of systems of equations. Entering

Solve[{lhs1==rhs1,lhs2==rhs2},{x,y}]

solves a system of two equations forxandywhile entering Solve[{lhs1==rhs1,lhs2==rhs2}]

1 2 3 4 5 6

attempts to solve the system of equations for all unknowns. In general,Solvecan find the solutions to a system of linear equations. In fact, if the systems to be solved are inconsistent or dependent, Mathematica’s output indicates so.

EXAMPLE 2.4.5: Solve each system:

(a)

SOLUTION: In each case we useSolveto solve the given system. For (a), the result of entering

In[202]:= Solve3xy 4, xy 2,x, y Out[202]= x 3

2, y1 2

means that the solution of

3xy4

xy2 isx, y 3/2,1/2. (b) We can verify that the results returned by Mathematica are correct. First, we name the system of equations sysand then useSolve to solve the system of equations naming the resultsols.

In[203]:= sys 2x3y4z 2, 3x2yz 0,

We verify the result by substituting the values obtained with Solve back intosyswithReplaceAll(/.).

In[205]:= sys/. sols

Out[205]= True, True, True

means that the solution of

(c) When we useSolveto solve this system, Mathematica returns{}, which indicates that the system has no solution; the system is inconsis-tent.

In[206]:= Solve2x2y2z 2,

xy3z 0,3x3y2z 1 Out[206]=

(d) On the other hand, when we use Solve to solve this system, Mathematica’s result indicates that the system has infinitely many so-lutions. That is, all ordered triples of the form 0, z1, zzreal are solutions of the system.

In[207]:= Solve2x2y2z 2,

3x2y2z 2, x3y3z 3 Solve svars

Equations may not give solutions for all"solve"variables.

Out[207]= x0, y 1z

We can often use Solveto find solutions of a nonlinear system of equations as well.

EXAMPLE 2.4.6: Solve the systems

SOLUTION: The graphs of the equations are both ellipses. We use ContourPlot to graph each equation, naming the results cp1 and cp2, respectively, and then useShowto display both graphs together in Figure 2-29. The solutions of the system correspond to the intersection points of the two graphs.

In[208]:= cp1 ContourPlot4x2y24,

AxesAutomatic, AxesOrigin 0, 0, DisplayFunction$DisplayFunction Finally, we useSolveto find the solutions of the system.

In[209]:= Solve4x2y2 4, x24y2 4

For (b), we also useSolveto find the solutions of the system. However, because the unknowns in the equations area,b,m,x, andy, we must

-2 -1 1 2

-2 -1 1 2

Figure 2-29 Graphs of4x2y24andx24y24

specify that we want to solve forxandyin theSolvecommand.

In[210]:= Solvex2 a2 y2

b2 1, y mx,x, y Out[210]= y a b m

b2a2m2, x a b b2a2m2, y a b m

b2a2m2

, x a b

b2a2m2

Although Mathematica can find the exact solution to every polynomial equation of degree four or less, exact solutions to some equations may not be meaningful. In those cases, Mathematica can provide approximations of the exact solutions using either theN[expression]or theexpression // Ncommands.

EXAMPLE 2.4.7: Approximate the solutions to the equations (a)x4 2x2 1x; and (b)1x2x3.

SOLUTION: Each of these is a polynomial equation with degree less than five so Solve will find the exact solutions of each equation.

However, the solutions are quite complicated so we useN to obtain approximate solutions of each equation. For (a), entering

In[211]:= NSolvex42x2 1x Out[211]= x0.1827770.633397,

x0.1827770.633397, x 1.71064,x1.34509

first finds the exact solutions of the equationx42x2 1xand then computes approximations of those solutions. The resulting output is the list of approximate solutions. For (b), entering

In[212]:= Solve1x2 x3, x//N Out[212]= x0.754878,

x 0.8774390.744862, x 0.8774390.744862

first finds the exact solutions of the equation1x2 x3and then com-putes approximations of those solutions. The resulting output is the list of approximate solutions.

Dans le document Getting Started (Page 94-103)