ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 16 Jul 2020 16:30:02 +0200Selecting specific values in Sagehttps://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/ I have the following solution:
solve(...)=[[xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b), l1 == (a + b)*(R*b/(a + b))^b*(R*a/((a + b)*p1))^a/R]]
Im aware I can get the whole set of solutions back with the use of
solve(...)[0]
[xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b), l1 == (a + b)*(R*b/(a + b))^b*(R*a/((a + b)*p1))^a/R]
Im only interested in getting back `xa1`. Is there a way to do that?Thu, 16 Jul 2020 05:13:23 +0200https://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/Answer by EconJohn for <p>I have the following solution:</p>
<pre><code>solve(...)=[[xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b), l1 == (a + b)*(R*b/(a + b))^b*(R*a/((a + b)*p1))^a/R]]
</code></pre>
<p>Im aware I can get the whole set of solutions back with the use of </p>
<pre><code>solve(...)[0]
[xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b), l1 == (a + b)*(R*b/(a + b))^b*(R*a/((a + b)*p1))^a/R]
</code></pre>
<p>Im only interested in getting back <code>xa1</code>. Is there a way to do that?</p>
https://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/?answer=52489#post-id-52489A solution I found to this problem is that you need to do as follows:
solution1=solve(...)[0]
solution1[0]
xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b)Thu, 16 Jul 2020 05:59:28 +0200https://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/?answer=52489#post-id-52489Comment by Emmanuel Charpentier for <p>A solution I found to this problem is that you need to do as follows:</p>
<pre><code> solution1=solve(...)[0]
solution1[0]
xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b)
</code></pre>
https://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/?comment=52496#post-id-52496`solution1(0][0]` i more streamlined. And faster.
You should peruse a Python tutorial ; Python lends itself to a lot of useful idioms,which may be time consuming to discover by yourself.
I cannot recommend enough this [marvelous book](http://sagebook.gforge.inria.fr/english.html) on Sage, even if it's a bit outdated (reporting on a Python 2-based version of Sage, whereas Sage is Python 3-based : version 9.1 and later support only Python 3).Thu, 16 Jul 2020 12:32:12 +0200https://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/?comment=52496#post-id-52496Comment by EconJohn for <p>A solution I found to this problem is that you need to do as follows:</p>
<pre><code> solution1=solve(...)[0]
solution1[0]
xa1 == R*a/((a + b)*p1), xa2 == R*b/(a + b)
</code></pre>
https://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/?comment=52503#post-id-52503@EmmanuelCharpentier Thanks for the tip!Thu, 16 Jul 2020 16:30:02 +0200https://ask.sagemath.org/question/52488/selecting-specific-values-in-sage/?comment=52503#post-id-52503