View Javadoc
1   /*
2    * Copyright (C) 2016 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.numerical.polynomials.estimators;
17  
18  /**
19   * Contains an evaluation of the nth-integral of a polynomial and the
20   * point where such integral has been evaluated.
21   */
22  public class IntegralPolynomialEvaluation extends PolynomialEvaluation {
23  
24      /**
25       * Minimum allowed integral order.
26       */
27      public static final int MIN_INTEGRAL_ORDER = 1;
28  
29      /**
30       * Point where integral of a given order has been evaluated.
31       */
32      private double x;
33  
34      /**
35       * Constant terms of integral.
36       */
37      private double[] constants;
38  
39      /**
40       * Order of integral.
41       */
42      private int integralOrder;
43  
44      /**
45       * Constructor.
46       */
47      public IntegralPolynomialEvaluation() {
48          super();
49          setIntegralOrder(MIN_INTEGRAL_ORDER);
50      }
51  
52      /**
53       * Constructor.
54       *
55       * @param x             point where integral of polynomial has been evaluated.
56       * @param evaluation    evaluation of nth-integral of polynomial at point x.
57       * @param constants     constant terms of nth-integral.
58       * @param integralOrder order of integral.
59       * @throws IllegalArgumentException if order of integral is less than 1.
60       */
61      public IntegralPolynomialEvaluation(
62              final double x, final double evaluation, final double[] constants, final int integralOrder) {
63          super(evaluation);
64          this.x = x;
65          this.constants = constants;
66          setIntegralOrder(integralOrder);
67      }
68  
69      /**
70       * Constructor.
71       *
72       * @param x          point where integral of polynomial has been evaluated.
73       * @param evaluation evaluation of nth-integral of polynomial at point x.
74       * @param constants  constant terms of nth-integral.
75       */
76      public IntegralPolynomialEvaluation(final double x, final double evaluation, final double[] constants) {
77          this(x, evaluation, constants, MIN_INTEGRAL_ORDER);
78      }
79  
80      /**
81       * Constructor.
82       *
83       * @param x             point where integral of polynomial has been evaluated.
84       * @param evaluation    evaluation of nth-integral of polynomial at point x.
85       * @param integralOrder order of integral.
86       * @throws IllegalArgumentException if order of integral is less than 1.
87       */
88      public IntegralPolynomialEvaluation(final double x, final double evaluation, final int integralOrder) {
89          this(x, evaluation, null, integralOrder);
90      }
91  
92      /**
93       * Constructor.
94       *
95       * @param x          point where integral of polynomial has been evaluated.
96       * @param evaluation evaluation of nth-integral of polynomial at point x.
97       */
98      public IntegralPolynomialEvaluation(final double x, final double evaluation) {
99          this(x, evaluation, null, MIN_INTEGRAL_ORDER);
100     }
101 
102     /**
103      * Gets point where nth-polynomial integral has been evaluated.
104      *
105      * @return point where nth-polynomial integral has been evaluated.
106      */
107     public double getX() {
108         return x;
109     }
110 
111     /**
112      * Sets point where nth-polynomial integral has been evaluated.
113      *
114      * @param x point where nth-polynomial integral has been evaluated.
115      */
116     public void setX(final double x) {
117         this.x = x;
118     }
119 
120     /**
121      * Gets constant terms of integral.
122      *
123      * @return constant terms of integral.
124      */
125     public double[] getConstants() {
126         return constants;
127     }
128 
129     /**
130      * Sets constant terms of integral.
131      *
132      * @param constants constant terms of integral.
133      */
134     public void setConstant(final double[] constants) {
135         this.constants = constants;
136     }
137 
138     /**
139      * Gets integral order.
140      *
141      * @return integral order.
142      */
143     public int getIntegralOrder() {
144         return integralOrder;
145     }
146 
147     /**
148      * Sets integral order.
149      *
150      * @param integralOrder integral order.
151      * @throws IllegalArgumentException if integral order is less than 1.
152      */
153     public final void setIntegralOrder(final int integralOrder) {
154         if (integralOrder < MIN_INTEGRAL_ORDER) {
155             throw new IllegalArgumentException("integral order must be at least 1");
156         }
157 
158         this.integralOrder = integralOrder;
159     }
160 
161     /**
162      * Gets type of polynomial evaluation.
163      *
164      * @return type of polynomial evaluation.
165      */
166     @Override
167     public PolynomialEvaluationType getType() {
168         return PolynomialEvaluationType.INTEGRAL_EVALUATION;
169     }
170 }