Code-Eli  0.3.6
radius.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef eli_mutil_poly_root_radius_hpp
14 #define eli_mutil_poly_root_radius_hpp
15 
16 #include <cmath>
17 
18 #include "eli/code_eli.hpp"
19 
21 
22 namespace eli
23 {
24  namespace mutil
25  {
26  namespace poly
27  {
28  namespace root
29  {
30  template<typename data__>
31  data__ max_radius(const polynomial<data__> &f)
32  {
33  data__ term, max_term(0), radius(1);
34  typename polynomial<data__>::index_type i, deg(f.degree());
36 
37  // get the coefficient info
38  f.get_coefficients(coef);
39 
40  // cycle through coefficients
41  for (i=0; i<deg; ++i)
42  {
43  term=std::abs(coef(i)/coef(deg));
44  if (term>max_term)
45  max_term=term;
46  }
47  radius+=max_term;
48 
49  return radius;
50  }
51 
52  template<typename data__>
54  {
55  data__ term1, term2, radius(1);
56  typename polynomial<data__>::index_type i, deg(f.degree());
58 
59  // get the coefficient info
60  f.get_coefficients(coef);
61 
62  // calculate the two terms
63  term2=std::pow(std::abs(coef[0]/coef[deg]), 1/static_cast<data__>(deg));
64  if (coef[1]==0)
65  return term2;
66  term1=deg*std::abs(coef[0]/coef[1]);
67  return std::min(term1, term2);
68  }
69  }
70  }
71  }
72 }
73 
74 #endif
data__ max_radius(const polynomial< data__ > &f)
Definition: radius.hpp:31
Definition: math.hpp:20
Definition: polynomial.hpp:31
Eigen::Matrix< data_type, Eigen::Dynamic, 1 > coefficient_type
Definition: polynomial.hpp:35
index_type degree() const
Definition: polynomial.hpp:72
void get_coefficients(coefficient_type &aout) const
Definition: polynomial.hpp:86
coefficient_type::Index index_type
Definition: polynomial.hpp:36
data__ at_least_radius(const polynomial< data__ > &f)
Definition: radius.hpp:53