% Pre-calculation of maps for Carleman Bilinearization

%   CBVK Toolbox
%   JHMG, PMSB 2016

m=4;
%m=11;

%P=2;
%P=3;
%P=4;
P=5;


%------------------------------------

allterms = fliplr(calcnumterms(P,m));
[Mvars, Mpos, D] = mapsvarspos(m, P);
Dg = D(1:end-allterms(end),1:end-allterms(end));
Dg(Dg > size(Dg,1)) = 0;

MP = nchoosek(m+P,P);
F1=randn(m,MP);
MP = nchoosek(m+P-1,P-1);
G1=randn(m,MP);

[F,G,b,K] = carlbilin(F1,G1,P,Mvars,Mpos,D,Dg);

arq=['mapscb_m' num2str(m) '_P' num2str(P)];
eval(['save ../mat/' arq ' Mvars Mpos D Dg K']);

