Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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.]}}

share|improve this answer
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.]}}

share|improve this answer
 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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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