Ask Your Question

convert a symbolic var into a numeric var

asked 2013-12-12 05:09:33 +0200

jeanpat gravatar image

Hello, How to compute y or to draw a point of coord (sol, 0) ?

Thank you

print sol
print sol[0], type(sol), type(sol[0])
#print y

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-12-12 05:53:27 +0200

tmonteil gravatar image

updated 2013-12-12 06:01:42 +0200

Your sol is a list, with 1 element:

sage: sol
[x == 3]

Then, sol[0] is a symbolic expression. To get its right hand side, it suffice to use the .rhs() method:

sage: sol[0]
x == 3

sage: sol[0].rhs()

Then, it should be enough to work since the symbolic variable 3 should be automatically coerced by Sage into a numeric value if needed (and plot should understand symbolic numbers).

sage: sol[0].rhs().parent()
Symbolic Ring

That said, it may be a good idea to escape the symbolic ring. If you want to have a genuine integer, you can do:

sage: ZZ(sol[0].rhs())
sage: ZZ(sol[0].rhs()).parent()
Integer Ring

If you want an algebraic number:

sage: AA(sol[0].rhs())
sage: AA(sol[0].rhs()).parent()
Algebraic Real Field

If you want a floating number:

sage: RR(sol[0].rhs())
sage: RR(sol[0].rhs()).parent()
Real Field with 53 bits of precision
edit flag offensive delete link more

answered 2013-12-12 08:33:52 +0200

calc314 gravatar image

Here is how to plot the point:

edit flag offensive delete link more

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


Asked: 2013-12-12 05:09:33 +0200

Seen: 1,440 times

Last updated: Dec 12 '13