# Initializing a system of abstract functions with a for loop [closed]

I am trying to initialize a collection of abstract functions $$\theta_k(t)$$ in a variable $$t$$ where $$1\leq k\leq n$$.

I cannot define them explicitely; the entire point is that I want to numerically solve an ODE I can define with their derivatives. It's clear how I can do this if I had the array, but I don't know how to initialize the array.

If I only cared about a particular value for $$n$$, I could declare an array of functions explicitly like this:

thetas = Array[{theta1[t_], theta2[t_], ... , thetan[t_]}]


There should be a away to initialize an array of abstract functions in the variable $$t$$. Once I have such an array, thetas, I can likewise initialize a second array, derivs such that

For[i=0,i<n, ++i,
derivs[[i]]=Sum[matrix[[i,j]]Sin[Abs[thetas[[j]]-thetas[[i]]]],{j,0,n}]
]


and then use NDSolve as suggested in the comments:

NDSolve[derivs, thetas = myInitialCondition, thetas, {t,0,reallyBigNumber}]

• The question is unclear, please show us your specific problem. Anyway, if I have to guess: are you trying to handle implicit array? If so, in most cases you don't need any special treatment, NDSolve can directly handle it, see 3rd example in section Scope -> Ordinary Differential Equations of document of NDSolve. Dec 3, 2022 at 1:34
• @xzczd Maybe I'm misunderstanding your meaning, but the third example (entitled "Directly specify a system of equations") does not do what I want; the author explicitly names the functions they are differentiating, that is, they specify ahead of time that they are defining a system of ODEs using three functions, x(t), y(t), and z(t). For any n, I want to initialize a collection of n functions; if they are in an array A, I can de-reference them with their index and define the system of ODEs with a For loop. I don't know how to tell Mathematica "A is an array of functions in the variable t"
– gdd
Dec 3, 2022 at 2:21
• I'm refering to "Solve for a vector-valued function". Notice there're separation lines between the examples. Dec 3, 2022 at 2:24
• You can also find many examples in this site. Just a few examples: mathematica.stackexchange.com/q/144339/1871 mathematica.stackexchange.com/q/268249/1871 mathematica.stackexchange.com/q/25260/1871 Then, don't use For loop: mathematica.stackexchange.com/q/134609/1871 Dec 3, 2022 at 2:39
• @xzczd Ah, apologies. I think I can do something with this. Thank you.
– gdd
Dec 3, 2022 at 2:42

Looks with With could be used.

a way to initialize an array of abstract functions

With[{vars = Array[theta, 3]}, vars = {"a", "b", "c"}]


or with non-ordinal indices

With[{vars = {theta, theta, theta}}, vars = {"a", "b", "c"}]


e.g.

theta


c