-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgetMon.m
62 lines (59 loc) · 1.51 KB
/
getMon.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
function fullBase = getMon(d,n,varargin)
% fullBase = getMon(d,n) or getMon(d,n,d0)
% ----------------------------------------------
%
% Returns a full canonical base of monomials of total degree d and in n
% variables. Each row of mon refers to a n-tuple of exponents of a monomial
% whereby each column corresponds to a variable.
%
% example: d= 2, n = 3
%
% fullBase =
%
% 0 0 0
% 1 0 0
% 0 1 0
% 0 0 1
% 2 0 0
% 1 1 0
% 1 0 1
% 0 2 0
% 0 1 1
% 0 0 2
%
% CALLS
% -----
%
% getMonBase.m
%
% Kim Batselier, 2009-10
%
% Updated 2010-12-04: removed the monomial ordering argument. Replaced it
% by a minimal degree from which the monomial basis needs to be calculated.
% Further optimized the code by calling getMonBase once per for-iteration.
if ~isempty(varargin)
d0 = varargin{1};
if d0 > d
fullBase = [];
return
end
else
d0 = 0;
end
if d0 == 0
fullBase = zeros(nchoosek(d+n,n),n);
rowCounter = 2;
for i = 1 : d,
tempbase = getMonBase(i,n);
fullBase(rowCounter:rowCounter+length(tempbase)-1,:) = tempbase;
rowCounter = rowCounter+length(tempbase);
end
else
rowCounter = 1;
for i = d0 : d,
tempbase = getMonBase(i,n);
fullBase(rowCounter:rowCounter+length(tempbase)-1,:) = tempbase;
rowCounter = rowCounter+length(tempbase);
end
end
end