2
$\begingroup$

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.

$\endgroup$
4
$\begingroup$

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

$\endgroup$
4
$\begingroup$
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.]}}

$\endgroup$
2
$\begingroup$
 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
$\endgroup$

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.