% Measures the the minimum execution time of non-redundant Carleman
% Bilinearization of integrator + loudspeaker A

clear

P=4;        % Expansion order
rep=100;    % Number of repetitions for greater precision of execution
            % time measurement

arq='mcb_nr_Aitgr_P4';  % Ouput file


% Numerical model
[f,g,h,x]=dloudAitgr_num;      % Regenerate model to be sure


% ----------------------------------------------------
% Taylor expansion


% Pre-calculated weights and indices (cbvkutil/mkwtaylor.m)
load wtaylor_m4_P5

x0=zeros(1,length(f));
F1 = multaylor(f,x,x0,P,wtylr,I);
G1 = multaylor(g,x,x0,P-1,wtylr,I);


%----------------------------------------------------
% Carleman Bilinearization

% Pre-calculated maps (cbvkutil/mkmapscb.m)
load mapscb_m4_P4

dt=zeros(1,rep);

for r=1:rep
  tic
  [F,G,b] = carlbilin(F1,G1,P,Mvars,Mpos,D,Dg,K);
  %[F,G,b] = carlbilin(F1,G1,P);
  dt(r)=toc;
  fprintf('%g\n ', dt(r));
end

min(dt)
%save(arq,'dt');

