This is ratfn.h in view mode; [Download] [Up]
#ifndef RATFNH #define RATFNH #include "polynomial.h" class partial_fraction { public: complex root, coeff; int multiplicity; complex operator()( complex z ); complex evaluate_integral(complex z1, complex z2); complex invert_z_transform( int n ); }; const int polynomial_quotient=1, partial_fraction_sum=2; class ratfn { public: // for the quotient of polynomials representation polynomial num, den; // for the sum of partial fractions representation polynomial leading_polynomial; // causes warning messages when I do bit-set & bit-clear operations on valid // enum { polynomial_quotient=1, partial_fraction_sum=2 } valid; int valid; partial_fraction *pf; int n_pf; // could also use continued fraction representation // ... ratfn(){ polynomial num, den; valid=0; } ratfn(const polynomial& p) { num=p; den=complex(1); valid = polynomial_quotient; } ratfn(const partial_fraction p); // Needed because C++ doesn't try multiple user-defined conversions ratfn(const transform_variable z); ratfn(const complex z); ratfn(const double z); ~ratfn() { if( pf_valid() ) delete pf; } void simplify(); int read_in( const char * ); polynomial reduce(); void print_partial_fraction(); double choose(int ,int ); double factorial(int); friend ratfn operator*( const ratfn&, const ratfn& ); complex operator() ( complex x ){ return num(x)/den(x); } complex pf_evaluate(complex x); // special cases which may one day be worth implementing // friend ratfn operator+( const ratfn&, const double ); // friend ratfn operator-( const ratfn&, const double ); friend ratfn operator+( const ratfn&, const ratfn& ); friend ratfn operator-( const ratfn&, const ratfn& ); friend ratfn operator/( const polynomial&, const polynomial& ); /* this pile of code is needed to handle multiple representations */ // // FOR NOW, I'LL ASSUME THAT THE QUOTIENT OF POLYNOMIALS REPRESENTATION // IS ALWAYS CORRECT. I'LL ONLY PROVIDE THE FACILITY TO CALCULATE THE // PARTIAL FRACTION REPRESENTATION. // int nd_valid(){ return valid & polynomial_quotient; } void nd_valid (int ok) { if (ok) valid |= polynomial_quotient; else valid &= ~polynomial_quotient; } int pf_valid(){ return valid & partial_fraction_sum; } void pf_valid( int ok ); void calculate_partial_fraction_expansion(); void bless_partial_fraction() { if (!pf_valid()) calculate_partial_fraction_expansion(); } void make_consistent(){ bless_partial_fraction(); } complex invert_z_transform( int n ); double integrate_mag2_along_unit_circle( double f1, double f2 ); ratfn unitCircleMagnitudeSquared(); double analytically_integrate_along_C( double f1, double f2 ); int encircles_more_than_halfway( complex z, complex z1, complex z2 ); double numerically_integrate_mag2_along_C( double f1, double f2 ); double pf_error( double f1, double f2 ); int stable(); double h1(); }; ostream& operator<<(ostream&, const partial_fraction& ); ostream& operator<<(ostream&, const ratfn& ); istream& operator>>(istream&, ratfn& ); #endif
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.