ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 06 Feb 2014 02:11:41 -0600Two questions about parameters in solutionshttp://ask.sagemath.org/question/10997/two-questions-about-parameters-in-solutions/In the Sage documentation, this example is given:
sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
of a solution which includes an extra parameter:
[[x=?r1+3,y=r1]]
1. If I run this comand again, the solution is given with r2, then again with r3 etc. Is it possible to "reset" the parameter number?
2. How does one substitute a particular value for this parameter? I can do it by iterating through the list and using rhs():
[i.rhs().subs(r1=1/2) for i in sols]
or by setting solution_dict=True and fiddling another way:
[sols[i].subs(r1=1/2) for i in [x,y]]
Neither of these seem particularly elegant - is there a more "natural" way?Wed, 05 Feb 2014 17:04:20 -0600http://ask.sagemath.org/question/10997/two-questions-about-parameters-in-solutions/Answer by kcrisman for <p>In the Sage documentation, this example is given:</p>
<pre><code> sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
</code></pre>
<p>of a solution which includes an extra parameter:</p>
<pre><code>[[x=?r1+3,y=r1]]
</code></pre>
<ol>
<li>If I run this comand again, the solution is given with r2, then again with r3 etc. Is it possible to "reset" the parameter number?</li>
<li><p>How does one substitute a particular value for this parameter? I can do it by iterating through the list and using rhs():</p>
<pre><code>[i.rhs().subs(r1=1/2) for i in sols]
</code></pre>
<p>or by setting solution_dict=True and fiddling another way:</p>
<pre><code>[sols[i].subs(r1=1/2) for i in [x,y]]
</code></pre></li>
</ol>
<p>Neither of these seem particularly elegant - is there a more "natural" way?</p>
http://ask.sagemath.org/question/10997/two-questions-about-parameters-in-solutions/?answer=16012#post-id-16012Tab-completion was my friend for this:
sage: var("y")
y
sage: sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
[[x == -r1 + 3, y == r1]]
sage: sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
[[x == -r2 + 3, y == r2]]
sage: maxima_calculus.reset()
[multiplicities,%rnum,lispdisp,%rnum_list]
sage: sols = solve([x+y == 3, 2*x+2*y == 6],x,y); sols
[[x == -r1 + 3, y == r1]]
Note that you may get different things in the reset depending on how many computations you've done already. I suppose one could even go into the depths of the lisp interface and reset just `%rnum` and `%rnumlist` but I didn't want to do that.
Unfortunately, I don't think there is any more elegant way to do what you want - the solutions are lists by design. In some sense this is a feature, not a bug... though one it would be nice to do more easily. Maybe `map` is your friend here, though I doubt it would be fewer characters to type.
Thu, 06 Feb 2014 02:11:41 -0600http://ask.sagemath.org/question/10997/two-questions-about-parameters-in-solutions/?answer=16012#post-id-16012