annotate scripts/polynomial/splinefit.m @ 21546:f7f97d7e9294

doc: Wrap m-file docstrings to 79 characters + newline (80 total). * isrecording.m, soundsc.m, delaunay3.m, cell2mat.m, cumtrapz.m, del2.m, inputParser.m, interp1.m, interp3.m, narginchk.m, profile.m, validateattributes.m, delaunayn.m, tsearchn.m, voronoin.m, brighten.m, cmunique.m, colorcube.m, imfinfo.m, imshow.m, edit.m, orderfields.m, run.m, warning_ids.m, ode23.m, ode45.m, odeget.m, integrate_adaptive.m, kahan.m, ode_struct_value_check.m, runge_kutta_23.m, fminunc.m, fsolve.m, fzero.m, pkg.m, build.m, specular.m, view.m, bar.m, barh.m, contour3.m, isosurface.m, line.m, pie.m, pie3.m, quiver3.m, scatter.m, scatter3.m, stem3.m, stemleaf.m, surfl.m, tetramesh.m, isfigure.m, mkpp.m, pchip.m, residue.m, splinefit.m, rmpref.m, unique.m, eigs.m, ilu.m, factor.m, factorial.m, gallery.m, hankel.m, histc.m, ols.m, finv.m, fpdf.m, kruskal_wallis_test.m, weekday.m: Wrap m-file docstrings to 79 characters + newline (80 total).
author Rik <rik@octave.org>
date Sun, 27 Mar 2016 15:50:01 -0700
parents 516bb87ea72e
children ecce63c99c3f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 2012-2015 Ben Abbott, Jonas Lundgren
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
2 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
3 ## This file is part of Octave.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
4 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
8 ## your option) any later version.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
9 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
13 ## General Public License for more details.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
14 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
18
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
19 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
20 ## @deftypefn {} {@var{pp} =} splinefit (@var{x}, @var{y}, @var{breaks})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
21 ## @deftypefnx {} {@var{pp} =} splinefit (@var{x}, @var{y}, @var{p})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
22 ## @deftypefnx {} {@var{pp} =} splinefit (@dots{}, "periodic", @var{periodic})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
23 ## @deftypefnx {} {@var{pp} =} splinefit (@dots{}, "robust", @var{robust})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
24 ## @deftypefnx {} {@var{pp} =} splinefit (@dots{}, "beta", @var{beta})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
25 ## @deftypefnx {} {@var{pp} =} splinefit (@dots{}, "order", @var{order})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
26 ## @deftypefnx {} {@var{pp} =} splinefit (@dots{}, "constraints", @var{constraints})
16489
36dba9be680b doc: Make documentation compatible with Texinfo 5.0 (bug #38392)
Amod Mulay <amodmulay1@gmail.com>
parents: 15082
diff changeset
27 ##
14620
cd375519eab0 doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
28 ## Fit a piecewise cubic spline with breaks (knots) @var{breaks} to the
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ## noisy data, @var{x} and @var{y}.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
30 ##
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ## @var{x} is a vector, and @var{y} is a vector or N-D array. If @var{y} is an
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
32 ## N-D array, then @var{x}(j) is matched to @var{y}(:,@dots{},:,j).
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
33 ##
21546
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20852
diff changeset
34 ## @var{p} is a positive integer defining the number of intervals along
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20852
diff changeset
35 ## @var{x}, and @var{p}+1 is the number of breaks. The number of points in
f7f97d7e9294 doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents: 20852
diff changeset
36 ## each interval differ by no more than 1.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
37 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
38 ## The optional property @var{periodic} is a logical value which specifies
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
39 ## whether a periodic boundary condition is applied to the spline. The
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14621
diff changeset
40 ## length of the period is @code{max (@var{breaks}) - min (@var{breaks})}.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
41 ## The default value is @code{false}.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
42 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
43 ## The optional property @var{robust} is a logical value which specifies
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
44 ## if robust fitting is to be applied to reduce the influence of outlying
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
45 ## data points. Three iterations of weighted least squares are performed.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
46 ## Weights are computed from previous residuals. The sensitivity of outlier
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
47 ## identification is controlled by the property @var{beta}. The value of
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
48 ## @var{beta} is restricted to the range, 0 < @var{beta} < 1. The default
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
49 ## value is @var{beta} = 1/2. Values close to 0 give all data equal
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
50 ## weighting. Increasing values of @var{beta} reduce the influence of
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
51 ## outlying data. Values close to unity may cause instability or rank
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
52 ## deficiency.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
53 ##
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
54 ## The fitted spline is returned as a piecewise polynomial, @var{pp}, and
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
55 ## may be evaluated using @code{ppval}.
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
56 ##
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
57 ## The splines are constructed of polynomials with degree @var{order}.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
58 ## The default is a cubic, @var{order}=3. A spline with P pieces has
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
59 ## P+@var{order} degrees of freedom. With periodic boundary conditions
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
60 ## the degrees of freedom are reduced to P.
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
61 ##
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
62 ## The optional property, @var{constaints}, is a structure specifying linear
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
63 ## constraints on the fit. The structure has three fields, @qcode{"xc"},
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16491
diff changeset
64 ## @qcode{"yc"}, and @qcode{"cc"}.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
65 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
66 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16491
diff changeset
67 ## @item @qcode{"xc"}
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
68 ## Vector of the x-locations of the constraints.
14620
cd375519eab0 doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
69 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16491
diff changeset
70 ## @item @qcode{"yc"}
16491
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
71 ## Constraining values at the locations @var{xc}.
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
72 ## The default is an array of zeros.
14620
cd375519eab0 doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
73 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16491
diff changeset
74 ## @item @qcode{"cc"}
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
75 ## Coefficients (matrix). The default is an array of ones. The number of
14620
cd375519eab0 doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents: 14551
diff changeset
76 ## rows is limited to the order of the piecewise polynomials, @var{order}.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
77 ## @end table
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
78 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
79 ## Constraints are linear combinations of derivatives of order 0 to
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
80 ## @var{order}-1 according to
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
81 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
82 ## @example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
83 ## @group
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
84 ## @tex
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
85 ## $cc(1,j) \cdot y(xc(j)) + cc(2,j) \cdot y\prime(xc(j)) + ... = yc(:,\dots,:,j)$.
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
86 ## @end tex
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
87 ## @ifnottex
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
88 ## cc(1,j) * y(xc(j)) + cc(2,j) * y'(xc(j)) + ... = yc(:,...,:,j).
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
89 ## @end ifnottex
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
90 ## @end group
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
91 ## @end example
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
92 ##
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
93 ## @seealso{interp1, unmkpp, ppval, spline, pchip, ppder, ppint, ppjumps}
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
94 ## @end deftypefn
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
95
16491
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
96 function pp = splinefit (x, y, breaks, varargin)
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
97 if (nargin > 3)
17386
6dbc866379e2 Replace cellfun() occurrences with faster code where possible.
Rik <rik@octave.org>
parents: 17281
diff changeset
98 n = cellfun ("isclass", varargin, "char");
16491
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
99 varargin(n) = lower (varargin(n));
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
100 try
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
101 props = struct (varargin{:});
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
102 catch
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
103 print_usage ();
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
104 end_try_catch
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
105 else
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
106 props = struct ();
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
107 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
108 fields = fieldnames (props);
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
109 for f = 1:numel (fields)
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
110 if (! any (strcmp (fields{f},
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
111 {"periodic", "robust", "beta", "order", "constraints"})))
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
112 error ("splinefit:invalidproperty",
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
113 "unrecognized property '%s'", fields{f});
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
114 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
115 endfor
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
116 args = {};
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
117 if (isfield (props, "periodic") && props.periodic)
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
118 args{end+1} = "p";
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
119 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
120 if (isfield (props, "robust") && props.robust)
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
121 args{end+1} = "r";
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
122 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
123 if (isfield (props, "beta"))
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
124 if (0 < props.beta && props.beta < 1)
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
125 args{end+1} = props.beta;
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
126 else
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
127 error ("splinefit:invalidbeta", "invalid beta parameter (0 < beta < 1)");
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
128 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
129 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
130 if (isfield (props, "order"))
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
131 if (props.order >= 0)
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
132 args{end+1} = props.order + 1;
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
133 else
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
134 error ("splinefit:invalidorder", "invalid order");
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
135 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
136 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
137 if (isfield (props, "constraints"))
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
138 args{end+1} = props.constraints;
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
139 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
140 if (nargin < 3)
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
141 print_usage ();
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
142 elseif (! isnumeric (breaks) || ! isvector (breaks))
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
143 print_usage ();
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
144 endif
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
145 pp = __splinefit__ (x, y, breaks, args{:});
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
146 endfunction
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
147
b10a23fe80bb doc: Tweak docstrings of functions changed for Texinfo 5.0 compatibility.
Rik <rik@octave.org>
parents: 16489
diff changeset
148
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
149 %!demo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
150 %! % Noisy data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
151 %! x = linspace (0, 2*pi, 100);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
152 %! y = sin (x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
153 %! % Breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
154 %! breaks = [0:5, 2*pi];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
155 %! % Fit a spline of order 5
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
156 %! pp = splinefit (x, y, breaks, "order", 4);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
157 %! clf ()
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
158 %! plot (x, y, "s", x, ppval (pp, x), "r", breaks, ppval (pp, breaks), "+r")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
159 %! xlabel ("Independent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
160 %! ylabel ("Dependent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
161 %! title ("Fit a piece-wise polynomial of order 4");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
162 %! legend ({"data", "fit", "breaks"})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
163 %! axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
164 %! ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
165
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
166 %!demo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
167 %! % Noisy data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
168 %! x = linspace (0,2*pi, 100);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
169 %! y = sin (x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
170 %! % Breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
171 %! breaks = [0:5, 2*pi];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
172 %! % Fit a spline of order 3 with periodic boundary conditions
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
173 %! pp = splinefit (x, y, breaks, "order", 2, "periodic", true);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
174 %! clf ()
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
175 %! plot (x, y, "s", x, ppval (pp, x), "r", breaks, ppval (pp, breaks), "+r")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
176 %! xlabel ("Independent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
177 %! ylabel ("Dependent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
178 %! title ("Fit a periodic piece-wise polynomial of order 2");
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
179 %! legend ({"data", "fit", "breaks"})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
180 %! axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
181 %! ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
182
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
183 %!demo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
184 %! % Noisy data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
185 %! x = linspace (0, 2*pi, 100);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
186 %! y = sin (x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
187 %! % Breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
188 %! breaks = [0:5, 2*pi];
14551
60ed9260399a Improve/correct documentation for splinefit.m
Ben Abbott <bpabbott@mac.com>
parents: 14531
diff changeset
189 %! % Constraints: y(0) = 0, y'(0) = 1 and y(3) + y"(3) = 0
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
190 %! xc = [0 0 3];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
191 %! yc = [0 1 0];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
192 %! cc = [1 0 1; 0 1 0; 0 0 1];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
193 %! con = struct ("xc", xc, "yc", yc, "cc", cc);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
194 %! % Fit a cubic spline with 8 pieces and constraints
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
195 %! pp = splinefit (x, y, 8, "constraints", con);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
196 %! clf ()
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
197 %! plot (x, y, "s", x, ppval (pp, x), "r", breaks, ppval (pp, breaks), "+r")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
198 %! xlabel ("Independent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
199 %! ylabel ("Dependent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
200 %! title ("Fit a cubic spline with constraints")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
201 %! legend ({"data", "fit", "breaks"})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
202 %! axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
203 %! ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
204
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
205 %!demo
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
206 %! % Noisy data
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
207 %! x = linspace (0, 2*pi, 100);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
208 %! y = sin (x) + 0.1 * randn (size (x));
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
209 %! % Breaks
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
210 %! breaks = [0:5, 2*pi];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
211 %! xc = [0 0 3];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
212 %! yc = [0 1 0];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
213 %! cc = [1 0 1; 0 1 0; 0 0 1];
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
214 %! con = struct ("xc", xc, "yc", yc, "cc", cc);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
215 %! % Fit a spline of order 6 with constraints and periodicity
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
216 %! pp = splinefit (x, y, breaks, "constraints", con, "order", 5, "periodic", true);
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
217 %! clf ()
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
218 %! plot (x, y, "s", x, ppval (pp, x), "r", breaks, ppval (pp, breaks), "+r")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
219 %! xlabel ("Independent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
220 %! ylabel ("Dependent Variable")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
221 %! title ("Fit a 5th order piece-wise periodic polynomial with constraints")
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
222 %! legend ({"data", "fit", "breaks"})
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
223 %! axis tight
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
224 %! ylim auto
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
225
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
226 %!shared xb, yb, x
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
227 %! xb = 0:2:10;
15082
902a8e27b2a2 splinefit.m: Increase tolerance for %!tests. Use rand, not randn, for generating test data.
Rik <rik@octave.org>
parents: 15077
diff changeset
228 %! yb = 2*rand (size (xb)) - 1;
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
229 %! x = 0:0.1:10;
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
230
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
231 %!test
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
232 %! y = interp1 (xb, yb, x, "linear");
15082
902a8e27b2a2 splinefit.m: Increase tolerance for %!tests. Use rand, not randn, for generating test data.
Rik <rik@octave.org>
parents: 15077
diff changeset
233 %! assert (ppval (splinefit (x, y, xb, "order", 1), x), y, 15 * eps ());
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
234 %!test
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
235 %! y = interp1 (xb, yb, x, "spline");
15082
902a8e27b2a2 splinefit.m: Increase tolerance for %!tests. Use rand, not randn, for generating test data.
Rik <rik@octave.org>
parents: 15077
diff changeset
236 %! assert (ppval (splinefit (x, y, xb, "order", 3), x), y, 15 * eps ());
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
237 %!test
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
238 %! y = interp1 (xb, yb, x, "spline");
15082
902a8e27b2a2 splinefit.m: Increase tolerance for %!tests. Use rand, not randn, for generating test data.
Rik <rik@octave.org>
parents: 15077
diff changeset
239 %! assert (ppval (splinefit (x, y, xb), x), y, 15 * eps ());
14509
a88f8e4fae56 New Function, splinefit.m
Ben Abbott <bpabbott@mac.com>
parents:
diff changeset
240