ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Feb 2013 13:49:07 -0600Extracting numerical value from a symbolic expressionhttps://ask.sagemath.org/question/9825/extracting-numerical-value-from-a-symbolic-expression/Hi,
First of sorry for the title as I am not sure what should be the title of this question.
I used solve() command to solve a system of equations and got a result like this.
[[x1 == (4/3), x2 == (-1/6), x3 == (-1/6)]]
We can say that it is some vertex and I want to have a result as (4/3, -1/6, -1/6) or [4/3, -1/6, -1/6]. At the moment I am doing it manually. Is there any sage command that can automatically extract (4/3, -1/6, -1/6) from the solution [[x1 == (4/3), x2 == (-1/6), x3 == (-1/6)]].
Thanks in advance!
Wed, 20 Feb 2013 12:26:55 -0600https://ask.sagemath.org/question/9825/extracting-numerical-value-from-a-symbolic-expression/Answer by benjaminfjones for <p>Hi,</p>
<p>First of sorry for the title as I am not sure what should be the title of this question. </p>
<p>I used solve() command to solve a system of equations and got a result like this.</p>
<p>[[x1 == (4/3), x2 == (-1/6), x3 == (-1/6)]]</p>
<p>We can say that it is some vertex and I want to have a result as (4/3, -1/6, -1/6) or [4/3, -1/6, -1/6]. At the moment I am doing it manually. Is there any sage command that can automatically extract (4/3, -1/6, -1/6) from the solution [[x1 == (4/3), x2 == (-1/6), x3 == (-1/6)]].</p>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/9825/extracting-numerical-value-from-a-symbolic-expression/?answer=13722#post-id-13722I don't think there is a built-in solution that does exactly what you want, but it's easy enough to extract a vector solution:
sage: s = solve([x1==4/3, x2==-1/6, x3==-1/6], (x1,x2,x3))
sage: [ x.rhs() for x in s[0] ]
[4/3, -1/6, -1/6]Wed, 20 Feb 2013 13:49:07 -0600https://ask.sagemath.org/question/9825/extracting-numerical-value-from-a-symbolic-expression/?answer=13722#post-id-13722