Storing the positive solution only of a quadratic in a variable

Hi everyone, I am quite new to Sagemath, and I have the following problem:

DPi_R_D_R_AI = (Pistar_R_D - Pistar_R_AI).simplify_full()


Is a quadratic function of c (or, a parabola).

I need to find the positive roots only, and I know that the only positive root is the one with the "+" sign (it is a parametric function), and I need to store this root in a variable.

Problem: when I try

c_prof = solve(DPi_R_D_R_AI == 0,c)[0].rhs()


Sagemath only displays the negative root! I tried to have a look at this post, but I don't have a "number" I can exploit: c>=0 means nothing for Sagemath...

How should I approach this?

Thanks for the attention,

Matteo

edit retag close merge delete

Sort by ยป oldest newest most voted

Ok, I randomly tried this:

c_prof = solve(DPi_R_D_R_AI == 0,c)[1].rhs()


And it works! Can I ask you, then, why is it the case?

Thanks,

Matteo

more

If DPi_R_D_R_AI is a quadratic in c with two (symbolically) distinct roots then solve(DPi_R_D_R_AI == 0,c) is a list with two elements (try evaluating/printing it) and solve(DPi_R_D_R_AI == 0,c)[1].rhs() selects the right-hand side of one of them (while the same expression with [0] selects the right-hand side of the other).

( 2022-10-06 11:29:39 +0200 )edit

ok, so basically the [i] refers to the ith element of the list? Thanks a lot btw!

( 2022-10-06 15:19:44 +0200 )edit