I have an array of variables that I've constructed, that all depend on time s

ntestarr = Array[n$ #[s] &, NCap]
{n$ 1[s], n$ 2[s], n$ 3[s], n$ 4[s], n$ 5[s], n$ 6[s], n$ 7[s], 
 n$ 8[s], n$ 9[s], n$ 10[s], n$ 11[s], n$ 12[s], n$ 13[s], n$ 14[s], 
 n$ 15[s], n$ 16[s], n$ 17[s], n$ 18[s], n$ 19[s], n$ 20[s]}

However I would like to additionally create an array of the derivatives of these variables, that is something like


However this does not work. Also, note that that there is a space between "n$" and "#", that I would like to get rid of in every term.

  • $\begingroup$ The idiomatic way to create indexed variables in MMA is to use square brackets e.g. ntestarr=Table[n[i,s],{i,20}]. This saves you from turning strings into symbols etc. You can find the derivatives just as Henrik showed. But if you are going to use this for calculations, it's probably easier to have n[s_]=Table[n[i,s],{i,20}] and the derivative is n'[s]. $\endgroup$ – N.J.Evans Nov 15 '17 at 17:35
  • $\begingroup$ This works perfectly thank you $\endgroup$ – Danny Weiss Nov 30 '17 at 23:05
ntestarr = Array[Symbol["n$" <> ToString[#]][s] &, NCap]
D[#, s] & /@ ntestarr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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