1% STK_LM_POLYNOMIAL creates a polynomial linear model object
2%
3% CALL: LM = STK_LM_POLYNOMIAL (D)
4%
5%    creates a polynomial linear model object LM of degree D.
6
7% Copyright Notice
8%
9%    Copyright (C) 2016-2018 CentraleSupelec
10%    Copyright (C) 2012-2014 SUPELEC
11%
12%    Author:  Julien Bect  <julien.bect@centralesupelec.fr>
13
14% Copying Permission Statement
15%
16%    This file is part of
17%
18%            STK: a Small (Matlab/Octave) Toolbox for Kriging
19%               (http://sourceforge.net/projects/kriging)
20%
21%    STK is free software: you can redistribute it and/or modify it under
22%    the terms of the GNU General Public License as published by the Free
23%    Software Foundation,  either version 3  of the License, or  (at your
24%    option) any later version.
25%
26%    STK is distributed  in the hope that it will  be useful, but WITHOUT
27%    ANY WARRANTY;  without even the implied  warranty of MERCHANTABILITY
28%    or FITNESS  FOR A  PARTICULAR PURPOSE.  See  the GNU  General Public
29%    License for more details.
30%
31%    You should  have received a copy  of the GNU  General Public License
32%    along with STK.  If not, see <http://www.gnu.org/licenses/>.
33
34function lm = stk_lm_polynomial (order)
35
36% nargin check neded here.  See https://sourceforge.net/p/kriging/tickets/52.
37if nargin < 1
38    stk_error ('Not enough input arguments.', 'NotEnoughInputArgs');
39end
40
41switch order
42
43    case -1, % 'simple' kriging
44        lm = stk_lm_null ();
45
46    case 0, % 'ordinary' kriging
47        lm = stk_lm_constant ();
48
49    case 1, % affine trend
50        lm = stk_lm_affine ();
51
52    case 2, % quadratic trend
53        lm = stk_lm_quadratic ();
54
55    case 3, % cubic trend
56        lm = stk_lm_cubic ();
57
58    otherwise, % syntax error
59        stk_error ('order should be in {-1, 0, 1, 2, 3}', 'InvalidArgument');
60end
61
62end % function
63
64
65%!error lm = stk_lm_polynomial ();
66
67%!test
68%! lm = stk_lm_polynomial (-1);
69%! assert (isa (lm, 'stk_lm_null'));
70
71%!test
72%! lm = stk_lm_polynomial (0);
73%! assert (isa (lm, 'stk_lm_constant'));
74
75%!test
76%! lm = stk_lm_polynomial (1);
77%! assert (isa (lm, 'stk_lm_affine'));
78
79%!test
80%! lm = stk_lm_polynomial (2);
81%! assert (isa (lm, 'stk_lm_quadratic'));
82
83%!test
84%! lm = stk_lm_polynomial (3);
85%! assert (isa (lm, 'stk_lm_cubic'));
86