© 2001 by CRC Press LLC
derived equation. In case that three points are given and the two selected functions
are f
1
(x) = x–1 and f
2
(x) = x
2
, then the interactive operation goes as follows:
In[2]: = Fit[{{1,2},{3,5},{4,13}}, {x–1, x^2}, x]
Out[2]: = –7.05263 (–1 + x) + 2.13158 x
Two other examples previously presented in the MATLAB applications can also
be considered and the results are:
In[3]: = (Fit[{{1,2}, {2,4}, {3,7}, {4,11}, {5,23}, {6,45}},
{x, x^2, Sin[x], Cos[x]}, x])
Out[3]: = –4.75756 x + 2.11159 x
2
– 0.986915 Cos[x] + 5.76573 Sin[x]
and
In[4]: = (Fit[{{1.4, 2.25}, {3.2, 15}, {4.8, 26.25}, {8, 33}, {10, 35}},
{Sin[Pi*x/20], Sin[3*Pi*x/20], Sin[5*Pi*x/20]}, x])
All of the results obtained here are in agreement with those presented earlier.
2.5 PROGRAM CUBESPLN — CURVE FITTING
WITH CUBIC SPLINE
If a set of N given points (X
i
,Y
i
) for i = 1, 2,…,N is to be fitted with a polynomial
of N–1 degree passing these points exactly, the polynomial curve will have many
fluctuations between data points as the number of points, N, increases. A popular
method for avoiding such over-fluctuation is to fit every two adjacent points with a
cubic equation and to impose continuity conditions at the point shared by two
neighboring cubic equations. This is like using a draftsman’s spline attempting to
pass through all of the N given points. It is known as cubic-spline curve fit. For a
typical interval of X, say X
i
to X
i + 1
, the cubic equation can be written as:
(1)
where a
i
, b
i
, c
i
, and d
i
are unknown coefficients. If there are N–1 intervals and each
interval is fitted by a cubic equation, the total number of unknown coefficients is
equal to 4(N–1). They are to be determined by the following conditions:
1. Each curve passes two specified points. The first and last specified points
are used once by the first and N-1st curves, respectively, whereas all
interior points are used twice by the two cubic curves meeting there. This
gives 2 + 2(N–2), or, 2N–2 conditions.
Out[4]:=
−
−
35 9251
20
1 19261
3
20
3 46705
5
20
.. .Sin
Pi x
Sin
Pi x
Sin
Pi x
YaX bX cXd
iiii
=+++
32