Function Repository Resource:

PolynomialToBSplineCurve

Source Notebook

Make a B-spline representation of a polynomial over an interval

Contributed by: Jan Mangaldan

ResourceFunction["PolynomialToBSplineCurve"][p,{x,xmin,xmax}]

generates a BSplineCurve representation of the polynomial p as a function of x from xmin to xmax.

Details

ResourceFunction["PolynomialToBSplineCurve"] treats the variable x as local, effectively using Block.
ResourceFunction["PolynomialToBSplineCurve"] has attribute HoldAll and evaluates p only after assigning specific numerical values to x.
In some cases, it may be more efficient to use Evaluate to evaluate p symbolically before specific numerical values are assigned to x.

Examples

Basic Examples (1) 

Use PolynomialToBSplineCurve to plot a polynomial:

In[1]:=
Graphics[ResourceFunction["PolynomialToBSplineCurve"][
  x^3 - 2 x - 5, {x, -1, 3}], AspectRatio -> 1/GoldenRatio, Axes -> True]
Out[1]=

Scope (2) 

Use a style similar to Plot:

In[2]:=
Graphics[{Directive[ColorData[97, 1], AbsoluteThickness[1.6]], ResourceFunction["PolynomialToBSplineCurve"][
   HermiteH[7, x], {x, -1, 2}]}, AspectRatio -> 1/GoldenRatio, Axes -> True]
Out[2]=

Plot multiple polynomials:

In[3]:=
Graphics[MapIndexed[{ColorData[97] @@ #2, #1} &, ResourceFunction[
   "PolynomialToBSplineCurve"][{LegendreP[6, x], ChebyshevT[6, x], ChebyshevU[6, x]}, {x, -1, 1}]], AspectRatio -> 1/GoldenRatio, Axes -> True, PlotRange -> {-1.5, 1.5}]
Out[3]=

Properties and Relations (2) 

PolynomialToBSplineCurve returns a BSplineCurve object:

In[4]:=
ResourceFunction["PolynomialToBSplineCurve"][
  x^3 - 1, {x, -1, 1}] // Head
Out[4]=

Using PolynomialToBSplineCurve in Graphics usually gives results with a smaller ByteCount:

In[5]:=
p1 = Plot[LaguerreL[7, 11/5, x], {x, -1, 5}, PlotRange -> All]
Out[5]=
In[6]:=
p2 = Graphics[{Directive[ColorData[97, 1], AbsoluteThickness[1.6]], ResourceFunction["PolynomialToBSplineCurve"][
    LaguerreL[7, 11/5, x], {x, -1, 5}]}, AspectRatio -> 1/GoldenRatio,
   Axes -> True]
Out[6]=
In[7]:=
ByteCount /@ {p1, p2}
Out[7]=

Version History

  • 1.0.0 – 07 July 2021

Related Resources

License Information