Ask Your Question

How to get positive solution only of a quadratic equation

asked 2013-01-21 21:25:37 +0200

Majid Khonji gravatar image

I have a quadratic equation when I give it to the solver, I get two solutions, one positive one negative. By doing this: solve(eq, x)[0]

we can select which one. However, I want to insure that is always positive. I don't want manual stuff!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-01-21 21:41:41 +0200

kcrisman gravatar image
sage: eq = x^2+2*x-3==0
sage: solve(eq,x)
[x == -3, x == 1]
sage: [sol for sol in solve(eq,x) if sol.rhs()>0]
[x == 1]

But keep in mind that not every quadratic equation has one positive and one negative solution! (Or even two real solutions...)

edit flag offensive delete link more

answered 2013-02-22 20:05:57 +0200

lftabera gravatar image


sage: solve([x^2+2*x-3==0, x>=0],x)
[[x == 1]]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-01-21 21:25:37 +0200

Seen: 6,583 times

Last updated: Feb 22 '13