1
$\begingroup$

I want to do the following. Say I have a list:

test = List[a,b,c]

and I now want to assign some value to elements of that list, so that say if I assign 4 to a, when I input a it spits 4 out. How can I do that?

Only just started with Mathematica, there is probably some very easy answer to that question but I don't seem to be able to figure it out myself. I'd appreciate some help.

$\endgroup$
  • $\begingroup$ test[[1]] = 4; $\endgroup$ – march Dec 19 '18 at 16:25
  • $\begingroup$ That just replaces the value in my list, which is not what I'm after. $\endgroup$ – amator2357 Dec 19 '18 at 16:33
  • $\begingroup$ Related, and possible duplicates: (280), (6511), (10322). $\endgroup$ – Mr.Wizard Dec 19 '18 at 21:10
1
$\begingroup$
test = List[a, b, c];
MapThread[Set, {test, {4, 5, 6}}];
a
b
c

4

5

6

I would not suggest to rely in that too heavily. It is much more efficient and more useful to store the values in a List and index into it:

list = {4,5,6};
list[[1]]
list[[2]]
list[[3]]

4

5

6

$\endgroup$
  • $\begingroup$ Thank you for answer. Yeah, you're right. It actually does not work for my case. I guess I should've been more specific when formulating the question. The elements of my list are actually of the form: \alpha_{1} + \alpha_{2},\alpha_{2} + \alpha_{3},\alpha_{1} + \alpha_{2} + \alpha_{3}, etc. I know that it is not advisable to use subscripts in Wolfram but in my case it simply makes everything more understandable, especially in terms of the theory behind. $\endgroup$ – amator2357 Dec 19 '18 at 16:28
  • 1
    $\begingroup$ The simple way to subscript is to use a[1], a[2], a[3] ... i.e the symbol with single square brackets. This can be used in symbolic form too as a[n]. Curly brackets i.e. {.} indicate a list and are best only used for that. $\endgroup$ – Hugh Dec 19 '18 at 16:47
  • $\begingroup$ Thanks Hugh. I didn't use curly brackets for subscripts. I've written it that way in the comment above in order to illustrate what the elements in my list really look like, following latex kind of style of writing. $\endgroup$ – amator2357 Dec 19 '18 at 16:54
  • $\begingroup$ @amator2357 There is absolutely no point in saying, that "my list are actually of the form: [latex syntax following]" when you are dealing with Mathematica issue. Moreover, Subscript id definitely a way to "everything more understandable". What you actually want is \[Alpha] = {4,5,6};. Indexing into that is done with \[Alpha][[1]] and so on. Then you can also write \[Alpha][[1]] = 4. $\endgroup$ – Henrik Schumacher Dec 19 '18 at 17:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.