# Defining list of new variables at once (in a loop?)

I have a list of solutions Subscript[x, 1][t], i = 1,...,n (n given).

I would like to use these variables to define new variables such as:

i = 1;
For[i = 1, i <= n, i++,
Subscript[X, i][t_] := Subscript[x, i][t] /. sol]


I know that this code is not working and I know why. However, I would like to ask you if there is a way how to define these variables at once (without having to define them one by one)?

David.

• TIP: never use Subscript nor For. They are one of the main sources of confusion. – AccidentalFourierTransform Nov 30 '19 at 18:15
• Here you could try Table[X[i][t_] := x[i][t] /. sol, {i, 1, n}]. Does this work as expected? – AccidentalFourierTransform Nov 30 '19 at 18:16
• Thank you very much, I replaced Substrict and with some more changes itw working properly now. Many thanks! – David Cichra Nov 30 '19 at 19:08

You can use Inactive to postpone the SetDelayed operation until after the RHS has been defined. Here is an example:

Clear[Subscript];
sol = Subscript[x, i_][t] -> t^i;
n = 10;

Activate @ Table[
Inactive[SetDelayed][
Subscript[X,i][t_],
Subscript[x,i][t]/.sol
],
{i, n}
];


Check:

Subscript[X, 4][2]


16

• Many thanks, that helped me a lot! – David Cichra Nov 30 '19 at 19:07