How to get only the real solutions in Maxima?

Viewed 171

I am trying to solve an equation with Maxima so that I only get real solutions if they exist; if there are no real solutions, or if there are not even complex solutions, I would like Maxima to return an empty list.

For example, I would like that when solving x^2+100-x=0 using solve(x^2+100-x,x), which has only complex solutions, Maxima would return an empty list. Or that when solving log(x)-x=0 using solve(log(x)-x,x), which also has no real solutions, Maxima would return an empty list. In this second example, what I get instead is [x=log(x)].

How could this be achieved with Maxima?

1 Answers

Inhibit implicit solutions:

(%i1) solve(log(x)-x);
(%o1)                            [x = log(x)]
(%i2) solve(log(x)-x), solveexplicit: true;
(%o2)                                 []

Keep only solutions without an imaginary part:

(%i1) s: solve(x^2+100-x);
                       sqrt(399) %i - 1      sqrt(399) %i + 1
(%o1)           [x = - ----------------, x = ----------------]
                              2                     2
(%i2) sublist(s, imagpart);
(%o2)                                 []
(%i3) s: solve(x^2+2 * x + 1);
(%o3)                              [x = - 1]
(%i4) sublist(s, imagpart);
(%o4)                              [x = - 1]
Related