1 ## Copyright (C) 2009-2012 Tony Richardson, Jaroslav Hajek
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} polyaffine (@var{f}, @var{mu})
21 ## Return the coefficients of the polynomial vector @var{f} after an affine
22 ## transformation. If @var{f} is the vector representing the polynomial f(x),
23 ## then @code{@var{g} = polyaffine (@var{f}, @var{mu})} is the vector
27 ## g(x) = f( (x - @var{mu}(1)) / @var{mu}(2) )
30 ## @seealso{polyval, polyfit}
34 function g = polyaffine (f, mu)
41 error ("polyaffine: F must be a vector");
44 if (! isvector (mu) || length (mu) != 2)
45 error ("polyaffine: MU must be a two-element vector");
50 ## Ensure that f is a row vector
59 g = g ./ (mu(2) .^ (lf-1:-1:0));
64 w = (-mu(1)) .^ (0:lf-1);
66 g = g(ii) * (toeplitz (w) .* pascal (lf, -1));
74 %! f = [1/5 4/5 -7/5 -2];
75 %! g = polyaffine (f, [1, 1.2]);
76 %! x = linspace (-4, 4, 100);
77 %! plot(x, polyval (f, x), x, polyval (g, x));
78 %! legend ("original", "affine");
79 %! axis ([-4 4 -3 5]);
83 %! f = [1/5 4/5 -7/5 -2];
85 %! g = polyaffine (f, mu);
86 %! x = linspace (-4, 4, 100);
87 %! assert (polyval (f, x, [], mu), polyval (g, x), 1e-10);