/**
* \file
* \brief Polynomial in canonical (monomial) basis
*//*
* Authors:
* MenTaLguY <mental@rydia.net>
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright 2007-2015 Authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*/
#include <algorithm>
#include <math.h>
#ifdef HAVE_GSL
#include <gsl/gsl_poly.h>
#endif
namespace Geom {
for(unsigned i = 0; i < size(); i++) {
for(unsigned j = 0; j < p.size(); j++) {
result[i+j] += (*this)[i] * p[j];
}
}
return result;
}
/*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(unsigned 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 (unsigned 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(); 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);
}
{
if (a == 0) {
// linear equation
if (b == 0) return result;
return result;
}
if (delta == 0) {
// one root
} else if (delta > 0) {
// two roots
// Use different formulas depending on sign of b to preserve
// numerical stability. See e.g.:
}
// no roots otherwise
return result;
}
{
// based on:
if (a == 0) {
return solve_quadratic(b, c, d);
}
if (d == 0) {
// divide by x
return result;
}
// 1. divide everything by a to bring to canonical form
b /= a;
c /= a;
d /= a;
// 2. eliminate x^2 term: x^3 + 3Qx - 2R = 0
// 3. compute polynomial discriminant
Coord D = Q*Q*Q + R*R;
if (D > 0) {
// only one real root
} else if (D == 0) {
// 3 real roots, 2 of which are equal
} else {
// 3 distinct real roots
assert(Q < 0);
}
return result;
}
/*Poly divide_out_root(Poly const & p, double x) {
assert(1);
}*/
} //namespace Geom
/*
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:fileencoding=utf-8:textwidth=99 :