Ask Your Question

remove values from variables but keep variables

asked 2017-05-07 09:27:33 -0500

cybervigilante gravatar image

updated 2017-05-07 11:12:00 -0500

tmonteil gravatar image

How do I remove the values from variables but keep the variables. i.e. if x is defined and equal to 5, and I reset() I just get x as undefined if I try to use it in a symbolic equation. I just want to remove the 5 but keep the x.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-05-07 11:02:10 -0500

tmonteil gravatar image

updated 2017-05-07 11:13:29 -0500

You are confusing two very different notions of "variable".

When you write:

sage: x = 5

The Python name points to the integer 5.

When you write:

 sage:  reset()

or just

 sage: del(x)

you remove the name x from the global namespace.

In the symbolic expression cos(x), the x is not a Python name but a mathematical symbol, it is an object, like the integer 5 above.

The confusion might come from the fact that, at Sage startup, the Python name x points to the symbol x:

sage: x
sage: x.parent()
Symbolic Ring
sage: x.is_symbol()

But once you write x=5, the Python name x now points to the integer 5, and there is no way to let it remember that it used to point to the symbol x. If you want the Python x to point to the symbol x again, you can do:

sage: x = SR.var("x")

This is a very common confusion, see the tag variable_issue, this question or that question.

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: 2017-05-07 09:27:33 -0500

Seen: 40 times

Last updated: May 07