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; 17 18 import com.irurueta.algebra.Complex; 19 20 /** 21 * Utility class to evaluate complex polynomials. 22 * This class is useful when the same complex polynomial needs to be evaluated 23 * multiple times. 24 */ 25 public class ComplexPolynomialEvaluator extends PolynomialEvaluator { 26 27 /** 28 * Polynomial coefficients. 29 * A polynomial of degree n is defined as: 30 * p(x) = a0 * x^n + a1 * x^(n - 1) + ... a(n-1) * x + an 31 * Hence, the array of polynomial coefficients is [a0, a1, ... a(n-1), an] 32 */ 33 private final Complex[] polyParams; 34 35 /** 36 * Constructor. 37 * 38 * @param polyParams polynomial coefficients 39 * @throws IllegalArgumentException if provided array is null or has length 40 * 0. 41 */ 42 public ComplexPolynomialEvaluator(final Complex[] polyParams) { 43 if (polyParams == null || polyParams.length == 0) { 44 throw new IllegalArgumentException(); 45 } 46 47 this.polyParams = polyParams; 48 } 49 50 /** 51 * Gets polynomial parameters. 52 * 53 * @return polynomial parameters. 54 */ 55 public Complex[] getPolyParams() { 56 return polyParams; 57 } 58 59 /** 60 * Evaluates polynomial at provided point x. 61 * 62 * @param x point where polynomial is evaluated. 63 * @return result of evaluation. 64 */ 65 public Complex evaluate(final Complex x) { 66 return evaluate(polyParams, x); 67 } 68 }