Mercurial > hg > octave-lyh
annotate scripts/polynomial/ppder.m @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | 614505385171 |
children | f3d52523cde1 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
1 ## Copyright (C) 2008-2012 VZLU Prague, a.s., Czech Republic |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
2 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
4 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published by |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 ## (at your option) any later version. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
9 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 ## This program is distributed in the hope that it will be useful, |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 ## GNU General Public License for more details. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11536
diff
changeset
|
14 ## |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 ## along with this software; see the file COPYING. If not, see |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
20 ## @deftypefn {Function File} {ppd =} ppder (pp) |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
21 ## @deftypefnx {Function File} {ppd =} ppder (pp, m) |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13258
diff
changeset
|
22 ## Compute the piecewise @var{m}-th derivative of a piecewise polynomial |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
23 ## struct @var{pp}. If @var{m} is omitted the first derivative is calculated. |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
24 ## @seealso{mkpp, ppval, ppint} |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 ## @end deftypefn |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
27 function ppd = ppder (pp, m) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
28 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
29 if ((nargin < 1) || (nargin > 2)) |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 print_usage (); |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
31 elseif (nargin == 1) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
32 m = 1; |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
34 |
13258
be74491c20e8
Correct typo in input validation of polynomial functions (Bug #33252)
Rik <octave@nomad.inbox5.com>
parents:
12608
diff
changeset
|
35 if (! (isstruct (pp) && strcmp (pp.form, "pp"))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
36 error ("ppder: PP must be a structure"); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 endif |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 [x, p, n, k, d] = unmkpp (pp); |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
40 |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
41 if (k - m <= 0) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
42 x = [x(1) x(end)]; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
43 pd = zeros (prod (d), 1); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 else |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
45 f = k : -1 : 1; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
46 ff = bincoeff (f, m + 1) .* factorial (m + 1) ./ f; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
47 k -= m; |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
48 pd = p(:,1:k) * diag (ff(1:k)); |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 endif |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
50 |
9976
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 ppd = mkpp (x, pd, d); |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
52 endfunction |
702b998698ea
implement ppder, ppint, ppjmups
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 |
12608
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
54 %!shared x,y,pp,ppd |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
55 %! x=0:8;y=[x.^2;x.^3+1];pp=spline(x,y); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
56 %! ppd=ppder(pp); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
57 %!assert(ppval(ppd,x),[2*x;3*x.^2],1e-14) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
58 %!assert(ppd.order,3) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
59 %! ppd=ppder(pp,2); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
60 %!assert(ppval(ppd,x),[2*ones(size(x));6*x],1e-14) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
61 %!assert(ppd.order,2) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
62 %! ppd=ppder(pp,3); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
63 %!assert(ppd.order,1) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
64 %!assert(ppd.pieces,8) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
65 %!assert(size(ppd.coefs),[16,1]) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
66 %! ppd=ppder(pp,4); |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
67 %!assert(ppd.order,1) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
68 %!assert(ppd.pieces,1) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
69 %!assert(size(ppd.coefs),[2,1]) |
59e2460acae1
make piecewise polynomial (pp) functions more compatible
Kai Habel <kai.habel@gmx.de>
parents:
12575
diff
changeset
|
70 %!assert(ppval(ppd,x),zeros(size(y)),1e-14) |