MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Bug in Solve?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102971] Re: Bug in Solve?
  • From: pfalloon <pfalloon at gmail.com>
  • Date: Thu, 3 Sep 2009 05:41:24 -0400 (EDT)
  • References: <h7l8rh$35s$1@smc.vnet.net>

On Sep 2, 6:02 pm, tonysin <a2mg... at yahoo.com> wrote:
> I am just trying to learn Mathematica. What am I doing wrong here?
>
> I have a very simple equation:
>
> x^3 - 15 x + 2 = 0
>
> When I plot it in Mathematica 7,
>
> ClearAll[*]
> f[x_] := x^3 - 15 x + 2
> Plot[f[x], {x, -5, 5}]
>
> it gives the expected graph of a cubic, with three real roots near -4,
> 0, and 4.
>
> When I NSolve it,
>
> NSolve[f[x] == 0, x]
>
> it gives
>
> {{x -> -3.938}, {x -> 0.133492}, {x -> 3.80451}}
>
> which is exactly what you would expect from the graph.
>
> But when I Solve it
>
> Solve[f[x] == 0, x]
>
> it gives this mess
>
> {{x -> 5/(-1 + 2 I Sqrt[31])^(1/3) + (-1 + 2 I Sqrt[31])^(
>     1/3)}, {x -> -((5 (1 + I Sqrt[3]))/(
>      2 (-1 + 2 I Sqrt[31])^(1/3))) -
>     1/2 (1 - I Sqrt[3]) (-1 + 2 I Sqrt[31])^(1/3)}, {x -> -((
>      5 (1 - I Sqrt[3]))/(2 (-1 + 2 I Sqrt[31])^(1/3))) -
>     1/2 (1 + I Sqrt[3]) (-1 + 2 I Sqrt[31])^(1/3)}}
>
> I don't know how it looks in your font, but that "I" in each solution
> is the imaginary i.  Solve is saying this equation has no real roots,
> even though the graph clearly shows that all three roots are real.
>
> Can someone tell me if I am doing something wrong, or am I expecting
> something wrong, or if I just can't trust Mathematica?  Thanks for any
> help.

If you dig a little further, you'll see that although the exact
solutions involve imaginary components, they all cancel out.

Try a numerical approximation:

In[31]:= Clear[x];
x /. Solve[x^3 - 15 x + 2 == 0, x] // N[#, 30] &
Out[32]= {3.80451157728856211448739226254+0.*10^-30
I,-3.93800349985703665057810982327+0.*10^-30 I,
0.1334919225684745360907175607268+0.*10^-32 I}

You can get rid of the zero imaginary part by using Chop:

In[33]:= % // Chop
Out[33]=
{3.80451157728856211448739226254,-3.93800349985703665057810982327,0.1334919=
225684745360907175607268}

It shouldn't be too surprising to see imaginary parts appear in the
exact solution. After all, the general solution (for symbolic
coefficients) must allow for complex solutions, since not all cubic
curves with real coefficients will cross the axis three times. There's
a useful discussion of this in MathWorld (see paragraph below Eq.
69):

http://mathworld.wolfram.com/CubicFormula.html

So, to answer your question: you weren't doing anything wrong, you
were probably expecting something unrealistic (challenge: how much
more simply could you express the "mess" that is the exact solution??)
and, finally, you certainly *can* trust Mathematica in this domain (as
a general principle, given that so many serious people having been
using the system for decades now, it's a pretty safe bet that any such
obvious bugs in a function like Solve would have been noticed long
ago).

Cheers,
Peter.


  • Prev by Date: Re: Bug in Solve?
  • Next by Date: Re: Bug in Solve?
  • Previous by thread: Re: Bug in Solve?
  • Next by thread: Re: Bug in Solve?