]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Legendre polynomials fixed
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 28 May 2001 11:27:22 +0000 (11:27 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 28 May 2001 11:27:22 +0000 (11:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@4734 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/polynomial.h
deal.II/base/source/legendre.cc

index 5153321895b1ecad0c44a4501e36020850fb73da..b520904bbc8a0f338391100c2539441efe4f5b34 100644 (file)
@@ -43,7 +43,7 @@ class Polynomial : public Subscriptor
                                      * of the array denotes the
                                      * constant term, the second the
                                      * linear one, and so on. The
-                                     * order of the polynomial
+                                     * degree of the polynomial
                                      * represented by this object is
                                      * thus the number of elements in
                                      * the @p{coefficient} array
@@ -85,6 +85,17 @@ class Polynomial : public Subscriptor
     void value (const number         x,
                std::vector<number> &values) const;
 
+                                    /**
+                                     * Degree of the polynomial. This
+                                     * is the degree reflected by the
+                                     * number of coefficients
+                                     * provided by the
+                                     * constructor. Leading non-zero
+                                     * coefficients are not treated
+                                     * separately.
+                                     */
+    unsigned int degree () const;
+    
                                     /**
                                      * Exception
                                      */
@@ -214,5 +225,14 @@ class Legendre : public Polynomial<number>
 };
 
 
+template <typename number>
+inline
+unsigned int
+Polynomial<number>::degree () const
+{
+  Assert (coefficients.size()>0, ExcVoidPolynomial());
+  return coefficients.size() - 1;
+}
+
 #endif
 
index cc3c975d4445086ec5043b4b1448df08fddeed96..81c74a4a418e2baa118a2cbbf5434ca9a5fd4689 100644 (file)
@@ -91,15 +91,17 @@ Legendre<number>::compute_coefficients (const unsigned int k)
 
          std::vector<number> *ck = new std::vector<number>(k+1);
          
-         const number a = 1./k+1;
-         const number b = a*(2*k+1);
+         const number a = 1./(k);
+         const number b = a*(2*k-1);
+         const number c = a*(k-1);
          
          (*ck)[k]   = b*(*coefficients[k-1])[k-1];
          (*ck)[k-1] = b*(*coefficients[k-1])[k-2];
          for (unsigned int i=1 ; i<= k-2 ; ++i)
            (*ck)[i] = b*(*coefficients[k-1])[i-1]
-                      - k*a*(*coefficients[k-2])[i];
-         (*ck)[0]   = -k*a*(*coefficients[k-2])[0];
+                      -c*(*coefficients[k-2])[i];
+
+         (*ck)[0]   = -c*(*coefficients[k-2])[0];
 
                                           // finally assign the newly
                                           // created vector to the

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.