Only real roots (basic)



On 12/8/2013 6:25 AM, Aleksas Domarkas wrote:
> Ricardo JF on Dec 8 07:26:43 wrote:
>
> >hi friends,
>
> >why this doesn't give only real roots:
>
> >f(x):=x^3-x^2+x+1;
> >declare(x,real);
> >solve(f(x));
>
> >i just want [x=(sqrt(11)/...)]
>
> >thanks.
>
> (%i1) load(odes);
> (%o1) "C:/Users/Aleksas/maxima/odes.mac"
>
> Example 1
> (%i2) eq:x^3-x^2+x+1;
> (%o2) x^3-x^2+x+1
> (%i3) solvet(eq,x)$
> (%i4) sublist(%,lambda([e],freeof(%i,e)));
> (%o4) 
> [x=(sqrt(11)/3^(3/2)-17/27)^(1/3)-2/(9*(sqrt(11)/3^(3/2)-17/27)^(1/3))+1/3]

What does solvet have to offer here?  You can do the exact same thing 
with solve.
Also, the fact that an expression  involves  %i does not mean it is
necessarily  non-real.   The imaginary parts may cancel.

The use of trig functions can be useful in reducing the size of the 
expression,
but, so far as I can tell, does not address the potential ambiguity
of subexpressions from polynomial formulas or answer the questions as to 
which (symbolic, parametric)
roots are "positive" etc.

Of course in a purely numeric example the situation tends to be 
completely resolvable if
floating-point numbers are acceptable (and no overflows etc.)

Note that for the solution of   x^2-q=0,  you have two roots, x=sqrt(q) 
and x=-sqrt(q), and you
don't know which is positive or if they are real.




>
> Example 2
> (%i5) eq:x^3-4*x^2+x+1;
> (%o5) x^3-4*x^2+x+1
> (%i6) solvet(eq,x)$
> (%i7) sublist(%,lambda([e],freeof(%i,e)));
> (%o7) 
> [x=(2*sqrt(13)*cos(atan(3^(3/2)/5)/3)+4)/3,x=(2*sqrt(13)*cos((atan(3^(3/2)/5)-2*%pi)/3)+4)/3,x=(2*sqrt(13)*cos((atan(3^(3/2)/5)+2*%pi)/3)+4)/3]
> (%i8) float(%), numer;
> (%o8) [x=3.651093408937175,x=0.72610944503578,x=-0.37720285397296]
> (%i9) allroots(eq);
> (%o9) [x=-0.37720285397296,x=0.72610944503578,x=3.651093408937175]
>
> function "solvet" see in next Maxima relase
>
> best
> Aleksas
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima