1 % KNTBRKDEGMULT: Construct an open knot vector by giving the sequence of
2 % knots, the degree and the multiplicity.
4 % knots = kntbrkdegreg (breaks, degree)
5 % knots = kntbrkdegreg (breaks, degree, mult)
9 % breaks: sequence of knots.
10 % degree: polynomial degree of the splines associated to the knot vector.
11 % mult: multiplicity of the knots.
17 % If MULT has as many entries as BREAKS, or as the number of interior
18 % knots, a different multiplicity will be assigned to each knot. If
19 % MULT is not present, it will be taken equal to 1.
21 % Copyright (C) 2010 Carlo de Falco, Rafael Vazquez
23 % This program is free software: you can redistribute it and/or modify
24 % it under the terms of the GNU General Public License as published by
25 % the Free Software Foundation, either version 2 of the License, or
26 % (at your option) any later version.
28 % This program is distributed in the hope that it will be useful,
29 % but WITHOUT ANY WARRANTY; without even the implied warranty of
30 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 % GNU General Public License for more details.
33 % You should have received a copy of the GNU General Public License
34 % along with this program. If not, see <http://www.gnu.org/licenses/>.
36 function knots = kntbrkdegmult (breaks, degree, mult)
43 if (numel(breaks)~=numel(degree) || numel(breaks)~=numel(mult))
44 error('kntbrkdegmult: degree and multiplicity must have the same length as the number of knot vectors')
47 degree = num2cell (degree);
50 mult = num2cell (mult);
53 knots = cellfun (@do_kntbrkdegmult, breaks, degree, mult, 'uniformoutput', false);
61 knots = do_kntbrkdegmult (breaks, degree, mult);
66 function knots = do_kntbrkdegmult (breaks, degree, mult)
68 if (numel (breaks) < 2)
69 error ('kntbrkdegmult: the knots sequence should contain at least two points')
72 if (numel (mult) == 1)
73 mults = [degree+1, mult(ones (1, numel (breaks) - 2)), degree+1];
74 elseif (numel (mult) == numel (breaks))
75 mults = [degree+1 mult(2:end-1) degree+1];
76 elseif (numel (mult) == numel (breaks) - 2)
77 mults = [degree+1 mult degree+1];
79 error('kntbrkdegmult: the length of mult should be equal to one or the number of knots')
82 if (any (mults > degree+1))
83 warning ('kntbrkdegmult: some knots have higher multiplicity than the degree+1')
86 breaks = sort (breaks);
92 mm (cumsum ([1 reshape(mults (1:end-1), 1, lm-1)])) = ones (1,lm);
93 knots = breaks (cumsum (mm));
98 %! breaks = [0 1 2 3 4];
100 %! knots = kntbrkdegmult (breaks, degree);
101 %! assert (knots, [0 0 0 0 1 2 3 4 4 4 4])
104 %! breaks = [0 1 2 3 4];
107 %! knots = kntbrkdegmult (breaks, degree, mult);
108 %! assert (knots, [0 0 0 0 1 1 2 2 3 3 4 4 4 4])
111 %! breaks = [0 1 2 3 4];
114 %! knots = kntbrkdegmult (breaks, degree, mult);
115 %! assert (knots, [0 0 0 0 1 2 2 3 3 3 4 4 4 4])
118 %! breaks = {[0 1 2 3 4] [0 1 2 3]};
120 %! mult = {[1 2 3] 2};
121 %! knots = kntbrkdegmult (breaks, degree, mult);
122 %! assert (knots, {[0 0 0 0 1 2 2 3 3 3 4 4 4 4] [0 0 0 1 1 2 2 3 3 3]})