# include # include # include # include # include # include using namespace std; # include "c8poly.hpp" //****************************************************************************80 void c8poly_print ( int n, complex c[], string title ) //****************************************************************************80 // // Purpose: // // c8poly_print() prints out a polynomial. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 08 December 2023 // // Author: // // John Burkardt // // Input: // // int N, the dimension of C. // // complex C[N+1], the polynomial coefficients. // C(0) is the constant term and // C(N) is the coefficient of X^N. // // string TITLE, a title. // { int i; cout << "\n"; if ( n < 0 ) { cout << " p(z) = 0\n"; return; } if ( 2 <= n ) { cout << " p(z) = ( " << real ( c[n] ) << ", " << imag ( c[n] ) << " ) * z^" << n << "\n"; } else if ( n == 1 ) { cout << " p(z) = ( " << real ( c[n] ) << ", " << imag ( c[n] ) << " ) * z" << "\n"; } else if ( n == 0 ) { cout << " p(z) = ( " << real ( c[n] ) << ", " << imag ( c[n] ) << ")"; } for ( i = n - 1; 0 <= i; i-- ) { if ( 2 <= i ) { cout << " + ( " << real ( c[i] ) << ", " << imag ( c[i] ) << " ) * z^" << i << "\n"; } else if ( i == 1 ) { cout << " + ( " << real ( c[i] ) << ", " << imag ( c[i] ) << " ) * z" << "\n"; } else if ( i == 0 ) { cout << " + ( " << real ( c[i] ) << ", " << imag ( c[i] ) << " )\n"; } } return; } //*****************************************************************************/ complex *roots_to_c8poly ( int n, complex r[] ) //*****************************************************************************/ // // Purpose: // // roots_to_c8poly() converts polynomial roots to polynomial coefficients. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 08 December 2023 // // Author: // // John Burkardt // // Input: // // int N, the number of roots. // // complex R[N], the roots. // // Output: // // complex ROOTS_TO_C8POLY[N+1], the coefficients of the polynomial. // { complex *c; int i; int j; c = new complex [n+1]; // // Initialize C to (0, 0, ..., 0, 1). // Essentially, we are setting up a divided difference table. // for ( i = 0; i < n; i++ ) { c[i] = 0.0; } c[n] = 1.0; // // Convert to standard polynomial form by shifting the abscissas // of the divided difference table to 0. // for ( j = 1; j <= n; j++ ) { for ( i = 1; i <= n + 1 - j; i++ ) { c[n-i] = c[n-i] - r[n+1-i-j] * c[n-i+1]; } } return c; }