Ask Your Question

remove values from variables but keep variables

asked 2017-05-07 16:27:33 +0200

cybervigilante gravatar image

updated 2017-05-07 18:12:00 +0200

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 18:02:10 +0200

tmonteil gravatar image

updated 2017-05-07 18:13:29 +0200

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 16:27:33 +0200

Seen: 476 times

Last updated: May 07 '17