# Integration along BSpline

**URL:** <https://community.wolfram.com/t/integration-along-bspline/3556>\
**Category:** Questions\
**Tags:** mathematica, calculus, numerical-computation\
**Created:** [October 6, 2014, 3:45pm UTC](https://community.wolfram.com/t/integration-along-bspline/3556 "2014-10-06T15:45:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopherpurcell](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/christopherpurcell/32/1616_2.png) [@christopherpurcell](https://community.wolfram.com/u/christopherpurcell)\
**Post date:** [October 6, 2014, 3:45pm UTC](https://community.wolfram.com/t/integration-along-bspline/3556/1 "2014-10-06T15:45:17Z")

</div>

I need to integrate along a parametric space curve defined by some data points. Here is a simple example that works in Version 10.

```
circle = Table[{Cos[\[Pi] t ], Sin[\[Pi] t ]}, {t, 0, 1, .1}];
interp[u_] := {
   ListInterpolation[circle[[All, 1]], {{0, 1}}][u], 
   ListInterpolation[circle[[All, 2]], {{0, 1}}][u]};
Show[Graphics[Point[circle]], ParametricPlot[interp[x], {x, 0, 1}]]
NIntegrate[
  interp[x], {x, 0, 1}] (* returns {0,1/Pi} as expected *)

```

However, if I repeat this example with BSplineFunction providing the interpolation, the integration fails, because it thinks BSplineFunction is not numeric.

```
circle = Table[{Cos[\[Pi] t ], Sin[\[Pi] t ]}, {t, 0, 1, .1}];
Show[Graphics[Point[circle]], 
 ParametricPlot[BSplineFunction[circle][t], {t, 0, 1}]]
 NIntegrate[ 
 BSplineFunction[circle][t], {t, 0, 
  1}] (* fails with NIntegrate::inum *)

```

I have tried my usual bag of tricks on this without any luck. Any hints on getting integration to work along a BSpline would be appreciated.

---

<div class="post-metadata">

**Author:** ![iliang](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/iliang/32/11263_2.png) [@iliang](https://community.wolfram.com/u/iliang)\
**Post date:** [October 6, 2014, 4:31pm UTC](https://community.wolfram.com/t/integration-along-bspline/3556/2 "2014-10-06T16:31:29Z")

</div>

In[3]:= circle = Table[{Cos[[Pi] t], Sin[[Pi] t]}, {t, 0, 1, .1}];  
bsplinefunction = BSplineFunction[circle];  
int1[t\_?NumericQ] := First[bsplinefunction[t]];  
int2[t\_?NumericQ] := Last[bsplinefunction[t]];  
NIntegrate[{int1[t], int2[t]}, {t, 0, 1}, AccuracyGoal → 10]

```
Out[7]= {2.77556*10^-17, 0.713855}

```

---

<div class="post-metadata">

**Author:** ![christopherpurcell](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/christopherpurcell/32/1616_2.png) [@christopherpurcell](https://community.wolfram.com/u/christopherpurcell)\
**Post date:** [October 6, 2014, 5:20pm UTC](https://community.wolfram.com/t/integration-along-bspline/3556/3 "2014-10-06T17:20:39Z")

</div>

My earliest failed attempt was:

```
circle = Table[{Cos[\[Pi] t], Sin[\[Pi] t]}, {t, 0, 1, .1}];
splat[t_?NumericQ] := BSplineFunction[circle][t];
NIntegrate[splat[t], {t, 0, 1}]  

```

So your ingenious splitting into parts was not something I would have tried. Well done.

This behavior of BSplineFunction is not as elegant as it could be.

---

<div class="post-metadata">

**Author:** ![Vitaliyk](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vitaliyk/32/45591_2.png) [@Vitaliyk](https://community.wolfram.com/u/Vitaliyk)\
**Post date:** [October 6, 2014, 6:23pm UTC](https://community.wolfram.com/t/integration-along-bspline/3556/4 "2014-10-06T18:23:09Z")

</div>

Have you seen this post? - [Computing arch length of a spline curve](https://wolfram.discourse.group/t/115/1)

---

<div class="post-metadata">

**Author:** ![christopherpurcell](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/christopherpurcell/32/1616_2.png) [@christopherpurcell](https://community.wolfram.com/u/christopherpurcell)\
**Post date:** [October 7, 2014, 4:39pm UTC](https://community.wolfram.com/t/integration-along-bspline/3556/5 "2014-10-07T16:39:16Z")

</div>

Yes and it suggested I could use NIntegrate along the BSpline. The post contains the code (simplified, by removing the derivative):

```
pts = {{1, 1}, {2, -1}, {3, 0}, {2, 1}, {1, 0}};
f = BSplineFunction[pts];
NIntegrate[Norm[f[t]], {t, 0, 1}] (* works *)

```

but a further simplification (to a vector integrand), fails;

```
 NIntegrate[ 
     f[t], {t, 0, 1}] (* fails with NIntegrate::inum *)  

```

NIntegrate can handle vector integrands, so NIntegrate must not know that the head BSplineFunction can return a vector.  
When the BSpline is working on one dimensional data, NIntegrate works fine.

```
pts = { 1, 2, 3, 2, 1};
f = BSplineFunction[pts];
NIntegrate[f[t], {t, 0, 1}] (* works *)

```
