www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregcubic/eval.m
function y= eval(m,X) %EVAL Evaluate multivariate polynomial % % y = EVAL(m,X) evaluates the model m at inputs X. % Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc. [Npts,nf] = size(X); if Npts>0 c= double(m); if isempty(c) y = zeros(Npts,1); elseif nf==1 % 1-d polynomial y(1:Npts,1)= c(end); for i=length(c)-1:-1:1 y= y.*X + c(i); end else % reorder if necessary if any(diff(m.reorder)~=1) X= X(:,m.reorder); end N= m.N; MaxInteract= m.MaxInteract; m.N(MaxInteract+1:end)=0; % use mex evaluation for speed [y,p]= cubiceval_mex(c,m.N,MaxInteract,X'); nx= sum(N(MaxInteract+1:end)); if nx>0 % terms with no interactions Xm=X(:,1:N(MaxInteract+1)); Xi= Xm.^MaxInteract; for i=MaxInteract+1:length(N) Xi= Xi.*Xm; for j=1:N(i) p= p + 1; y= y + c(p)*Xi(:,j); end end end end else % correctly dim'ed output y = zeros(0,1); end % this is obsolete m code now replaced by cubiceval_mex. The code is % commeted to show the algorithm % function [y,p]= i_ceval(m,X) % % c= double(m); % % Evaluate using nested multiplication % p=1; % coefficient index % % Constant Term % y(1:size(X,1),1)= c(1); % N= m.N; % % % for i=1:N(1) % % 1st order terms % p=p+1; % Yi = c(p); % for j=i:N(2) % % 2nd order terms % p=p+1; % % Yj = c(p); % for k=j:N(3) % % 3rd order terms % p=p+1; % Yj= Yj + c(p)*X(:,k); % end % % Yi= Yi + X(:,j).*Yj; % end % y = y + X(:,i).*Yi; % end