This is a static copy of a profile reportHome
slvblk (404 calls, 1.112 sec)
Generated 05-Nov-2014 07:52:40 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/curvefit/splines/slvblk.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
88 | blocks(f:l,:) = ... | 2626 | 0.621 s | 55.9% |  |
49 | [nb,rows,ncols,last,blocks] = ... | 404 | 0.070 s | 6.3% |  |
87 | q = [vv;blocks(f+1:l,k)]; | 2626 | 0.060 s | 5.4% |  |
68 | blocks(f:l,:) = ... | 1212 | 0.060 s | 5.4% |  |
63 | if nargin>2, w = sqrt(w); b... | 404 | 0.060 s | 5.4% |  |
All other lines | | | 0.240 s | 21.6% |  |
Totals | | | 1.112 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
repmat | function | 5454 | 0.531 s | 47.7% |  |
bkbrk | function | 404 | 0.040 s | 3.6% |  |
Self time (built-ins, overhead, etc.) | | | 0.541 s | 48.6% |  |
Totals | | | 1.112 s | 100% | |
Code Analyzer results
Line number | Message |
103 | Use of brackets [] is unnecessary. Use parentheses to group, if needed. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 106 |
Non-code lines (comments, blank lines) | 60 |
Code lines (lines that can run) | 46 |
Code lines that did run | 34 |
Code lines that did not run | 12 |
Coverage (did run/can run) | 73.91 % |
Function listing
time calls line
1 function x = slvblk(blokmat,b,w)
2 %SLVBLK Solve almost block-diagonal linear system.
3 %
4 % SLVBLK(BLOKMAT,B) returns the solution (if any) of the linear system
5 % A*X=B, with the matrix A stored in BLOKMAT in the spline almost block
6 % diagonal form (as generated, e.g., in SPCOL).
7 %
8 % If the system is overdetermined (i.e., has more equations than
9 % unknowns), the least-squares solution is returned.
10 %
11 % SLVBLK(BLOKMAT,B,W) returns the vector X that minimizes the
12 % weighted l_2 sum
13 %
14 % sum_j W(j)*( (A*X-B)(j) )^2 .
15 %
16 % This is useful when the system is overdetermined.
17 % The default for W is the sequence [1,1,1,...].
18 %
19 % Example:
20 % The following statements generate some noisy data, then use SLVBLK to
21 % determine the least-squares approximation, weighted by the weights of
22 % the composite trapezoidal rule, to those data by cubic splines with
23 % two uniformly spaced knots, and plot the results:
24 %
25 % x = [0,sort(rand(1,31)),1]*(2*pi);
26 % y = sin(x)+(rand(1,33)-.5)/10;
27 % k = 4; knots = augknt(linspace(x(1),x(end),3),k);
28 % dx = diff(x); w = ([dx 0] + [0 dx])/2;
29 % sp = spmak(knots,slvblk(spcol(knots,k,x,'slvblk','noderiv'),y.',w).');
30 % fnplt(sp,2); hold on, plot(x,y,'ok'), hold off
31 %
32 % See also SPCOL, SPAPS, SPAPI, SPAP2.
33
34 % Copyright 1987-2008 The MathWorks, Inc.
35 % $Revision: 1.1.6.2 $
36
37 % If BLOKMAT is sparse, handle the problem sparsely:
404 38 if issparse(blokmat)
39 if nargin>2&&~isempty(w)
40 n = length(w); spw = sparse(1:n,1:n,sqrt(w));
41 x = (spw*blokmat)\(spw*b);
42 else
43 x = blokmat\b;
44 end
45 return
46 end
47
48 % get the basic information
0.07 404 49 [nb,rows,ncols,last,blocks] = bkbrk(blokmat);
50
404 51 ne = sum(rows);nu = sum(last);
404 52 if any(cumsum(rows)<cumsum(last))||any(last>ncols)
53 error(message('SPLINES:SLVBLK:matrixnot11'))
54 end
55
404 56 [brow,bcol] = size(b);
404 57 if(ne~=brow)
58 error(message('SPLINES:SLVBLK:wrongrightside'))
59 end
60
0.02 404 61 blocks = [blocks b];
404 62 ccols = ncols+bcol;
0.06 404 63 if nargin>2, w = sqrt(w); blocks = repmat(w(:),1,ccols).*blocks; end
64
404 65 f = 1; l = 0; elim = 0;
0.01 404 66 for j=1:nb
0.01 1616 67 if (f<=l) % shift the rows still remaining from previous block
0.06 1212 68 blocks(f:l,:) = ...
69 [blocks(f:l,elim+1:ncols) zeros(l+1-f,elim),blocks(f:l,ncols+1:ccols)];
0.01 1212 70 end
1616 71 l = l+rows(j);
72
1616 73 elim = last(j);
74 % ideally, one would now use
75 % [q,r] = qr(blocks(f:l,1:elim));
76 % followed up by
77 % blocks(f:l,:) = q'*blocks(f:l,:);
78 % f = f+elim;
79 % but, unfortunately, this generates the possibly very large square matrix q
80 % The unhappy alternative is to do the elimination explicitly here, using
81 % Householder reflections (and an additional inner loop):
1616 82 for k=1:elim
0.03 2626 83 a = norm(blocks(f:l,k));
0.01 2626 84 vv = abs(blocks(f,k))+a;
2626 85 c = vv*a;
2626 86 if blocks(f,k)<0, vv = -vv; end
0.06 2626 87 q = [vv;blocks(f+1:l,k)];
0.62 2626 88 blocks(f:l,:) = ...
89 blocks(f:l,:)-repmat(q/c,1,ccols).*repmat(q'*blocks(f:l,:),l+1-f,1);
90 %blocks(f:l,:)-((q/c)*ones(1,ccols)).*(ones(l+1-f,1)*(q'*blocks(f:l,:)));
0.01 2626 91 f = f+1;
0.01 2626 92 end
0.01 1616 93 end
94
95 % now we are ready for back-substitution
0.01 404 96 x = zeros(f-elim-1+ncols,bcol);
97
404 98 for j=nb:-1:1
1616 99 elim = last(j); l = f-1; f = f-elim;
100 % here is another occasion where empty matrices of various sizes would help;
101 % instead, use an if statement:
0.03 1616 102 if elim<ncols, blocks(f:l,ncols+1:ccols) = blocks(f:l,ncols+1:ccols) ...
1212 103 - blocks(f:l,elim+1:ncols)*x(f-1+[elim+1:ncols],:); end
0.03 1616 104 x(f:l,:) = blocks(f:l,1:elim) \ blocks(f:l,ncols+1:ccols);
1616 105 end
404 106 x = x(1:nu,:);