Mercurial > hg > octave-nkf
annotate scripts/polynomial/mkpp.m @ 9245:16f53d29049f
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 May 2009 10:46:00 -0400 |
parents | 1bf0ce0930be |
children | 31900e17b5f5 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2000, 2006, 2007, 2008, 2009 Paul Kienzle |
5824 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5824 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5824 | 18 |
19 ## -*- texinfo -*- | |
7650 | 20 ## @deftypefn {Function File} {@var{pp} =} mkpp (@var{x}, @var{p}) |
21 ## @deftypefnx {Function File} {@var{pp} =} mkpp (@var{x}, @var{p}, @var{d}) | |
5824 | 22 ## |
23 ## Construct a piece-wise polynomial structure from sample points | |
8494 | 24 ## @var{x} and coefficients @var{p}. The i-th row of @var{p}, |
5824 | 25 ## @code{@var{p} (@var{i},:)}, contains the coefficients for the polynomial |
26 ## over the @var{i}-th interval, ordered from highest to | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
27 ## lowest. There must be one row for each interval in @var{x}, so |
5824 | 28 ## @code{rows (@var{p}) == length (@var{x}) - 1}. |
29 ## | |
30 ## You can concatenate multiple polynomials of the same order over the | |
31 ## same set of intervals using @code{@var{p} = [ @var{p1}; @var{p2}; | |
32 ## @dots{}; @var{pd} ]}. In this case, @code{rows (@var{p}) == @var{d} | |
33 ## * (length (@var{x}) - 1)}. | |
34 ## | |
35 ## @var{d} specifies the shape of the matrix @var{p} for all except the | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
36 ## last dimension. If @var{d} is not specified it will be computed as |
6248 | 37 ## @code{round (rows (@var{p}) / (length (@var{x}) - 1))} instead. |
5824 | 38 ## |
39 ## @seealso{unmkpp, ppval, spline} | |
40 ## @end deftypefn | |
41 | |
42 function pp = mkpp (x, P, d) | |
43 if (nargin < 2 || nargin > 3) | |
6046 | 44 print_usage (); |
5824 | 45 endif |
46 pp.x = x(:); | |
47 pp.P = P; | |
48 pp.n = length (x) - 1; | |
49 pp.k = columns (P); | |
50 if (nargin < 3) | |
51 d = round (rows (P) / pp.n); | |
52 endif | |
53 pp.d = d; | |
6721 | 54 if (pp.n * prod (d) != rows (P)) |
5824 | 55 error ("mkpp: num intervals in x doesn't match num polynomials in P"); |
56 endif | |
57 endfunction | |
58 | |
59 %!demo # linear interpolation | |
60 %! x=linspace(0,pi,5)'; | |
61 %! t=[sin(x),cos(x)]; | |
62 %! m=diff(t)./(x(2)-x(1)); | |
63 %! b=t(1:4,:); | |
64 %! pp = mkpp(x, [m(:),b(:)]); | |
65 %! xi=linspace(0,pi,50); | |
6746 | 66 %! plot(x,t,"x",xi,ppval(pp,xi)); |
67 %! legend("control","interp"); |