• No results found

Equations in One Variable

In document Mathematica Book.pdf (Page 106-113)

The main equations that Solve and related Mathematica functions deal with are polynomial equations.

It is easy to solve a linear equation in x.

In[1]:= Solve@a x + b == c, xD

Out[1]= ::x Ø-b + c a >>

One can also solve quadratic equations just by applying a simple formula.

In[2]:= Solve@x ^ 2 + a x + 2 == 0, xD

Out[2]= ::x Ø1

2 -a - -8 + a2 >, :x Ø1

2 -a + -8 + a2 >>

Mathematica can also find exact solutions to cubic equations. Here is the first solution to a comparatively simple cubic equation. degrees up to four Mathematica is always able to give explicit formulas for the solutions.

For cubic and quartic equations the results are often complicated, but for all equations with degrees up to four Mathematica is always able to give explicit formulas for the solutions.

An important feature of these formulas is that they involve only radicals: arithmetic combina-tions of square roots, cube roots and higher roots.

It is a fundamental mathematical fact, however, that for equations of degree five or higher, it is no longer possible in general to give explicit formulas for solutions in terms of radicals.

There are some specific equations for which this is still possible, but in the vast majority of cases it is not.

This constructs a degree six polynomial.

In[4]:= Expand@Product@x ^ 2 - 2 i, 8i, 3<DD

Out[4]= -48 + 44 x2- 12 x4+ x6

For a polynomial that factors in the way this one does, it is straightforward for Solve to find the roots.

In[5]:= Solve@% == 0, xD

Out[5]= :8x Ø -2<, 8x Ø 2<, :x Ø - 2 >, :x Ø 2 >, :x Ø - 6 >, :x Ø 6 >>

This constructs a polynomial of degree eight.

In[6]:= Expand@x ^ 2 - 2 ê. x -> x ^ 2 - 3 ê. x -> x ^ 2 - 5D

Out[6]= 482 - 440 x2+ 144 x4- 20 x6+ x8

The polynomial does not factor, but it can be decomposed into nested polynomials, so Solve can again find explicit formulas for the roots.

In[7]:= Solve@% == 0, xD

Out[7]= ::x Ø - 5 - 3 - 2 >, :x Ø 5 - 3 - 2 >, :x Ø - 5 + 3 - 2 >, :x Ø 5 + 3 - 2 >,

:x Ø - 5 - 3 + 2 >, :x Ø 5 - 3 + 2 >, :x Ø - 5 + 3 + 2 >, :x Ø 5 + 3 + 2 >>

Root@ f ,kD the kth root of the equation f @xD == 0 Implicit representation for roots.

No explicit formulas for the solution to this equation can be given in terms of radicals, so Mathematica uses an implicit symbolic representation.

In[8]:= Solve@x ^ 5 - x + 11 == 0, xD

Out[8]= 99x Ø RootA11 - Ò1 + Ò15&, 1E=, 9x Ø RootA11 - Ò1 + Ò15&, 2E=,

9x Ø RootA11 - Ò1 + Ò15&, 3E=, 9x Ø RootA11 - Ò1 + Ò15&, 4E=, 9x Ø RootA11 - Ò1 + Ò15&, 5E==

This finds a numerical approximation to each root.

In[9]:= N@%D

Out[9]= 88x Ø -1.66149<, 8x Ø -0.46194 - 1.565 Â<,

8x Ø -0.46194 + 1.565 Â<, 8x Ø 1.29268 - 0.903032 Â<, 8x Ø 1.29268 + 0.903032 Â<<

If what you want in the end is a numerical solution, it is usually much faster to use NSolve from the outset.

In[10]:= NSolve@x ^ 5 - x + 11 == 0, xD

Out[10]= 88x Ø -1.66149<, 8x Ø -0.46194 - 1.565 Â<,

8x Ø -0.46194 + 1.565 Â<, 8x Ø 1.29268 - 0.903032 Â<, 8x Ø 1.29268 + 0.903032 Â<<

Root objects provide an exact, though implicit, representation for the roots of a polynomial.

You can work with them much as you would work with Sqrt@2D or any other expression that represents an exact numerical quantity.

Here is the Root object representing the first root of the polynomial discussed above.

In[11]:= r = Root@Ò ^ 5 - Ò + 11 &, 1D

Out[11]= RootA11 - Ò1 + Ò15&, 1E

This is a numerical approximation to its value.

In[12]:= N@rD

Out[12]= -1.66149

Round does an exact computation to find the closest integer to the root.

In[13]:= Round@rD

Out[13]= -2

If you substitute the root into the original polynomial, and then simplify the result, you get zero.

In[14]:= FullSimplify@x ^ 5 - x + 11 ê. x -> rD

Out[14]= 0

This finds the product of all the roots of the original polynomial.

In[15]:= FullSimplify@Product@Root@11 - Ò + Ò ^ 5 &, kD, 8k, 5<DD

Out[15]= -11

The complex conjugate of the third root is the second root.

In[16]:= Conjugate@Root@11 - Ò + Ò ^ 5 &, 3DD

Out[16]= RootA11 - Ò1 + Ò15&, 2E

If the only symbolic parameter that exists in an equation is the variable that you are solving for, then all the solutions to the equation will just be numbers. But if there are other symbolic parameters in the equation, then the solutions will typically be functions of these parameters.

The solution to this equation can again be represented by Root objects, but now each Root object involves the parameter a.

In[17]:= Solve@x ^ 5 + x + a == 0, xD

This shows the behavior of the first root as a function of a.

In[19]:= Plot@Root@Ò ^ 5 + Ò + a &, 1D, 8a, - 2, 2<D

Out[19]=

This finds the derivative of the first root with respect to a.

In[20]:= D@Root@Ò ^ 5 + Ò + a &, 1D, aD

Out[20]= - 1

1 + 5 RootAa + Ò1 + Ò15&, 1E4

If you give Solve any nth-degree polynomial equation, then it will always return exactly n solu-tions, although some of these may be represented by Root objects. If there are degenerate

If you give Solve any nth-degree polynomial equation, then it will always return exactly n solu-tions, although some of these may be represented by Root objects. If there are degenerate solutions, then the number of times that each particular solution appears will be equal to its multiplicity.

Solve gives two identical solutions to this equation.

In[21]:= Solve@Hx - 1L ^ 2 == 0, xD

Out[21]= 88x Ø 1<, 8x Ø 1<<

Here are the first four solutions to a tenth-degree equation. The solutions come in pairs.

In[22]:= Take@Solve@Hx ^ 5 - x + 11L ^ 2 == 0, xD, 4D

Out[22]= 99x Ø RootA11 - Ò1 + Ò15&, 1E=, 9x Ø RootA11 - Ò1 + Ò15&, 1E=, 9x Ø RootA11 - Ò1 + Ò15&, 2E=, 9x Ø RootA11 - Ò1 + Ò15&, 2E==

Mathematica also knows how to solve equations which are not explicitly in the form of polynomi-als.

Here is an equation involving square roots.

In[23]:= Solve@Sqrt@xD + Sqrt@1 + xD == a, xD

Out[23]= ::x Ø1 - 2 a2+ a4 4 a2

>>

And here is one involving logarithms.

In[24]:= Solve@Log@xD + Log@1 - xD == a, xD

Out[24]= ::x Ø1

2 1 - 1 - 4 ‰a >, :x Ø1

2 1 + 1 - 4 ‰a >>

So long as it can reduce an equation to some kind of polynomial form, Mathematica will always be able to represent its solution in terms of Root objects. However, with more general equa-tions, involving say transcendental funcequa-tions, there is no systematic way to use Root objects, or even necessarily to find numerical approximations.

Here is a simple transcendental equation for x.

In[25]:= Solve@ArcSin@xD == a, xD

Out[25]= 88x Ø Sin@aD<<

There is no solution to this equation in terms of standard functions.

In[26]:= Solve@Cos@xD == x, xD Solve::tdep :

The equations appear to involve the variables to be solved for in an essentially non-algebraic way.

Out[26]= Solve@Cos@xD ã x, xD

Mathematica can nevertheless find a numerical solution even in this case.

In[27]:= FindRoot@Cos@xD == x, 8x, 0<D

Out[27]= 8x Ø 0.739085<

Polynomial equations in one variable only ever have a finite number of solutions. But transcen-dental equations often have an infinite number. Typically the reason for this is that functions like Sin in effect have infinitely many possible inverses. With the default option setting InverseFunctions -> True, Solve will nevertheless assume that there is a definite inverse for any such function. Solve may then be able to return particular solutions in terms of this inverse function.

Mathematica returns a particular solution in terms of ArcSin, but prints a warning indicating that other solutions are lost.

In[28]:= Solve@Sin@xD == a, xD

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

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

Out[28]= 88x Ø ArcSin@aD<<

Here the answer comes out in terms of ProductLog.

In[29]:= Solve@Exp@xD + x + 1 == 0, xD

InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses.

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

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

Out[29]= ::x Ø -1 - ProductLogB1

F>>

If you ask Solve to solve an equation involving an arbitrary function like f, it will by default try to construct a formal solution in terms of inverse functions.

Solve by default uses a formal inverse for the function f.

In[30]:= Solve@f@xD == a, xD

InverseFunction::ifun : Inverse functions are being used. Values may be lost for multivalued inverses.

Out[30]= 99x Ø fH-1L@aD==

This is the structure of the inverse function.

In[31]:= InputForm@%D

Out[31]//InputForm= {{x -> InverseFunction[f, 1, 1][a]}}

InverseFunction@ f D the inverse function of f

InverseFunction@ f ,k,nD the inverse function of the n-argument function f with respect to its kth argument

Inverse functions.

This returns an explicit inverse function.

In[32]:= InverseFunction@TanD

Out[32]= ArcTan

Mathematica can do formal operations on inverse functions.

In[33]:= D@InverseFunction@fD@x ^ 2D, xD

Out[33]= 2 x f£AfH-1LAx2EE

While Solve can only give specific solutions to an equation, Reduce can give a representation of a whole solution set. For transcendental equations, it often ends up introducing new parame-ters, say with values ranging over all possible integers.

This is a complete representation of the solution set.

In[34]:= Reduce@Sin@xD == a, xD

Out[34]= C@1D œ Integers && Hx ã p - ArcSin@aD + 2 p C@1D »» x ã ArcSin@aD + 2 p C@1DL

Here again is a representation of the general solution.

In[35]:= Reduce@Exp@xD + x + 1 == 0, xD

Out[35]= C@1D œ Integers && x ã -1 - ProductLogBC@1D, 1

F

As discussed at more length in "Equations and Inequalities over Domains", Reduce allows you to restrict the domains of variables. Sometimes this will let you generate definite solutions to transcendental equations~or show that they do not exist.

With the domain of x restricted, this yields definite solutions.

In[36]:= Reduce@8Sin@xD == 1 ê 2, Abs@xD < 4<, xD

Out[36]= x ã -7 p 6

»» x ãp 6

»» x ã5 p 6

With x constrained to be real, only one solution is possible.

In[37]:= Reduce@Exp@xD + x + 1 == 0, x, RealsD

Out[37]= x ã -1 - ProductLogB1

F

Reduce knows there can be no solution here.

In[38]:= Reduce@8Sin@xD == x, x > 1<, xD

Out[38]= False

In document Mathematica Book.pdf (Page 106-113)