function [F1n,G1n]=evtred(m,P,F1,G1,names,values)
%EVTRED evaluates a redundant literal Taylor expansion
%
% [F1n,G1n]=evtred(M,P,F1,G1,NAMES,VALUES,WTYLR) evaluates the literal
% Taylor expansion coefficients F1 and G1 of a literal symbolic
% linear-analytic state-space model x'= f(x) + g(x)u. NAMES is a cell
% containing parameter names, VALUES is a structure with default parameter
% values.

%   CBVK Toolbox
%   JHMG, PMSB 2016

 
% Parameter setting 
for i=1:length(names)
    eval([names{i} '= values.' names{i} ';']);
end

MP = sum(m.^(0:P));
MP1 = sum(m.^(0:P-1));
mps = cumsum(m.^(0:P))+1;
mps1 = cumsum(m.^(0:P-1))+1;

F1n = zeros(m,MP);
G1n = zeros(m,MP1);

% Evaluation
for i=1:m
    
  % p=0
  F1n(i,1)=eval(F1{i,1});
  G1n(i,1)=eval(G1{i,1});
  
  % p=1
  F1n(i,2:m+1)=eval(F1{i,2});
  G1n(i,2:m+1)=eval(G1{i,2}); 
  
   for p=2:P-1
      p1=1/factorial(p);
      F1n(i,mps(p):mps(p+1)-1)=p1*eval(F1{i,p+1});
      G1n(i,mps(p):mps(p+1)-1)=p1*eval(G1{i,p+1});
   end
   p=P;
   p1=1/factorial(p);
   F1n(i,mps(p):mps(p+1)-1)=p1*eval(F1{i,p+1});

end

  

