source: MML/trunk/machine/SOLEIL/common/toolbox/PolyfitnTools/PolyfitnTools/polyvaln.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 1.6 KB
Line 
1function ypred = polyvaln(polymodel,indepvar)
2% polyvaln: evaluates a polynomial model as a function of its variables
3% usage: ypred = polyvaln(polymodel,indepvar)
4%
5% arguments: (input)
6%  indepvar - (n x p) array of independent variables as columns
7%        n is the number of data points to evaluate
8%        p is the dimension of the independent variable space
9%
10%        IF n == 1, then I will assume there is only a
11%        single independent variable.
12%
13%  polymodel - A structure containing a regression model from polyfitn
14%        polymodel.ModelTerms = list of terms in the model
15%        polymodel.Coefficients = regression coefficients
16
17%        Note: A polymodel can be evaluated for any set of
18%        values with the function polyvaln. However, if you
19%        wish to manipulate the result symbolically using my
20%        own sympoly tools, this structure should be converted
21%        to a sympoly using the function polyn2sympoly.
22%
23% Arguments: (output)
24%  ypred - nx1 vector of predictions through the model.
25%
26%
27% See also: polyfitn, polyfit, polyval, polyn2sympoly, sympoly
28%
29% Author: John D'Errico
30% Release: 1.0
31% Release date: 2/19/06
32
33% get the size of indepvar
34[n,p] = size(indepvar);
35if (n == 1) && (size(polymodel.ModelTerms,2)==1)
36  indepvar = indepvar';
37  [n,p] = size(indepvar);
38elseif (size(polymodel.ModelTerms,2)~=p)
39  error 'Size of indepvar array and this model are inconsistent.'
40end
41
42% Evaluate the model
43nt = size(polymodel.ModelTerms,1);
44ypred = zeros(n,1);
45for i = 1:nt
46  t = ones(n,1);
47  for j = 1:p
48    t = t.*indepvar(:,j).^polymodel.ModelTerms(i,j);
49  end
50  ypred = ypred + t*polymodel.Coefficients(i);
51end
52
53
Note: See TracBrowser for help on using the repository browser.