Ask Your Question
1

How to get positive solution only of a quadratic equation

asked 2013-01-21 14:25:37 -0500

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
2

answered 2013-02-22 13:05:57 -0500

lftabera gravatar image

Also

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

answered 2013-01-21 14:41:41 -0500

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

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-01-21 14:25:37 -0500

Seen: 3,350 times

Last updated: Feb 22 '13