poly.cpp revision 981b809bc6ed10a21e89444d9447e5475801874f
#include "poly.h"
for(unsigned i = 0; i < size(); i++) {
for(unsigned j = 0; j < p.size(); j++) {
result[i+j] += (*this)[i] * p[j];
}
}
return result;
}
#ifdef HAVE_GSL
#include <gsl/gsl_poly.h>
#endif
/*double Poly::eval(double x) const {
return gsl_poly_eval(&coeff[0], size(), x);
}*/
while(back() == 0)
pop_back();
}
normalize();
for(unsigned i = 0; i < size(); i++) {
(*this)[i] *= scale;
}
}
#ifdef HAVE_GSL
p.normalize();
= gsl_poly_complex_workspace_alloc (p.size());
double* a = new double[p.size()];
for(int i = 0; i < p.size(); i++)
a[i] = p[i];
//roots.resize(p.degree());
gsl_poly_complex_solve (a, p.size(), w, z);
delete[]a;
for (int i = 0; i < p.degree(); i++) {
//printf ("z%d = %+.18f %+.18f\n", i, z[2*i], z[2*i+1]);
}
delete[] z;
return roots;
}
}
return real_roots;
}
#endif
}
return guess;
}
for(unsigned i = 0; i < p.size(); i++) {
}
return result;
}
if(p.size() <= 1)
return Poly(0);
for(unsigned i = 1; i < p.size(); i++) {
}
return result;
}
for(unsigned i = a.size()-1; i >=0; i--) {
}
return result;
}
/* This version is backwards - dividing taylor terms
Poly divide(Poly const &a, Poly const &b, Poly &r) {
Poly c;
r = a; // remainder
const unsigned k = a.size();
r.resize(k, 0);
c.resize(k, 0);
for(unsigned i = 0; i < k; i++) {
double ci = r[i]/b[0];
c[i] += ci;
Poly bb = ci*b;
std::cout << ci <<"*" << b << ", r= " << r << std::endl;
r -= bb.shifted(i);
}
return c;
}
*/
Poly c;
r = a; // remainder
const unsigned k = a.degree();
const unsigned l = b.degree();
c.resize(k, 0.);
for(unsigned i = k; i >= l; i--) {
assert(i >= 0);
c[i-l] += ci;
//std::cout << ci <<"*(" << b.shifted(i-l) << ") = "
// << bb.shifted(i-l) << " r= " << r << std::endl;
r.pop_back();
}
//std::cout << "r= " << r << std::endl;
r.normalize();
c.normalize();
return c;
}
return gcd(b, a);
if(b.size() <= 0)
return a;
if(b.size() == 1)
return a;
Poly r;
divide(a, b, r);
return gcd(b, r);
}
/*Poly divide_out_root(Poly const & p, double x) {
assert(1);
}*/
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :