5837
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 Kai Habel |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "defun-dld.h" |
|
29 #include "error.h" |
|
30 #include "gripes.h" |
|
31 #include "oct-obj.h" |
|
32 #include "utils.h" |
|
33 #include "f77-fcn.h" |
|
34 |
|
35 extern "C" { |
|
36 extern int F77_FUNC (dpchim, DPCHIM) |
|
37 (const int &n, double *x, double *f, |
|
38 double *d, const int &incfd, int *ierr); |
|
39 } |
|
40 |
|
41 DEFUN_DLD(__pchip_deriv__, args, , |
|
42 "-*- texinfo -*-\n\ |
|
43 @deftypefn {Loadable Function} {} __pchip_deriv__ (@var{x}, @var{y})\n\ |
|
44 Wrapper for SLATEC/PCHIP function DPCHIM to calculate the derivates for\n\ |
|
45 piecewise polynomials. You should be using @code{pchip} function instead.\n\ |
|
46 @end deftypefn") |
|
47 { |
|
48 octave_value retval; |
|
49 const int nargin = args.length(); |
|
50 |
|
51 if (nargin == 2) |
|
52 { |
|
53 ColumnVector xvec(args(0).vector_value()); |
|
54 Matrix ymat(args(1).matrix_value()); |
|
55 int nx = xvec.length(); |
|
56 int nyr = ymat.rows(); |
|
57 int nyc = ymat.columns(); |
|
58 |
|
59 if (nx != nyr) |
|
60 { |
|
61 error("number of rows for x and y must match"); |
|
62 return retval; |
|
63 } |
|
64 |
|
65 ColumnVector dvec(nx),yvec(nx); |
|
66 Matrix dmat(nyr,nyc); |
|
67 |
|
68 int ierr; |
|
69 const int incfd = 1; |
|
70 for (int c = 0; c < nyc; c++) |
|
71 { |
|
72 for (int r=0; r<nx; r++) |
|
73 { |
|
74 yvec(r) = ymat(r,c); |
|
75 } |
|
76 |
|
77 F77_FUNC (dpchim, DPCHIM) (nx, xvec.fortran_vec(), |
|
78 yvec.fortran_vec(), |
|
79 dvec.fortran_vec(), incfd, &ierr); |
|
80 |
|
81 if (ierr < 0) |
|
82 { |
|
83 error ("DPCHIM error: %i\n",ierr); |
|
84 return retval; |
|
85 } |
|
86 for (int r=0; r<nx; r++) |
|
87 { |
|
88 dmat(r,c) = dvec(r); |
|
89 } |
|
90 } |
|
91 |
|
92 retval = dmat; |
|
93 } |
|
94 |
|
95 return retval; |
|
96 } |