3rd order equations



On 08/16/2013 08:56 AM, Esben Byskov wrote:

> I have tried to solve the following rather simple equation using maxima:
>
> (%i1) Eq: -2*q^3+3*q-1.357008100494576;
> (%o1)                  - 2 q  + 3 q - 1.357008100494576
>
> (%i2) solve(Eq,q);
>
> rat: replaced -1.35700810049458 by -168062898/123848117 = -1.35700810049458
>                sqrt(3) %i   1   sqrt(1215787242366487) %i   84031449  1/3
> (%o2) [q = (- ---------- - -) (------------------------- - ---------)
>                    2        2                   3/2         247696234
.....<more nasty complicated complex expressions elided>.....
>
> **A plot of Eq shows that there is at least one real root at
> about -1.40.  Therefore the above result bothers me.  I have
> tried a bunch of functions to get at least one of the roots
> to be real, but haven't succeeded.  On the other hand, the
> following
> **
> realpart(%);
> float(%);
> **[q = .5875718061709099, q = - 1.40781890504042, q = 0.82024709886951]
>
> **agrees with MuPAD*
> *
> {-1.407818905, 0.5875718062, 0.8202470989}
>
> **What am I doing wrong?

You are not doing anything wrong, just that Maxima is a symbolic algebra 
rather than numerical algebra, and its preferred form for complex 
polynomial roots happens to be a little weird and different from what 
you would like to see. As you yourself noticed, those expressions can be 
reduced to simple real numbers. If you want to convince yourself that 
the imaginary part reduces out, you could manipulate the entire 
expression rather than dropping the Im part like you did in your 
float(realpart(...)) calculation:

float(trigsimp(rectform(solve(Eq,q))));

Whew, I think we can agree that this is not the most obvious thing to 
do. I first tried just float(solve(..)) but it kept a 
rational/exponential form, even after applying some *simp*() functions. 
I didn't come up with the rectform/trigsimp trick by myself--I found it 
in the FAQ at http://cadadr.org/maxima/faq.html

I am sure there are people on this list that can suggest simpler way to 
reduce such complex expressions, and explain why Maxima's preferred form 
for complex solutions is what it is.

In general, as great as Maxima is, it tends to require knowledge on how 
to convert its results between mathematically equivalent, but maybe not 
as convenient or conventional forms. If one is not interested in high 
maths but just in a numerical result, perhaps using Maxima is an 
overkill and numerical packages, such as Maxima's FOSS sibling Octave, 
are easier to use and control---in particular your example can be done 
in Octave simply:

format long; roots([-2,0,3,-1.357008100494576])

ans =

   -1.407818905040421
    0.820247098869510
    0.587571806170910