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 derivative of a given order of a polynomial and
20 * the point where such derivative has been evaluated.
21 */
22 public class DerivativePolynomialEvaluation extends PolynomialEvaluation {
23
24 /**
25 * Minimum allowed derivative order.
26 */
27 public static final int MIN_DERIVATIVE_ORDER = 1;
28
29 /**
30 * Point where derivative of a given order has been evaluated.
31 */
32 private double x;
33
34 /**
35 * Order of derivative.
36 */
37 private int derivativeOrder;
38
39 /**
40 * Constructor.
41 */
42 public DerivativePolynomialEvaluation() {
43 super();
44 setDerivativeOrder(MIN_DERIVATIVE_ORDER);
45 }
46
47 /**
48 * Constructor.
49 *
50 * @param x point where derivative of polynomial has been evaluated.
51 * @param evaluation evaluation of nth-derivative of polynomial at point x.
52 * @param derivativeOrder order of derivative.
53 * @throws IllegalArgumentException if order of derivative is less than 1.
54 */
55 public DerivativePolynomialEvaluation(final double x, final double evaluation, final int derivativeOrder) {
56 super(evaluation);
57 this.x = x;
58 setDerivativeOrder(derivativeOrder);
59 }
60
61 /**
62 * @param x point where derivative of polynomial has been evaluated.
63 * @param evaluation evaluation of nth-derivative of polynomial at point x.
64 */
65 public DerivativePolynomialEvaluation(final double x, final double evaluation) {
66 this(x, evaluation, MIN_DERIVATIVE_ORDER);
67 }
68
69 /**
70 * Gets point where polynomial derivative has been evaluated.
71 *
72 * @return point where polynomial derivative has been evaluated.
73 */
74 public double getX() {
75 return x;
76 }
77
78 /**
79 * Sets point where polynomial derivative has been evaluated.
80 *
81 * @param x point where polynomial derivative has been evaluated.
82 */
83 public void setX(final double x) {
84 this.x = x;
85 }
86
87 /**
88 * Gets order of derivative.
89 *
90 * @return order of derivative.
91 */
92 public int getDerivativeOrder() {
93 return derivativeOrder;
94 }
95
96 /**
97 * Sets order of derivative.
98 *
99 * @param derivativeOrder order of derivative.
100 * @throws IllegalArgumentException if order of derivative is less than 1.
101 */
102 public final void setDerivativeOrder(final int derivativeOrder) {
103 if (derivativeOrder < MIN_DERIVATIVE_ORDER) {
104 throw new IllegalArgumentException("derivative order must be at least 1");
105 }
106
107 this.derivativeOrder = derivativeOrder;
108 }
109
110 /**
111 * Gets type of polynomial evaluation.
112 *
113 * @return type of polynomial evaluation.
114 */
115 @Override
116 public PolynomialEvaluationType getType() {
117 return PolynomialEvaluationType.DERIVATIVE_EVALUATION;
118 }
119 }