Mercurial > octave-nkf
comparison scripts/polynomial/mkpp.m @ 5824:448f9982e7fb
[project @ 2006-05-19 06:53:31 by jwe]
author | jwe |
---|---|
date | Fri, 19 May 2006 06:53:31 +0000 |
parents | |
children | 34f96dd5441b |
comparison
equal
deleted
inserted
replaced
5823:080c08b192d8 | 5824:448f9982e7fb |
---|---|
1 ## Copyright (C) 2000 Paul Kienzle | |
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 | |
7 ## the Free Software Foundation; either version 2, or (at your option) | |
8 ## any later version. | |
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 | |
16 ## along with Octave; see the file COPYING. If not, write to the Free | |
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
18 ## 02110-1301, USA. | |
19 | |
20 ## -*- texinfo -*- | |
21 ## @deftypefn {Function File} {@var{pp} = } mkpp (@var{x}, @var{p}) | |
22 ## @deftypefnx {Function File} {@var{pp} = } mkpp (@var{x}, @var{p}, @var{d}) | |
23 ## | |
24 ## Construct a piece-wise polynomial structure from sample points | |
25 ## @var{x} and coefficients @var{p}. The ith row of @var{p}, | |
26 ## @code{@var{p} (@var{i},:)}, contains the coefficients for the polynomial | |
27 ## over the @var{i}-th interval, ordered from highest to | |
28 ## lowest. There must be one row for each interval in @var{x}, so | |
29 ## @code{rows (@var{p}) == length (@var{x}) - 1}. | |
30 ## | |
31 ## You can concatenate multiple polynomials of the same order over the | |
32 ## same set of intervals using @code{@var{p} = [ @var{p1}; @var{p2}; | |
33 ## @dots{}; @var{pd} ]}. In this case, @code{rows (@var{p}) == @var{d} | |
34 ## * (length (@var{x}) - 1)}. | |
35 ## | |
36 ## @var{d} specifies the shape of the matrix @var{p} for all except the | |
37 ## last dimension. If @var{d} is not specified it will be computed as | |
38 ## @code{round (rows (@var{p}) / (length (@var{x}) - 1)) instead. | |
39 ## | |
40 ## @seealso{unmkpp, ppval, spline} | |
41 ## @end deftypefn | |
42 | |
43 function pp = mkpp (x, P, d) | |
44 if (nargin < 2 || nargin > 3) | |
45 usage ("pp = mkpp(x,P,d)"); | |
46 endif | |
47 pp.x = x(:); | |
48 pp.P = P; | |
49 pp.n = length (x) - 1; | |
50 pp.k = columns (P); | |
51 if (nargin < 3) | |
52 d = round (rows (P) / pp.n); | |
53 endif | |
54 pp.d = d; | |
55 if (pp.n*d != rows (P)) | |
56 error ("mkpp: num intervals in x doesn't match num polynomials in P"); | |
57 endif | |
58 endfunction | |
59 | |
60 %!demo # linear interpolation | |
61 %! x=linspace(0,pi,5)'; | |
62 %! t=[sin(x),cos(x)]; | |
63 %! m=diff(t)./(x(2)-x(1)); | |
64 %! b=t(1:4,:); | |
65 %! pp = mkpp(x, [m(:),b(:)]); | |
66 %! xi=linspace(0,pi,50); | |
67 %! plot(x,t,"x;control;",xi,ppval(pp,xi),";interp;"); |