Message Boards Message Boards

GROUPS:

Clear the value of a subscripted variable?

Posted 2 months ago
431 Views
|
4 Replies
|
3 Total Likes
|

I defined K_b:

In[34]:= Subscript[K, b] = x y

Out[34]= x y

In[35]:= Subscript[K, b]

Out[35]= x y

but then decided to clear the value (so I can later change the assignment to an equation ==).

In[36]:= Clear[Subscript[K, b]]

During evaluation of In[36]:= Clear::ssym: Subscript[K, b] is not a symbol or a string.

Why did this fail? ClearAll didn't work either.

4 Replies

Use:

Subscript[k, b] =.

I would stay away from subscripted symbols, because it may cause problems when substituting things as it is not seen as a single symbol:

Subscript[k, b] /. k -> 3

gives

3_b

There is a general advice against the use of subscripts - as Sander did, because:

I you make an assignment like this

Subscript[k, b] = 1;
a = 2;

then with "normal" symbols OwnValues are created - but not in the case of Subscript:

enter image description here

Instead the assignment to Subscript went (as kind of a function definition!) into DownValues:

enter image description here

The only meaningful use of Subscript is (typically at the very end of a calculation) for displaying reasons.

Does that help? Regards -- Henrik

I've said it before: you should think of Subscript as a typographical construct.

OK, thanks for the comments! -Jon

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract