g=Sin[5x-0.2]+0.3

n=4

B=Table[Binomial[n, i]*x^i*(1-x)^(n-i),{i,0,n}]
coef=Table[a[i],{i,0,n}]

f=B.coef

NN=100

r=Sum[((f-g)^2)/.{x->j/NN},{j,0,NN}];

parcD=Table[Simplify[D[r, coef[[i]]]], {i,1, Length[coef]}]

res=Solve[parcD==0][[1]]

F=f/.res

Plot[{g,F},{x, 0,1}]

f={Sum[a[i]*x^i,{i,0,2}],Sum[b[i]*x^i,{i,0,2}],Sum[c[i]*x^i,{i,0,2}]}

res=Solve[{(f[[1]]-f[[2]])/.{x->1},D[(f[[1]]-f[[2]]),x]/.{x->1},(f[[3]]-f[[2]])/.{x->3}}==0][[1]]

pros=f/.res

baze={D[pros, a[0]],D[pros, a[1]],D[pros, a[2]],D[pros, b[0]],D[pros, c[0]],D[pros, c[1]]}

Table[Show[Plot[baze[[i]][[1]],{x, 0,1}],Plot[baze[[i]][[2]],{x,1,3}],Plot[baze[[i]][[3]],{x,3,6}], PlotRange->All],{i,1,6}]

knots={0,0,0, 1, 3,3, 6,6,6}

p=2
m=Length[knots]-1

Plot[Evaluate[Table[BSplineBasis[{p,knots},i,t],{i,0,5}]],{t,0,6},Filling->Axis,PlotRange->Full,PlotTheme->"Scientific"]