# B-Spline use

Hi everyone,

I am having troubling using the BSpline function from NGSolve.
Running with a simple test case with the function i want to interpolate being of the form f(x) = cos(2x). I find with this code (duplicating initial and end points)

Npoints=10
x_lin = np.linspace(np.pi,2np.pi,Npoints)
y=myfun(x_lin)
plt.figure()
x_out=np.linspace(np.pi,2
np.pi,1000)

orders = [1,2,3]
plt.plot(x_out,myfun(x_out),label=“Data”)
for order in orders:
xs=
ys=
# Duplicate start and end points according to degree

``````xs=xs+[x_lin[0]]
ys=ys+[y[0]]

xs=xs+x_lin.tolist()
ys=ys+y.tolist()

xs=xs+[x_lin[Npoints-1]]
ys=ys+[y[Npoints-1]]

print(xs,ys)
x_list=xs
y_list=ys

spline = BSpline(order,  x_list, y_list)
``````

simple_spline.pdf (11.4 KB)

Where there seems to be a slight shift of x values associated with higher orders.
I did look around the forums and there was a suggestion to duplicate the initial and end points according to the order, which I’ve done for orders 1,2,3 below

x_lin = np.linspace(np.pi,2*np.pi,Npoints)
y=myfun(x_lin)

plt.figure()
x_out=np.linspace(np.pi,2*np.pi,1000)

plt.plot(x_out,myfun(x_out),label=“Data”)
for Order in [1,2,3]:
xs=
ys=
# Duplicate start and end points according to degree

``````xs=xs+[x_lin[0]]
ys=ys+[y[0]]
if Order>=2:
ys=ys+[y[0]]
xs=xs+[x_lin[0]]
if Order==3:
ys=ys+[y[0]]
xs=xs+[x_lin[0]]

xs=xs+x_lin.tolist()
ys=ys+y.tolist()

xs=xs+[x_lin[Npoints-1]]
ys=ys+[y[Npoints-1]]
if Order>=2:
ys=ys+[y[Npoints-1]]
xs=xs+[x_lin[Npoints-1]]
if Order==3:
ys=ys+[y[Npoints-1]]
xs=xs+[x_lin[Npoints-1]]

print(xs,ys)
x_list=xs
y_list=ys

spline = BSpline(Order,  x_list, y_list)
``````

but I still yield the same result