using the value of a symbolic expression

42 views
Skip to first unread message

jean-pat

unread,
Dec 12, 2013, 4:56:38 AM12/12/13
to sage-s...@googlegroups.com
Hello,
After having solved an equation, I'd like to use the result for another calculation (calculating y) or a ploting.
How to convert sol into a numerical value?

thank you

jeanpat

sol=solve(2*x+1==7,x)
print sol
print sol[0], type(sol), type(sol[0])
#y=2*sol+7
#print y

#plot(sol,0)

Vincent Knight

unread,
Dec 12, 2013, 5:03:51 AM12/12/13
to sage-s...@googlegroups.com
You can do two things jeanpat:

1:

sol=solve(2*x+1==7,x, solution_dict=True)
print sol  # sol is a list of dictionaries (key: variables, value: solution value)
print sol[0][x]

2:

sol=solve(2*x+1==7,x)
print sol  # sol is a list of equations
print sol[0].rhs()  # takes the first (and only on this occasion) equation of your solution and take the right hand side (rhs) of it.

Vince

--
Dr Vincent Knight
Cardiff School of Mathematics
Senghennydd Road,
Cardiff
CF24 4AG
(+44) 29 2087 5548
www.vincent-knight.com
+Vincent Knight
@drvinceknight
Skype: drvinceknight

jean-pat

unread,
Dec 12, 2013, 5:16:54 AM12/12/13
to sage-s...@googlegroups.com
thank you for your help,

Doing print sol[0].rhs() failed on http://sagecell.sagemath.org with the message:

AttributeError: 'Sequence_generic' object has no attribute 'roots'

But the first method worked
Reply all
Reply to author
Forward
0 new messages