# Select a number in a list

here is my question. I have a range of parameters spanning in a given range, a={1,50},b={100,200} and c={300,500}. For every set of parameters I have an indexed vector like this (for a given set):

v[a][b][c]


If for example a=20, b=120, c=350:

Input: v[20][120][350]
Output: {1,3,5}


I would like to tell the code: give me the element "i" of v . But if i write (for every set):

Part[v[20][120][350],2]


It returns me the error message

 Part 2 of {1,3,5} does not exist. >>


and not the number 3.

• are your parameters predefined? or v is a function that generates the list? I think some fundamental information are still missing here. If the v vectors are already declared, then Part[v[20][120][350],2] should work. If they are not declared yet, why do you want to take the second element of something that doesn't exist yet? It's still not clear what you want to do. Maybe it's just me, but I also don't get what you mean with "for every set" – Fraccalo Jan 23 at 12:34
• I solved a set of differential equations in a range of parameters predefined by me. From the solutions I declared different vectors depending on the same parameters. Now I want to find the element "i" of every vector (defined previously) to compare them with other elements of other vectors. It is a very stupid question, maybe I should put these lists in just another form but I don't understand hoe. – Orion Jan 23 at 12:53

I have to admit that this is a very weird way of storing lists, but maybe you just simplified your real code for providing an example here. Anyway:

v[a][b][c] = {1, 5, 9};

v[a][b][c][[2]]
Part[v[a][b][c],2]


5

5

Both work for me (mathematica 12 on MacOS)

In an example:

v[3][1][5] = {1, 5, 9};

v[3][1][5][[2]]


5

If you want to keep it generic you could do something like:

ElementOperation[v_, n_] := ACertainOperationOnV[v[[n]]]

ElementOperation[v[a][b][c], 2]


ACertainOperationOnV[5]

This approach can be scaled to as many v elements as you want, without need of declaring them in advance. However, if you could expand on what you need to achieve, we could provide you with a better answer.

EDIT

Following from your comment: "Now I want to find the element "i" of every vector (defined previously) to compare them with other elements of other vectors. "

If you can restructure your code so that the vectors are in a list, you can easily access the i-th element of the list:

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


{2,5}

If you can't have the v vectors in a list, you could try something like the following (I can't stress enough how much I think this is a bad idea, but it's up to you):

Information[v, "SubValues"][[3, ;; , 2]][[;; , 2]]


{2, 5}

• Also for me work in this way, but if I fon't declare v[a][b][c]={1,5,9} it doesn't work. And I don't know how to declare v for every set of parameters, they are just given me in output. – Orion Jan 23 at 12:14
• can you explain a bit more what you want to achieve, maybe with an example? – Fraccalo Jan 23 at 12:18
• I tried to edit the question. – Orion Jan 23 at 12:26
    v = {1, 5, 9}
Part[v, 2]

Association[Thread[{a, b, c} -> {1, 5, 9}]][b]

• 1, 5, 9 are not the values of the parameters. a b and c span in a range I didn't specified. – Orion Jan 23 at 11:59
• The reason for the error is that your function name is not standardized. – Please Correct GrammarMistakes Jan 23 at 12:01
• and how can I standardize function depending on parameters? – Orion Jan 23 at 12:04