2

Based on this question:

I have a list of bspline functions (nearly 1000) provided by applying BSplineFunction to a list of points. I want to get the points each of bspline function for Range[0, 1, .1].

For instance:

functions = {bsplinefunc1, bsplinefunc2, bsplinefunc3};

The desired result is:

result =
  {bsplinefunc1[0], bsplinefunc1[.1], bsplinefunc1[.2], ..., bsplinefunc1[1]}, 
  {bsplinefunc2[0], bsplinefunc2[.1], bsplinefunc2[.2], ..., bsplinefunc2[1]},
  {bsplinefunc3[0], bsplinefunc3[.1], bsplinefunc3[.2], ..., bsplinefunc3[1]}}

I tried to use the solutions of this question, mainly István Zachar's answer; however, I couldn't make it work.

Any help is appreciated.

cesm
  • 449
  • 3
  • 12

3 Answers3

4

You can use Thread to apply a function to a list of arguments:

Thread[bsplinefunc1[Range[0, 1, .1]]]

{bsplinefunc1[0.], bsplinefunc1[0.1], bsplinefunc1[0.2], bsplinefunc1[0.3], bsplinefunc1[0.4], bsplinefunc1[0.5], bsplinefunc1[0.6], bsplinefunc1[0.7], bsplinefunc1[0.8], bsplinefunc1[0.9], bsplinefunc1[1.]}

Now you can use Map to use the above on a list of functions:

Map[Thread[#[Range[0, 1, .1]]] &, functions]

{{bsplinefunc1[0.], bsplinefunc1[0.1], bsplinefunc1[0.2], bsplinefunc1[0.3], bsplinefunc1[0.4], bsplinefunc1[0.5], bsplinefunc1[0.6], bsplinefunc1[0.7], bsplinefunc1[0.8], bsplinefunc1[0.9], bsplinefunc1[1.]}, {bsplinefunc2[0.], bsplinefunc2[0.1], bsplinefunc2[0.2], bsplinefunc2[0.3], bsplinefunc2[0.4], bsplinefunc2[0.5], bsplinefunc2[0.6], bsplinefunc2[0.7], bsplinefunc2[0.8], bsplinefunc2[0.9], bsplinefunc2[1.]}, {bsplinefunc3[0.], bsplinefunc3[0.1], bsplinefunc3[0.2], bsplinefunc3[0.3], bsplinefunc3[0.4], bsplinefunc3[0.5], bsplinefunc3[0.6], bsplinefunc3[0.7], bsplinefunc3[0.8], bsplinefunc3[0.9], bsplinefunc3[1.]}}

Markus Roellig
  • 7,703
  • 2
  • 29
  • 53
4
functions={bsplinefunc1,bsplinefunc2,bsplinefunc3};

Outer[#1[#2] &, functions, Range[0, 1, .1]]

{{bsplinefunc1[0.], bsplinefunc1[0.1], bsplinefunc1[0.2],
bsplinefunc1[0.3], bsplinefunc1[0.4], bsplinefunc1[0.5],
bsplinefunc1[0.6], bsplinefunc1[0.7], bsplinefunc1[0.8],
bsplinefunc1[0.9], bsplinefunc1[1.]}, {bsplinefunc2[0.],
bsplinefunc2[0.1], bsplinefunc2[0.2], bsplinefunc2[0.3],
bsplinefunc2[0.4], bsplinefunc2[0.5], bsplinefunc2[0.6],
bsplinefunc2[0.7], bsplinefunc2[0.8], bsplinefunc2[0.9],
bsplinefunc2[1.]}, {bsplinefunc3[0.], bsplinefunc3[0.1],
bsplinefunc3[0.2], bsplinefunc3[0.3], bsplinefunc3[0.4],
bsplinefunc3[0.5], bsplinefunc3[0.6], bsplinefunc3[0.7],
bsplinefunc3[0.8], bsplinefunc3[0.9], bsplinefunc3[1.]}}

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
2
 functions = {bsf1, bsf2, bsf3} (* =  Array[BSplineFunction[RandomReal[1, {100}]] &, {3}] *);
 range = Range[0, 1, .1];
 Table[f /@ range, {f, functions}]
 Table[f[x], {f, functions}, {x, range}]

or

 # /@ range & /@ functions
kglr
  • 394,356
  • 18
  • 477
  • 896