function [F1n,G1n]=evtaylor(m,P,F1,G1,names,values,wtylr)
%EVTAYLOR evaluates a literal non-redundant literal Taylor expansion
%
% [F1n,G1n]=evtaylor(M,P,F1,G1,NAMES,VALUES,WTYLR) evaluates the literal
% non-redundant 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, WTYLR are the Taylor expansion coefficients.

%   CBVK Toolbox
%   JHMG, PMSB 2016

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

MP = factorial(m+P)/factorial(m)/factorial(P);
MP1 = factorial(m+P-1)/factorial(m)/factorial(P-1);
mps = cumsum([1 fliplr(calcnumterms(P,m))])+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
      F1n(i,mps(p):mps(p+1)-1)=eval(F1{i,p+1});
      G1n(i,mps(p):mps(p+1)-1)=eval(G1{i,p+1});
   end
   p=P;
   F1n(i,mps(p):mps(p+1)-1)=eval(F1{i,p+1});

end

% Taylor expansion coefficients
F1n = F1n.*repmat(wtylr(1:size(F1n,2)),[m 1]);
G1n = G1n.*repmat(wtylr(1:size(G1n,2)),[m 1]);

  
  
