polyBasis[m_]:=Map[LegendreP[#,2.0(x-0.5)]&,Range[0,m-1]]

edgeBasis[m_]:=Map[(Abs[x-#/(m-1)])&,Range[0,m-1]]

rawdat=Import["~/doc/professional/presentations/2025/ictp-saifr_colloquium/test.dat"];

testdata=Partition[rawdat[[1]],2];
as=rawdat[[2;;]];
Length[as]

Show[Plot[{Sin[2π x]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

Show[Plot[{Sin[2π x],Last[as].polyBasis[Length[Last[as]]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

Show[Plot[{Sin[2π x],as[[6]].polyBasis[Length[as[[6]]]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

Show[Plot[{Sin[2π x],as[[100]].polyBasis[Length[as[[100]]]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

(1/1000)Sum[(((#.polyBasis[Length[#]]-Sin[2π x]))^2),{x,0,1,1/1000}]&/@{as[[6]],as[[-1]]}

ListLogPlot[(1/1000)Sum[(((#.polyBasis[Length[#]]-Sin[2π x]))^2),{x,0,1,1/1000}]&/@Join[as[[;;Length[testdata]]],Reverse@as[[Length[testdata]+1;;]]],Joined->True,PlotRange->All]

Show[Plot[{Sin[2π x]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

Show[Plot[{Sin[2π x],Last[as].edgeBasis[Length[Last[as]]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

Show[Plot[{Sin[2π x],as[[6]].edgeBasis[Length[as[[6]]]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

Show[Plot[{Sin[2π x],as[[100]].edgeBasis[Length[as[[100]]]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

(1/1000)Sum[(((#.polyBasis[Length[#]]-Sin[2π x]))^2),{x,0,1,1/1000}]&/@{as[[6]],as[[-1]]}

ListPlot[(1/1000)Sum[(((#.edgeBasis[Length[#]]-Sin[2π x]))^2),{x,0,1,1/1000}]&/@Join[as[[2;;Length[testdata]]],Reverse[as[[1+Length[testdata];;]]]],Joined->True,PlotRange->All]

Show[Plot[{Sin[2π x],as2.polyBasis[Length[as2]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

Show[Plot[{Sin[2π x],as3.polyBasis[Length[as3]]},{x,0,1},PlotPoints->100],ListPlot[testdata,PlotStyle->Black]]

rawdat2=Import["~/doc/professional/presentations/2025/ictp-saifr_colloquium/test_abs.dat"];

testdata2=Partition[rawdat2[[1]],2];
as2=rawdat2[[2]];

Show[Plot[{Sin[2π x],as2.edgeBasis[Length[as2]]},{x,0,1},PlotPoints->100],ListPlot[testdata2,PlotStyle->Black]]