clear functions

  k = 1;      % number of rows for the Qi(s)
  m = 1;      % number of columns for the Qi(s)

  % Inputs:
  %   k     - number of rows for the Qi(s)
  %   m     - number of columns for the Qi(s)
  %   Qi    - cell array with Q1(s), Q2(s), ..., QN(s)
  % Output:
  %   Ti    - cell array with T0(s), T1(s), T2(s), ..., TN(s)
  Ti = cell(length(Qi)+1,1);                       % initialize cell array
  % compute T0(s)
  [AQ,BQ,CQ,DQ] = ssdata(tf(zeros(k,m)));          % set Q = 0 in simulink
  [a,b,c,d]     = linmod('augmented_closedloop');  % get T0(s)
  Ti{1} = minreal(ss(a,b,c,d));                    % store T0
  % compute T1(s), T2(s), ...
  for i = 1:length(Qi)
      [AQ,BQ,CQ,DQ]=ssdata(Qi{i});                 % set Q = Qi in simulink
      [a,b,c,d]=linmod('augmented_closedloop');    % get T0(s) + Ti(s) 
      Ti{i+1}=minreal(ss(a,b,c,d)-Ti{1});          % store Ti(s)
  end
    
  augmented_closedloop
  print -s -depsc augmented_closedloop.eps