~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/2geom/poly-dk-solve.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Kees Cook, Ted Gould
  • Date: 2008-02-10 14:20:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080210142016-vcnb2zqyhszu0xvb
Tags: 0.46~pre1-0ubuntu1
[ Kees Cook ]
* debian/control:
  - add libgtkspell-dev build-dep to gain GtkSpell features (LP: #183547).
  - update Standards version (no changes needed).
  - add Vcs and Homepage fields.
  - switch to new python-lxml dep.
* debian/{control,rules}: switch from dpatch to quilt for more sanity.
* debian/patches/20_fix_glib_and_gxx43_ftbfs.patch:
  - merged against upstream fixes.
  - added additional fixes for newly written code.
* debian/rules: enable parallel building.

[ Ted Gould ]
* Updating POTFILES.in to make it so things build correctly.
* debian/control:
  - add ImageMagick++ and libboost-dev to build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "poly-dk-solve.h"
 
2
#include <iterator>
 
3
 
 
4
/*** implementation of the Durand-Kerner method.  seems buggy*/
 
5
 
 
6
std::complex<double> evalu(Poly const & p, std::complex<double> x) {
 
7
    std::complex<double> result = 0;
 
8
    std::complex<double> xx = 1;
 
9
 
 
10
    for(unsigned i = 0; i < p.size(); i++) {
 
11
        result += p[i]*xx;
 
12
        xx *= x;
 
13
    }
 
14
    return result;
 
15
}
 
16
 
 
17
std::vector<std::complex<double> > DK(Poly const & ply, const double tol) {
 
18
    std::vector<std::complex<double> > roots;
 
19
    const int N = ply.degree();
 
20
 
 
21
    std::complex<double> b(0.4, 0.9);
 
22
    std::complex<double> p = 1;
 
23
    for(int i = 0; i < N; i++) {
 
24
        roots.push_back(p);
 
25
        p *= b;
 
26
    }
 
27
    assert(roots.size() == ply.degree());
 
28
 
 
29
    double error = 0;
 
30
    int i;
 
31
    for( i = 0; i < 30; i++) {
 
32
        error = 0;
 
33
        for(int r_i = 0; r_i < N; r_i++) {
 
34
            std::complex<double> denom = 1;
 
35
            std::complex<double> R = roots[r_i];
 
36
            for(int d_i = 0; d_i < N; d_i++) {
 
37
                if(r_i != d_i)
 
38
                    denom *= R-roots[d_i];
 
39
            }
 
40
            assert(norm(denom) != 0);
 
41
            std::complex<double> dr = evalu(ply, R)/denom;
 
42
            error += norm(dr);
 
43
            roots[r_i] = R - dr;
 
44
        }
 
45
        /*std::copy(roots.begin(), roots.end(), std::ostream_iterator<std::complex<double> >(std::cout, ",\t"));
 
46
          std::cout << std::endl;*/
 
47
        if(error < tol)
 
48
            break;
 
49
    }
 
50
    //std::cout << error << ", " << i<< std::endl;
 
51
    return roots;
 
52
}
 
53
 
 
54
 
 
55
/*
 
56
  Local Variables:
 
57
  mode:c++
 
58
  c-file-style:"stroustrup"
 
59
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
60
  indent-tabs-mode:nil
 
61
  fill-column:99
 
62
  End:
 
63
*/
 
64
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :