(*Exploring splines*)

Needs["Splines`"]

F[x_]:=1/(1+25*x*x) (*define Runge's function*)

a=-1.0;b=1.0  (*define the interpolating interval*)

plotfunction=Plot[F[x],{x,a,b},PlotStyle->{Hue[1],Thickness[0.01]},PlotLabel->"Original function",DisplayFunction->Identity]

n=16;h=(b-a)/n;(*define knots*)
data=Table[N[{x,F[x]}],{x,a,b,h}] (*produce data points at each knot*)

(*Uncomment below to try spline fit for a parametric curve*)
(*Also,set a=-3.0 b=3.0 above*)

(*
data=Table[N[{Sin[t],Cos[3t]}],{t,a,b,h}] (*parametric curve*) 

plotfunction=ParametricPlot[{Sin[t],Cos[3t]},{t,a,b},PlotStyle->{Hue[1],Thickness[0.005]},PlotLabel->"A parametric curve"]
*) 

plotdata=ListPlot[data,PlotLabel->"Data points",PlotStyle->{PointSize[Large],Black}]

fit=SplineFit[data,Cubic] (*Do the Cubic spline interpolation*)


plotfit=ParametricPlot[fit[t],{t,0,n},PlotStyle->{Hue[0.5],Thickness[0.005]},PlotLabel->"Cubic spline",DisplayFunction->Identity]

(*Show all graphs at once*)
Show[plotfunction,plotdata,plotfit,PlotLabel->"red - original f(x), blue - Cubic spline, black - nodes (sample points)",DisplayFunction->$DisplayFunction,PlotRange->All]


(*Print the value of the spline at the leftmost knot.Output format {x,y}*)

(*You may need this for the homework*)

Print["value of the spline at the leftmost knot. Format (x, y) "]
Print[fit[0.0]]
Print["--------------------------"]

(*And at a point just a bit to the right*)Print["value of the spline 0.01 to the right of it. Format (x,y)"]
Print[fit[0.01]]

Clear[data]

Clear[fit]