This is a static copy of a profile report

Home

ppmak (3 calls, 0.020 sec)
Generated 05-Nov-2014 07:53:55 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/curvefit/splines/ppmak.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
sp2pp>sp2pp1subfunction2
sp2ppfunction1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
103
else
20.010 s50.0%
74
sizec = size(coefs);
30.010 s50.0%
165
pp.dim = sizeval;
30 s0%
164
pp.order = k;
30 s0%
163
pp.pieces = l;
30 s0%
All other lines  0 s0%
Totals  0.020 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in function165
Non-code lines (comments, blank lines)87
Code lines (lines that can run)78
Code lines that did run36
Code lines that did not run42
Coverage (did run/can run)46.15 %
Function listing
   time   calls  line
1 function pp = ppmak(breaks,coefs,d)
2 %PPMAK Put together a spline in ppform.
3 %
4 % PPMAK(BREAKS,COEFS) puts together a spline in ppform from the breaks
5 % BREAKS and coefficient matrix COEFS. Each column of COEFS is
6 % taken to be one coefficient, i.e., the spline is taken to be D-vector
7 % valued if COEFS has D rows. Further, with L taken as length(BREAKS)-1,
8 % the order K of the spline is computed as (# cols(COEFS))/L, and COEFS is
9 % interpreted as a three-dimensional array of size [D,K,L], with
10 % COEFS(i,:,j) containing the local polynomial coefficients for the i-th
11 % component of the j-th polynomial piece, from highest to lowest.
12 %
13 % PPMAK will prompt you for BREAKS and COEFS.
14 %
15 % PPMAK(BREAKS,COEFS,D), with D a positive integer, interprets the matrix
16 % COEFS to be of size [D,L,K], with COEFS(i,j,:) containing the local
17 % polynomial coefficients, from highest to lowest, of the i-th component
18 % of the j-th polynomial piece.
19 % In particular, the order K is taken to be the last dimension of COEFS,
20 % and L is taken to be length(COEFS(:))/(D*K),
21 % and BREAKS is expected to be of length L+1.
22 % The toolbox uses internally only this second format, reshaping COEFS
23 % to be of size [D*L,K].
24 %
25 % For example, ppmak([1 3 4],[1 2 5 6;3 4 7 8]) and
26 % ppmak([1 3 4],[1 2;3 4;5 6;7 8],2)
27 % specify the same function (2-vector-valued, of order 2).
28 %
29 % PPMAK(BREAKS,COEFS,SIZEC), with SIZEC a vector of positive integers,
30 % interprets COEFS to be of size SIZEC =: [D,L,K], with COEFS(i,j,:)
31 % containing the polynomial coefficient, from highest to lowest, of the i-th
32 % component of the j-th polynomial piece. The dimension of the function's
33 % target is taken to be SIZEC(1:end-2). Internally, COEFS is reshaped into a
34 % matrix, of size [prod(SIZEC(1:end-1)),K].
35 %
36 % For example, to make up the constant function, with basic interval [0..1]
37 % say, whose value is the matrix EYE(2), you have to use the command
38 % ppmak(0:1, eye(2), [2,2,1,1]);
39 %
40 % PPMAK({BREAKS1,...,BREAKSm},COEFS) puts together an m-variate
41 % tensor-product spline in ppform. In this case, COEFS is expected to be of
42 % size [D,lk], with lk := [l1*k1,...,lm*km] and li = length(BREAKS{i})-1,
43 % all i, and this defines D and k := [k1,...,km]. If, instead, COEFS is
44 % only an m-dimensional array, then D is taken to be 1.
45 %
46 % PPMAK({BREAKS1,...,BREAKSm},COEFS,SIZEC) uses the optional third argument
47 % to specify the size of COEFS. The intended size of COEFS is needed in case
48 % one or more of its trailing dimensions is a singleton and thus COEFS by
49 % itself appears to be of lower dimension.
50 %
51 % For example, if we intend to construct a 2-vector-valued bivariate
52 % polynomial on the rectangle [-1 .. 1] x [0 .. 1], linear in the first
53 % variable and constant in the second, say
54 % coefs = zeros(2,2,1); coefs(:,:,1) = [1 0; 0 1];
55 % then the straightforward
56 % pp = ppmak({[-1 1],[0 1]},coefs);
57 % will fail, producing a scalar-valued function of order 2 in each variable,
58 % as will
59 % pp = ppmak({[-1 1],[0 1]},coefs,size(coefs));
60 % while the command
61 % pp = ppmak({[-1 1],[0 1]},coefs,[2 2 1]);
62 % will succeed.
63 %
64 % See also PPBRK, RPMAK, SPMAK, RSMAK, STMAK, FNBRK.
65
66 % Copyright 1987-2010 The MathWorks, Inc.
67 % $Revision: 1.1.6.4 $
68
3 69 if nargin==0
70 breaks=input('Give the (l+1)-vector of breaks >');
71 coefs=input('Give the (d by (k*l)) matrix of local pol. coefficients >');
72 end
73
0.01 3 74 sizec = size(coefs);
75
3 76 if iscell(breaks) % we are dealing with a tensor-product spline
1 77 if nargin>2
1 78 if prod(sizec)~=prod(d)
79 error(message('SPLINES:PPMAK:coefsdontmatchsize'))
80 end
1 81 sizec = d;
1 82 end
1 83 m = length(breaks);
1 84 if length(sizec)<m
85 error('SPLINES:PPMAK:coefsdontmatchbreaks', ...
86 'If BREAKS is a cell-array of length m, then COEFS must have at least m dimensions.')
87 end
1 88 if length(sizec)==m, % coefficients of a scalar-valued function
89 sizec = [1 sizec];
90 end
1 91 sizeval = sizec(1:end-m);
1 92 sizec = [prod(sizeval), sizec(end-m+(1:m))];
1 93 coefs = reshape(coefs, sizec);
94
1 95 for i=m:-1:1
2 96 l(i) = length(breaks{i})-1;
2 97 k(i) = fix(sizec(i+1)/l(i));
2 98 if k(i)<=0||k(i)*l(i)~=sizec(i+1)
99 error(message('SPLINES:PPMAK:piecesdontmatchcoefsforvar', sprintf( '%g', l( i ) ), sprintf( '%g', sizec( i + 1 ) ), sprintf( '%g', i )))
100 end
2 101 breaks{i} = reshape(breaks{i},1,l(i)+1);
2 102 end
0.01 2 103 else
2 104 if nargin<3
105 if isempty(coefs)
106 error(message('SPLINES:PPMAK:emptycoefs'))
107 end
108 sizeval = sizec(1:end-1);
109 d = prod(sizeval);
110 kl = sizec(end);
111 l=length(breaks)-1;
112 k=fix(kl/l);
113 if (k<=0)||(k*l~=kl)
114 error(message('SPLINES:PPMAK:piecesdontmatchcoefs', sprintf( '%g', l ), sprintf( '%g', kl )));
115 elseif any(diff(breaks)<0)
116 error(message('SPLINES:PPMAK:decreasingbreaks'))
117 elseif breaks(1)==breaks(l+1)
118 error(message('SPLINES:PPMAK:extremebreakssame'))
119 else
120 % the ppformat expects coefs in array (d*l) by k, while the standard
121 % input supplies them in an array d by (k*l) . This requires the
122 % following shuffling, from D+d(-1+K + k(-1+L))=D-d +(K-k)d + dkL
123 % to D+d(-1+L + l(-1+K)=D-d +(L-l)d + dlK .
124 % This used to be handled by the following:
125 % c=coefs(:); temp = ([1-k:0].'*ones(1,l)+k*ones(k,1)*[1:l]).';
126 % coefs=[1-d:0].'*ones(1,kl)+d*ones(d,1)*(temp(:).');
127 % coefs(:)=c(coefs);
128 % Thanks to multidimensional arrays, we can now simply say
129 coefs = reshape(permute(reshape(coefs,[d,k,l]),[1,3,2]),d*l,k);
130 end
2 131 else % in the univariate case, a scalar D only specifies the dimension of
132 % the target and COEFS must be a matrix (though that is not checked for);
133 % but if D is a vector, then it is taken to be the intended size of
134 % COEFS whatever the actual dimensions of COEFS might be.
2 135 if length(d)==1
2 136 k = sizec(end);
2 137 l = prod(sizec(1:end-1))/d;
138 else
139 if prod(d)~=prod(sizec)
140 error(message('SPLINES:PPMAK:coefssizemismatch', num2str( sizec ), num2str( d )));
141 end
142 k = d(end);
143 l = d(end-1);
144 d(end-1:end) = [];
145 if isempty(d),
146 d = 1;
147 end
148 % Interpret the coefficients, COEFS, to be of size SIZEC =: [d,l,k]
149 coefs = reshape(coefs, prod(d)*l,k);
150 end
2 151 if l+1~=length(breaks)
152 error('SPLINES:PPMAK:coefsdontmatchbreaks', ...
153 'COEFS indicates %s piece(s) while BREAKS indicates %s.', ...
154 sprintf('%g',l), sprintf('%g',length(breaks)-1))
155 end
2 156 sizeval = d;
2 157 end
2 158 breaks = reshape(breaks,1,l+1);
2 159 end
3 160 pp.form = 'pp';
3 161 pp.breaks = breaks;
3 162 pp.coefs = coefs;
3 163 pp.pieces = l;
3 164 pp.order = k;
3 165 pp.dim = sizeval;