I have a symbol, say x, whose calculated value is a 2nd symbol. How can I set the 2nd symbol to a given value? For example, say the value of x is one of the symbols a, b, or c. If it is a, I want to set a = 10. If it is b, I want to set b = 10. Ditto for c. But, I can use a, b, or c only if I can extract it from x. I want to do something like
x=a
%=10
Out= a=10
To complicate this just a bit, my 2nd "symbols" actually are subscripts, like Subscript[a,1], Subscript[a,1,2], Subscript[a,1,3,4]. I found a partial solution.
x=Subscript[a,3];
Subscript[x[[1]],x[[2]]=10;
Subscript[a,3]
Out(1)= 10
But how do I do this if a has n subscripts? How do I write something like
x=Subscript[a,3,4,2, ..., 5];
Subscript[a,x[[2]], ... , x[[n]]]=10
Hold[x = 10] /. OwnValues[x] // ReleaseHold
? -- BTW, I avoid subscripts for variables, and most questions about them. But then I've only been using Mathematica for a couple of decades or so. Still,OwnValues
might work with them, ifx
is a regular symbol. Otherwise, maybeDownValues
will work. $\endgroup$ – Michael E2 Sep 14 '16 at 2:44