First time here? Check out the FAQ!

Ask Your Question
1

How to get positive solution only of a quadratic equation

asked 12 years ago

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!

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
2

answered 12 years ago

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...)

Preview: (hide)
link
2

answered 12 years ago

lftabera gravatar image

Also

sage: solve([x^2+2*x-3==0, x>=0],x)
[[x == 1]]
Preview: (hide)
link

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: 12 years ago

Seen: 7,235 times

Last updated: Feb 22 '13