I would like to create two arrays of functions yfunc[[i]] and tfunc[[i]], with each entry of those functions being a function depending on t, that is to say


and the same for tfunc. Then I would also like to plot members of these array with ParametricPlot in pairs, e.g.


This code works:

yfunc[t_?NumericQ, i_?IntegerQ] := i*t;
tfunc[t_?NumericQ, i_?IntegerQ] := 2 i*t;
comp[i_] := {tfunc[t, i], yfunc[t, i]};
Show[ParametricPlot[comp[1], {t, 0, 1}], AspectRatio -> 1]

But another try of creating this function array fails:

yfunc[t_?NumericQ] := Table[i*t, {i, 1, 100}]
tfunc[t_?NumericQ] := Table[2 i*t, {i, 1, 100}];
comp[i_?IntegerQ] := {tfunc[[i]][t], yfunc[[i]][t]};
Show[ParametricPlot[comp[1], {t, 0, 1}], AspectRatio -> 1]

I guess in this case it is a problem with the evaluation. What would be the correct way to do it in the second way?


  • 1
    $\begingroup$ Your patterns do not match; first argument is a real, second is an integer. $\endgroup$ Jan 24, 2013 at 9:46
  • $\begingroup$ Yes this works fine. Thanks! This resolved the first case. I mixed up t and i. Edited the post to correct this. $\endgroup$
    – malumno
    Jan 24, 2013 at 10:00
  • 1
    $\begingroup$ in the first example, you probably meant comp[i_] := {tfunc[t, i], yfunc[t, i]} (which works fine). Similarly for the second example: comp[i_] := {tfunc[t][[i]], yfunc[t][[i]]} works. $\endgroup$
    – kglr
    Jan 24, 2013 at 10:04
  • $\begingroup$ The problem with using comp[i_] := {tfunc[t][[i]], yfunc[t][[i]]} is that first every function in the vector gets evaluated only to choose one value of interest in the end. This is of course no problem in the toy model i*t, but takes more time with longer arrays and more complicated functions. $\endgroup$
    – malumno
    Jan 24, 2013 at 10:13
  • $\begingroup$ malumno, even with the toy example, it is quite slow. $\endgroup$
    – kglr
    Jan 24, 2013 at 11:02

1 Answer 1


The problem with not using tfunc[t][[i]] and trying as you do to call tfunc[[i]][t] is that tfunc is not a list and cannot be indexed. The result of calling tfunc[t] is a list, which can be indexed. If you want to use a list of functions, you can use anonymous functions:

yfunc = Table[With[{i = i}, Function[t, i*t]], {i, 1, 100}];
tfunc = Table[With[{i = i}, Function[t, 2 i*t]], {i, 1, 100}];

comp[i_?IntegerQ, t_] := {tfunc[[i]][t], yfunc[[i]][t]};
Show[ParametricPlot[comp[1, t], {t, 0, 1}], AspectRatio -> 1]

Note that since Function has attribute HoldAll, With[{i=i},...] is used to inject the value of i into the expression. If you don't do this it wont work as: Table[Function[t,i],{i,2}] evalutes to {Function[t,i],Function[t,i]}.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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