| 1 | #cxx . . $ `<file>/dwsys/Polynomial.h`/ifndef _Polynomial_h_ |
| 2 | #define _Polynomial_h_cxx . . $ `dwsys/Polynomial.h:2:9`! |
| 3 | /* Polynomial.h |
| 4 | * |
| 5 | * Copyright (C) 1993-2020 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | djmw 20020813 GPL header |
| 23 | djmw 20110306 Latest modification. |
| 24 | */ |
| 25 | |
| 26 | #include "FunctionSeries.h"cxx . . $ `<file>/dwsys/FunctionSeries.h`/ |
| 27 | #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/ |
| 28 | |
| 29 | Thing_definecxx . . $ mutablePolynomial# (Polynomial, FunctionSeries) { |
| 30 | // overridden methods: |
| 31 | public: |
| 32 | virtual double v_evaluatecxx . . $ structPolynomial#v_evaluate(447c67c6676f75c3). (double x); |
| 33 | virtual dcomplexcxx . . $ dcomplex# v_evaluate_zcxx . . $ structPolynomial#v_evaluate_z(b85d93c470fe5288). (dcomplexcxx . . $ dcomplex# z); |
| 34 | virtual void v_evaluateTermscxx . . $ structPolynomial#v_evaluateTerms(c7d2ecbf502d4cf4). (double x, VECcxx . . $ VEC# terms); |
| 35 | virtual void v_getExtremacxx . . $ structPolynomial#v_getExtrema(a54784ab049e7c7d). (double x1, double x2, double *xmin, double *ymin, double *xmax, double *ymax); |
| 36 | }; |
| 37 | |
| 38 | autoPolynomialcxx . . $ autoPolynomial# Polynomial_createcxx . . $ Polynomial_create(7da2dc008a3770b9). (double xmin, double xmax, integercxx . . $ integer# degree); |
| 39 | |
| 40 | autoPolynomialcxx . . $ autoPolynomial# Polynomial_createWithCoefficientscxx . . $ Polynomial_createWithCoefficients(5b87a4d1a4640451). (double xmin, double xmax, constVECVUcxx . . $ constVECVU# const& coefficients); |
| 41 | |
| 42 | void Polynomial_scaleCoefficients_moniccxx . . $ Polynomial_scaleCoefficients_monic(15dc4c37b1a38356). (mutablePolynomialcxx . . $ mutablePolynomial# me); |
| 43 | /* Make coefficent of leading term 1.0 */ |
| 44 | |
| 45 | autoPolynomialcxx . . $ autoPolynomial# Polynomial_scaleXcxx . . $ Polynomial_scaleX(5d8bde0bd4bb491f). (mutablePolynomialcxx . . $ mutablePolynomial# me, double xmin, double xmax); |
| 46 | /* x' = (x-location) / scale */ |
| 47 | |
| 48 | dcomplexcxx . . $ dcomplex# Polynomial_evaluate_zcxx . . $ Polynomial_evaluate_z(5c4acacfc238ab14). (Polynomialcxx . . $ Polynomial# me, dcomplexcxx . . $ dcomplex# z); |
| 49 | /* Evaluate at complex z = x + iy */ |
| 50 | |
| 51 | |
| 52 | /* Product (i=1; numberOfTerms; (1 + a*x + x^2) |
| 53 | * Precondition : my numberOfCoeffcients >= 3+2*numberOfOmegas |
| 54 | * Polynomial is uses as a "buffer". We define it one and reuse it |
| 55 | */ |
| 56 | void Polynomial_initFromProductOfSecondOrderTermscxx . . $ Polynomial_initFromProductOfSecondOrderTerms(9f3ac13450f26e09). (Polynomialcxx . . $ Polynomial# me, constVECVUcxx . . $ constVECVU# const& a); |
| 57 | autoPolynomialcxx . . $ autoPolynomial# Polynomial_createFromProductOfSecondOrderTermscxx . . $ Polynomial_createFromProductOfSecondOrderTerms(5b87a4d1a4640451). (double xmin, double xmax, constVECVUcxx . . $ constVECVU# const& a); |
| 58 | |
| 59 | void Polynomial_initFromRealRootscxx . . $ Polynomial_initFromRealRoots(9f3ac13450f26e09). (Polynomialcxx . . $ Polynomial# me, constVECVUcxx . . $ constVECVU# const& roots); |
| 60 | autoPolynomialcxx . . $ autoPolynomial# Polynomial_createFromRealRootscxx . . $ Polynomial_createFromRealRoots(5b87a4d1a4640451). (double xmin, double xmax, constVECVUcxx . . $ constVECVU# const& roots); |
| 61 | |
| 62 | double Polynomial_getAreacxx . . $ Polynomial_getArea(2ebb020f5d743d85). (Polynomialcxx . . $ Polynomial# me, double xmin, double xmax); |
| 63 | |
| 64 | autoPolynomialcxx . . $ autoPolynomial# Polynomial_getDerivativecxx . . $ Polynomial_getDerivative(11e0cf1518c80ad0). (Polynomialcxx . . $ Polynomial# me); |
| 65 | |
| 66 | autoPolynomialcxx . . $ autoPolynomial# Polynomial_getPrimitivecxx . . $ Polynomial_getPrimitive(8624713bdd99962e). (Polynomialcxx . . $ Polynomial# me, double constant); |
| 67 | |
| 68 | void Polynomial_drawcxx . . $ Polynomial_draw(70147c749a4d92fc). (Polynomialcxx . . $ Polynomial# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, bool garnish); |
| 69 | |
| 70 | double Polynomial_evaluatecxx . . $ Polynomial_evaluate(b9028d57f396b53). (Polynomialcxx . . $ Polynomial# me, double x); |
| 71 | |
| 72 | void Polynomial_evaluateWithDerivativecxx . . $ Polynomial_evaluateWithDerivative(df1c6b65354818cb). (constPolynomialcxx . . $ constPolynomial# me, double x, double *fx, double *dfx); |
| 73 | |
| 74 | autoVECcxx . . $ autoVEC# Polynomial_evaluateDerivativescxx . . $ Polynomial_evaluateDerivatives(ecb270fbd5db97d3). (constPolynomialcxx . . $ constPolynomial# me, double x, long numberOfDerivatives); |
| 75 | /* result [1] is function value at x, result [2..numberOfDerivatives+1] are derivatives at x. */ |
| 76 | |
| 77 | void Polynomial_evaluateTermscxx . . $ Polynomial_evaluateTerms(7b62d278d518bf28). (Polynomialcxx . . $ Polynomial# me, double x, double terms []); |
| 78 | |
| 79 | autoPolynomialcxx . . $ autoPolynomial# Polynomials_multiplycxx . . $ Polynomials_multiply(411b5393091da883). (Polynomialcxx . . $ Polynomial# me, Polynomialcxx . . $ Polynomial# thee); |
| 80 | |
| 81 | void Polynomial_multiply_firstOrderFactorcxx . . $ Polynomial_multiply_firstOrderFactor(126344cf3e2bb2ad). (Polynomialcxx . . $ Polynomial# me, double factor); |
| 82 | /* P(x) * (x-factor) |
| 83 | * Postcondition: my numberOfCoefficients = old_numberOfCoefficients + 1 |
| 84 | */ |
| 85 | |
| 86 | void Polynomial_multiply_secondOrderFactorcxx . . $ Polynomial_multiply_secondOrderFactor(126344cf3e2bb2ad). (Polynomialcxx . . $ Polynomial# me, double factor); |
| 87 | /* P(x) * (x^2 - a) |
| 88 | * Postcondition: my numberOfCoefficients = old_numberOfCoefficients + 2 |
| 89 | */ |
| 90 | |
| 91 | void Polynomials_dividecxx . . $ Polynomials_divide(1067916c3aa4901f). (Polynomialcxx . . $ Polynomial# me, Polynomialcxx . . $ Polynomial# thee, autoPolynomialcxx . . $ autoPolynomial# *out_q, autoPolynomialcxx . . $ autoPolynomial# *out_r); |
| 92 | |
| 93 | void Polynomial_divide_firstOrderFactorcxx . . $ Polynomial_divide_firstOrderFactor(7b62d278d518bf28). (Polynomialcxx . . $ Polynomial# me, double factor, double *p_remainder); // P(x)/(x-a) |
| 94 | /* Functions: calculate coefficients of new polynomial P(x)/(x-a) |
| 95 | * if p_remainder != nullptr it will contain |
| 96 | * remainder after dividing by monomial factor x-a. |
| 97 | * `undefined` if my numberOfCoefficients == 1 (error condition) |
| 98 | * Postcondition: my numberOfCoefficients reduced by 1 |
| 99 | */ |
| 100 | |
| 101 | void Polynomial_divide_secondOrderFactorcxx . . $ Polynomial_divide_secondOrderFactor(126344cf3e2bb2ad). (Polynomialcxx . . $ Polynomial# me, double factor); |
| 102 | /* P(x) / (x^2 - a) |
| 103 | * Postcondition: my numberOfCoefficients = old_numberOfCoefficients - 2 |
| 104 | */ |
| 105 | |
| 106 | double Polynomial_findOneSimpleRealRoot_nrcxx . . $ Polynomial_findOneSimpleRealRoot_nr(2ebb020f5d743d85). (Polynomialcxx . . $ Polynomial# me, double xmin, double xmax); |
| 107 | double Polynomial_findOneSimpleRealRoot_ridderscxx . . $ Polynomial_findOneSimpleRealRoot_ridders(2ebb020f5d743d85). (Polynomialcxx . . $ Polynomial# me, double xmin, double xmax); |
| 108 | /* Preconditions: there must be exactly one root in the [xmin, xmax] interval; |
| 109 | * Root will be found by newton-raphson with bisecting |
| 110 | */ |
| 111 | |
| 112 | #endif /* _Polynomial_h_ */ |