User1234321
User1234321

Reputation: 341

How to get only the real solutions in Maxima?

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?

Upvotes: 2

Views: 1053

Answers (2)

user16769489
user16769489

Reputation:

Maybe this could also help your answer:

(%i80) realroots(x^2+100-x=0);

(%o80) []

when the solution is [], there no real roots. On the other hand, when at least there is a real solution:

(%i7) realroots (x^3-3x^2+4x-2 = 0);

(%o7) [x=1]

x^3-3x^2+4x-2 = 0 have three solution, only one is real. For all solution:

(%i9) solve(x^3-3x^2+4x-2 = 0,x);

(%o9) [x=1-%i,x=%i+1,x=1]

Upvotes: 0

slitvinov
slitvinov

Reputation: 5768

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]

Upvotes: 2

Related Questions