This is a static copy of a profile reportHome
pchip (18 calls, 1.279 sec)
Generated 05-Aug-2011 13:00:40 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/polyfun/pchip.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
interp1 | function | 18 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
87 | v = ppval(v,xx); | 18 | 0.962 s | 75.2% |  |
84 | v = pwch(x,y,slopes,h,del); v.... | 18 | 0.153 s | 12.0% |  |
74 | slopes(r,:) = pchipslopes(x,y(... | 18 | 0.098 s | 7.7% |  |
70 | del = diff(y,1,2)./repmat(h,m,... | 18 | 0.022 s | 1.7% |  |
59 | [x,y,sizey] = chckxy(x,y); | 18 | 0.022 s | 1.7% |  |
All other lines | | | 0.022 s | 1.7% |  |
Totals | | | 1.279 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
ppval | function | 18 | 0.962 s | 75.2% |  |
pwch | function | 18 | 0.153 s | 12.0% |  |
pchip>pchipslopes | subfunction | 18 | 0.098 s | 7.7% |  |
polyfun/private/chckxy | function | 18 | 0.022 s | 1.7% |  |
repmat | function | 18 | 0 s | 0% |  |
Self time (built-ins, overhead, etc.) | | | 0.044 s | 3.4% |  |
Totals | | | 1.279 s | 100% | |
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 88 |
Non-code lines (comments, blank lines) | 68 |
Code lines (lines that can run) | 20 |
Code lines that did run | 13 |
Code lines that did not run | 7 |
Coverage (did run/can run) | 65.00 % |
Function listing
time calls line
1 function v = pchip(x,y,xx)
2 %PCHIP Piecewise Cubic Hermite Interpolating Polynomial.
3 % PP = PCHIP(X,Y) provides the piecewise polynomial form of a certain
4 % shape-preserving piecewise cubic Hermite interpolant, to the values
5 % Y at the sites X, for later use with PPVAL and the spline utility UNMKPP.
6 % X must be a vector.
7 % If Y is a vector, then Y(j) is taken as the value to be matched at X(j),
8 % hence Y must be of the same length as X.
9 % If Y is a matrix or ND array, then Y(:,...,:,j) is taken as the value to
10 % be matched at X(j), hence the last dimension of Y must equal length(X).
11 %
12 % YY = PCHIP(X,Y,XX) is the same as YY = PPVAL(PCHIP(X,Y),XX), thus
13 % providing, in YY, the values of the interpolant at XX.
14 %
15 % The PCHIP interpolating function, p(x), satisfies:
16 % On each subinterval, X(k) <= x <= X(k+1), p(x) is the cubic Hermite
17 % interpolant to the given values and certain slopes at the two endpoints.
18 % Therefore, p(x) interpolates Y, i.e., p(X(j)) = Y(:,j), and
19 % the first derivative, Dp(x), is continuous, but
20 % D^2p(x) is probably not continuous; there may be jumps at the X(j).
21 % The slopes at the X(j) are chosen in such a way that
22 % p(x) is "shape preserving" and "respects monotonicity". This means that,
23 % on intervals where the data is monotonic, so is p(x);
24 % at points where the data have a local extremum, so does p(x).
25 %
26 % Comparing PCHIP with SPLINE:
27 % The function s(x) supplied by SPLINE is constructed in exactly the same way,
28 % except that the slopes at the X(j) are chosen differently, namely to make
29 % even D^2s(x) continuous. This has the following effects.
30 % SPLINE is smoother, i.e., D^2s(x) is continuous.
31 % SPLINE is more accurate if the data are values of a smooth function.
32 % PCHIP has no overshoots and less oscillation if the data are not smooth.
33 % PCHIP is less expensive to set up.
34 % The two are equally expensive to evaluate.
35 %
36 % Example:
37 %
38 % x = -3:3;
39 % y = [-1 -1 -1 0 1 1 1];
40 % t = -3:.01:3;
41 % plot(x,y,'o',t,[pchip(x,y,t); spline(x,y,t)])
42 % legend('data','pchip','spline',4)
43 %
44 % Class support for inputs x, y, xx:
45 % float: double, single
46 %
47 % See also INTERP1, SPLINE, PPVAL, UNMKPP.
48
49 % References:
50 % F. N. Fritsch and R. E. Carlson, "Monotone Piecewise Cubic
51 % Interpolation", SIAM J. Numerical Analysis 17, 1980, 238-246.
52 % David Kahaner, Cleve Moler and Stephen Nash, Numerical Methods
53 % and Software, Prentice Hall, 1988.
54 %
55 % Copyright 1984-2004 The MathWorks, Inc.
56 % $Revision: 1.7.4.7 $ $Date: 2010/09/02 13:36:26 $
57
58 % Check that data are acceptable and, if not, try to adjust them appropriately
0.02 18 59 [x,y,sizey] = chckxy(x,y);
18 60 h = diff(x); m = prod(sizey);
61
62 %ensure that the interpolation points are real
63
18 64 if nargin==3 && any(~isreal(reshape(xx,numel(xx),1)))
65 error(message('MATLAB:pchip:ComplexInterpPts'))
66 end
67
68 % Compute slopes
69
0.02 18 70 del = diff(y,1,2)./repmat(h,m,1);
0.01 18 71 slopes = zeros(size(y));
18 72 for r = 1:m
18 73 if isreal(del)
0.10 18 74 slopes(r,:) = pchipslopes(x,y(r,:),del(r,:));
75 else
76 realslopes = pchipslopes(x,y(r,:),real(del(r,:)));
77 imagslopes = pchipslopes(x,y(r,:),imag(del(r,:)));
78 slopes(r,:) = complex(realslopes, imagslopes);
79 end
18 80 end
81
82 % Compute piecewise cubic Hermite interpolant to those values and slopes
83
0.15 18 84 v = pwch(x,y,slopes,h,del); v.dim = sizey;
85
18 86 if nargin == 3 % if values are wanted instead, provide them
0.96 18 87 v = ppval(v,xx);
18 88 end
Other subfunctions in this file are not included in this listing.