Only real roots (basic)



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)$

 We can define

(%i2) solveR(eq,x):=block([],solvet(eq,x),
sublist(%%,lambda([e],freeof(%i,e))))$

 Examples:

(%i3) solveR(x^2-1=0,x);
(%o3) [x=-1,x=1]

(%i4) solveR(x^2+1=0,x);
(%o4) []

(%i5) solveR(x^3+1=0,x);
(%o5) [x=-1]

(%i6) solveR(x^3-x^2+x+1=0,x);
(%o6)
[x=(sqrt(11)/3^(3/2)-17/27)^(1/3)-2/(9*(sqrt(11)/3^(3/2)-17/27)^(1/3))+1/3]

(%i7) solveR(x^5-7*x^4+8*x^3+7*x+7=0,x);
(%o7) [x=(4*sqrt(7)*cos(atan(3^(3/2))/3)+7)/3,
x=(4*sqrt(7)*cos((atan(3^(3/2))-2*%pi)/3)+7)/3,
x=(4*sqrt(7)*cos((atan(3^(3/2))+2*%pi)/3)+7)/3]

(%i8) solveR(x^6-3*x^5-3*x^4+12*x^3-3*x^2-6*x+2=0,x);
(%o8) [x=1, x=1-sqrt(3), x=sqrt(3)+1, x=2*cos((2*%pi)/9),
x=2*cos((4*%pi)/9), x=2*cos((8*%pi)/9)]

(%i10) assume(a<0);
(%o10) [a<0]
(%i11) solveR(x^2+a=0,x);
(%o11) [x=-sqrt(-a),x=sqrt(-a)]

best
Aleksas