solve(...) and unnecessary complex results



Paul Smith <phhs80 at gmail.com> wrote:
>On Wed, Feb 20, 2008 at 9:32 PM,  <maxima-list at ssteiner.com> wrote:

>>  Example: solve( (0=x^3-4*x+2), x );
>>
>>  Maxima returns:
>>  [x = (-sqrt(3)*%i/2-1/2)*(3^-(3/2)*sqrt(37)*%i-1)^(1/3)+4*(sqrt(3)*%i/2-\
>>  1/2)/(3*(3^-(3/2)*sqrt(37)*%i-1)^(1/3)),x = (sqrt(3)*%i/2-1/2)*(3^-(3/2)*sqrt(\
>>  37)*%i-1)^(1/3)+4*(-sqrt(3)*%i/2-1/2)/(3*(3^-(3/2)*sqrt(37)*%i-1)^(1/3)),x = (\
>>  3^-(3/2)*sqrt(37)*%i-1)^(1/3)+4/(3*(3^-(3/2)*sqrt(37)*%i-1)^(1/3))]
>>
>>  I think the correct results are -2,214; 0,539; 1,675
>>  How to make Maxima return these results (real numbers) instead of complicated terms containing complex numbers?
>
>You can also solve the problem numerically:
>
>1. with plot2d identify small intervals containing the solutions;
>
>2. use find_root to determine the numeric solutions.

That would certainly work, but if what's needed is only the real roots, I think the easier way to get that is to ask for them:  realroots(x^3-4*x+2);

Then it's easy, if desired, to turn those results from fractions into floating point numbers as: float(%);

That yields  [x=-2.214319705963135,x=0.53918886184692,x=1.675131320953369]

which matches nicely with what the original poster wanted.

Ed