annotate scripts/general/bicubic.m @ 11523:fd0a3ac60b0e

update copyright notices
author John W. Eaton <jwe@octave.org>
date Fri, 14 Jan 2011 05:47:45 -0500
parents eb9e0b597d61
children c792872f8942
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11470
diff changeset
1 ## Copyright (C) 2005-2011 Hoxide Ma
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
2 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
4 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
8 ## your option) any later version.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
9 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6702
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
18
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
20 ## @deftypefn {Function File} {@var{zi} =} bicubic (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}, @var{extrapval})
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
21 ##
6653
673686daec87 [project @ 2007-05-22 15:36:09 by jwe]
jwe
parents: 6448
diff changeset
22 ## Return a matrix @var{zi} corresponding to the bicubic
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
23 ## interpolations at @var{xi} and @var{yi} of the data supplied
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
24 ## as @var{x}, @var{y} and @var{z}. Points outside the grid are set
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8507
diff changeset
25 ## to @var{extrapval}.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
26 ##
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
27 ## See @url{http://wiki.woodpecker.org.cn/moin/Octave/Bicubic}
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
28 ## for further information.
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
29 ## @seealso{interp2}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
30 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
31
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
32 ## Bicubic interpolation method.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
33 ## Author: Hoxide Ma <hoxide_dirac@yahoo.com.cn>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
34
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
35 function zi = bicubic (x, y, z, xi, yi, extrapval, spline_alpha)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
36
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
37 if (nargin < 1 || nargin > 7)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
38 print_usage ();
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
39 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
40
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
41 if (nargin == 7 && isscalar(spline_alpha))
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
42 a = spline_alpha
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
43 else
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
44 a = 0.5;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
45 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
46
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
47 if (nargin < 6)
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
48 extrapval = NaN;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
49 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
50
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
51 if (isa (x, "single") || isa (y, "single") || isa (z, "single")
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
52 || isa (xi, "single") || isa (yi, "single"))
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
53 myeps = eps("single");
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
54 else
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
55 myeps = eps;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
56 endif
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
57
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
58 if (nargin <= 2)
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
59 ## bicubic (z) or bicubic (z, 2)
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
60 if (nargin == 1)
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
61 n = 1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
62 else
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
63 n = y;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
64 endif
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
65 z = x;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
66 x = [];
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
67 [rz, cz] = size (z);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
68 s = linspace (1, cz, (cz-1)*pow2(n)+1);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
69 t = linspace (1, rz, (rz-1)*pow2(n)+1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
70 elseif (nargin == 3)
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
71 if (! isvector (x) || ! isvector (y))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
72 error ("bicubic: XI and YI must be vector");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
73 endif
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
74 s = y;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
75 t = z;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
76 z = x;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
77 [rz, cz] = size (z);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
78 elseif (nargin == 5 || nargin == 6)
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
79 [rz, cz] = size (z) ;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
80 if (isvector (x) && isvector (y))
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
81 if (rz != length (y) || cz != length (x))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
82 error ("bicubic: length of X and Y must match the size of Z");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
83 endif
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
84 elseif (size_equal (x, y) && size_equal (x, z))
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
85 x = x(1,:);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
86 y = y(:,1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
87 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
88 error ("bicubic: X, Y and Z must be equal size matrices of same size");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
89 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
90
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
91 ## Mark values outside the lookup table.
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
92 xfirst_ind = find (xi < x(1));
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
93 xlast_ind = find (xi > x(cz));
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
94 yfirst_ind = find (yi < y(1));
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
95 ylast_ind = find (yi > y(rz));
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
96 ## Set value outside the table preliminary to min max index.
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
97 xi(xfirst_ind) = x(1);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
98 xi(xlast_ind) = x(cz);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
99 yi(yfirst_ind) = y(1);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
100 yi(ylast_ind) = y(rz);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
101
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
102
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
103 x = reshape (x, 1, cz);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
104 x(cz) *= 1 + sign (x(cz))*myeps;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
105 if (x(cz) == 0)
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
106 x(cz) = myeps;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
107 endif;
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
108 xi = reshape (xi, 1, length (xi));
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
109 [m, i] = sort ([x, xi]);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
110 o = cumsum (i <= cz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
111 xidx = o(find (i > cz));
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
112
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
113 y = reshape (y, rz, 1);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
114 y(rz) *= 1 + sign (y(rz))*myeps;
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
115 if (y(rz) == 0)
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
116 y(rz) = myeps;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
117 endif;
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
118 yi = reshape (yi, length (yi), 1);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
119 [m, i] = sort ([y; yi]);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
120 o = cumsum (i <= rz);
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
121 yidx = o([find(i > rz)]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
122
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
123 ## Set s and t used follow codes.
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
124 s = xidx + ((xi .- x(xidx))./(x(xidx+1) .- x(xidx)));
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
125 t = yidx + ((yi - y(yidx))./(y(yidx+1) - y(yidx)));
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
126 else
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
127 print_usage ();
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
128 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
129
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
130 if (rz < 3 || cz < 3)
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
131 error ("bicubic: Z at least a 3 by 3 matrices");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
132 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
133
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
134 inds = floor (s);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
135 d = find (s == cz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
136 s = s - floor (s);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
137 inds(d) = cz-1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
138 s(d) = 1.0;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
139
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
140 d = [];
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
141 indt = floor (t);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
142 d = find (t == rz);
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
143 t = t - floor (t);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
144 indt(d) = rz-1;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
145 t(d) = 1.0;
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
146 d = [];
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
147
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
148 p = zeros (size (z) + 2);
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
149 p(2:rz+1,2:cz+1) = z;
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
150 p(1,:) = (6*(1-a))*p(2,:) - 3*p(3,:) + (6*a-2)*p(4,:);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
151 p(rz+2,:) = (6*(1-a))*p(rz+1,:) - 3*p(rz,:) + (6*a-2)*p(rz-1,:);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
152 p(:,1) = (6*(1-a))*p(:,2) - 3*p(:,3) + (6*a-2)*p(:,4);
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
153 p(:,cz+2) = (6*(1-a))*p(:,cz+1) - 3*p(:,cz) + (6*a-2)*p(:,cz-1);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
154
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
155 ## Calculte the C1(t) C2(t) C3(t) C4(t) and C1(s) C2(s) C3(s) C4(s).
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
156 t2 = t.*t;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
157 t3 = t2.*t;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
158
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
159 ct0 = -a .* t3 + (2 * a) .* t2 - a .* t ; # -a G0
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
160 ct1 = (2-a) .* t3 + (-3+a) .* t2 + 1 ; # F0 - a G1
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
161 ct2 = (a-2) .* t3 + (-2 *a + 3) .* t2 + a .* t ; # F1 + a G0
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
162 ct3 = a .* t3 - a .* t2; # a G1
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
163 t = []; t2 = []; t3 = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
164
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
165 s2 = s.*s;
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
166 s3 = s2.*s;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
167
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
168 cs0 = -a .* s3 + (2 * a) .* s2 - a .*s ; # -a G0
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
169 cs1 = (2-a) .* s3 + (-3 + a) .* s2 + 1 ; # F0 - a G1
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
170 cs2 = (a-2) .* s3 + (-2 *a + 3) .* s2 + a .*s ; # F1 + a G0
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
171 cs3 = a .* s3 - a .* s2; # a G1
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
172 s = []; s2 = []; s3 = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
173
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
174 cs0 = cs0([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
175 cs1 = cs1([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
176 cs2 = cs2([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
177 cs3 = cs3([1,1,1,1],:);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
178
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
179 lent = length (ct0);
10859
09144fbb0e36 Fix bug #30400 when bicubic called with small numbers of arguments.
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
180 lens = columns (cs0);
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
181 zi = zeros (lent, lens);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
182
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
183 for i = 1:lent
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
184 it = indt(i);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
185 int = [it, it+1, it+2, it+3];
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
186 zi(i,:) = ([ct0(i),ct1(i),ct2(i),ct3(i)]
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
187 * (p(int,inds) .* cs0 + p(int,inds+1) .* cs1
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
188 + p(int,inds+2) .* cs2 + p(int,inds+3) .* cs3));
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
189 endfor
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
190
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 7795
diff changeset
191 ## Set points outside the table to extrapval.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
192 if (! (isempty (xfirst_ind) && isempty (xlast_ind)))
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
193 zi(:, [xfirst_ind, xlast_ind]) = extrapval;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
194 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
195 if (! (isempty (yfirst_ind) && isempty (ylast_ind)))
11470
eb9e0b597d61 Use common names for variables in documentation and code for a few more m-script files.
Rik <octave@nomad.inbox5.com>
parents: 11149
diff changeset
196 zi([yfirst_ind; ylast_ind], :) = extrapval;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
197 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
198
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
199 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
200
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
201 %!demo
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
202 %! A=[13,-1,12;5,4,3;1,6,2];
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
203 %! x=[0,1,4]+10; y=[-10,-9,-8];
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
204 %! xi=linspace(min(x),max(x),17);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6653
diff changeset
205 %! yi=linspace(min(y),max(y),26)';
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
206 %! mesh(xi,yi,bicubic(x,y,A,xi,yi));
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
207 %! [x,y] = meshgrid(x,y);
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
208 %! hold on; plot3(x(:),y(:),A(:),"b*"); hold off;