1
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
2
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
4
<LANGUAGE>eng</LANGUAGE>
5
<TITLE>lsq_splin</TITLE>
6
<TYPE>Scilab Function</TYPE>
7
<DATE>February 2004</DATE>
8
<SHORT_DESCRIPTION name="lsq_splin">weighted least squares cubic spline fitting</SHORT_DESCRIPTION>
11
<CALLING_SEQUENCE_ITEM> [y, d] = lsq_splin(xd, yd [, wd], x)</CALLING_SEQUENCE_ITEM>
17
<PARAM_NAME>xd, yd</PARAM_NAME>
19
<SP>: vectors of the same size, datas to be fitted by a cubic spline</SP>
23
<PARAM_NAME>wd</PARAM_NAME>
25
<SP>: (optionnal) a vector of same format than <VERB>xd</VERB> and <VERB>yd</VERB>,
26
weights of the least square fit.</SP>
30
<PARAM_NAME>x</PARAM_NAME>
32
<SP>: a strictly increasing (row or column) vector, breakpoints of the
37
<PARAM_NAME>y, d</PARAM_NAME>
39
<SP>: vectors of same format than <VERB>x</VERB>, the triplet (x,y,d) defines the approximated
48
This function computes an approximated cubic spline <EM>s</EM> for the datas
49
<VERB>xd, yd, wd</VERB> (in the following <EM>m</EM> is supposed to be the
50
length of these vectors) and from a choice of the spline breakpoints <VERB>x</VERB>
51
(for instance if you want n breakpoints uniformly choosen you may use
52
<TT>x=linspace(min(xd),max(xd),n))</TT>). If <EM>S</EM> is the space of all
53
cubic splines functions with breakpoints <EM>x1 < x2 < ... < xn</EM> then
54
the resulting spline <EM>s</EM> is such that:
59
/ wd(k) (s(xd(k)) - yd(k)) <= / wd(k) (f(xd(k)) - yd(k))
63
<P> for all <EM>f in S</EM>, i.e. realizes the minimum of the sum of the squared errors
64
over all functions of <EM>S</EM>.
67
The spline <EM>s</EM> is completly defined by the triplet <VERB>(x,y,d)</VERB>
68
(<VERB>y</VERB> and <VERB>d</VERB> are the vectors of the spline ordinates and
69
first derivatives at the xi 's : <EM>yi=s(xi)</EM> and <EM>di=s'(xi)</EM>) and
70
its evaluation at some points must be done by the <LINK>interp</LINK> function.
74
<SECTION label="Remarks">
75
<P> When <VERB>wd</VERB> is not given, all the points have the same weight 1.</P>
76
<P> A point <EM>(xd(k),yd(k))</EM> is considered in the fit if <EM>xd(k) in [x1,xn]
77
and wd(k) > 0</EM>. In particular you can put a null (or even negative) weight to
78
all data points you want to ignore in the fitting. When the total number of points
79
taken into account in the fit procedure is (strictly) less than 4 an error is issued.
81
<P> The vector <VERB>xd</VERB> do not need to be in increasing order.
83
<P> Depending on the number and on the positions of the <EM>xd(k)</EM> 's and on the choice
84
of the <EM>x(i)</EM> 's there may be several solutions but only one is selected. When this
85
occurs a warning message is displayed in the Scilab command window. This function is intended
86
to be used when <EM>m</EM> is much larger than <EM>n</EM> and in this case no such problem
91
// this is an artifical example where the datas xd and yd
92
// are build from a perturbed sin function
94
sigma = 0.1; // standard deviation of the gaussian noise
95
m = 200; // number of experimental points
96
xd = linspace(a,b,m)';
97
yd = sin(xd) + grand(xd,"nor",0,sigma);
99
n = 6; // number of breakpoints
100
x = linspace(a,b,n)';
102
// compute the spline
103
[y, d] = lsq_splin(xd, yd, x); // use equal weights
107
ys = interp(xd, x, y, d);
109
plot2d(xd,[ye yd ys],style=[2 -2 3], ...
110
leg="exact function@experimental measures (gaussian perturbation)@fitted spline")
111
xtitle("a least square spline")
125
<AUTHORS_ITEM> C. De Boor, A.H. Morris (code from the NSWC fortran lib)</AUTHORS_ITEM>
126
<AUTHORS_ITEM> B. Pincon (scilab interface and slight modifications)</AUTHORS_ITEM>