Ask Your Question
1

Storing the positive solution only of a quadratic in a variable

asked 2022-10-06 10:08:46 +0200

Boyko_Bu gravatar image

updated 2022-10-06 10:09:14 +0200

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-10-06 10:13:18 +0200

Boyko_Bu gravatar image

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

edit flag offensive delete link more

Comments

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

rburing gravatar imagerburing ( 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!

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

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-10-06 10:08:46 +0200

Seen: 88 times

Last updated: Oct 06 '22