How to get only real solutions?



Barton Willis <willisb at unk.edu> writes:

>> Is there a way to restrict solve or to_poly_solve to only real solutions?
>
> No, there isn't. I get this question fairly often--I simply do not know how to do this in a way that is as general and reliable as I would like it to be.
> Maybe I'm wrong, but I think that keepin' it real isn't such an easy thing to do.

I had the same problem, even worse because the numbers that appeared in
my equations caused solve to generate sometimes more than a million
solutions, and it seemed as if it hung, while generating this useless
list of solutions. So I made a function that uses to_poly_solve and then
throws away the %union and the imaginary part.

(%i31) esolve(eq, x) := block(numer:true, defrule(r1, %i, 0),
       expand(to_poly_solve(eq, x)), part(apply1(%%, r1),1))$

(%i32) esolve( exp(-10000*t/50175) = 1/2, t);
(%o32)                      [t = 3.477866116751269]

Note: you have to give the variable to solve (t) explicitely, contrary
to solve().
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]