Solutions

In[24]:=

(*1*)DataA = ReadList["c://documents and settings//yliopisto//desktop//data.txt", {Number, Number}]

Out[24]=

{{1, 2}, {2, 4}, {3, 7}, {4, 7}, {5, 9}, {6, 10}, {7, 9}, {8, 11}, {9, 10}, {10, 12}}

In[25]:=

(*2*)intf = Interpolation[DataA]

Out[25]=

InterpolatingFunction[{{1, 10}}, <>]

In[27]:=

(*3*)Plot[intf[x], {x, 1, 6}, PlotRangeAll]

[Graphics:../HTMLFiles/ex03_solutions_54.gif]

Out[27]=

⁃Graphics⁃

The spline interpolation add-on package must be loaded before using it. There are three types of spline interpolating functions. We'll be primarily concerned of the cubic spline. Note the range of the interpolating spline. This is not the range of x or y, but of some parameter which gives the graph interpolating DataA as a parametric plot. It always starts from zero and the end point is the number of data points. Note that the usual graph {x,y[x]} can be presented as a parametric graph {x[t],y[t]} with x[t]=t.

In[28]:=

(*4*)<<NumericalMath`SplineFit`splf = SplineFit[DataA, Cubic]

Out[29]=

SplineFunction[Cubic,  {0., 9.} , <>]

In[30]:=

(*5*)ParametricPlot[splf[x], {x, 0, 5}]

[Graphics:../HTMLFiles/ex03_solutions_59.gif]

Out[30]=

⁃Graphics⁃


Created by Mathematica  (April 10, 2007) Valid XHTML 1.1!