]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fix bug: if we take values and derivatives of functions that are low
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 30 Apr 2001 16:59:17 +0000 (16:59 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 30 Apr 2001 16:59:17 +0000 (16:59 +0000)
order polynomials, we get into situations where all higher derivatives
are zero. Don't read beyond the end of the array in that case.

git-svn-id: https://svn.dealii.org/trunk@4511 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/polynomial.cc

index 7b4396b588b8c6fa8be2f66a5f7f9b397fe4528a..df160e31619b571482385d1e82cb57ff37d87476 100644 (file)
@@ -75,14 +75,26 @@ Polynomial<number>::value (const number         x,
   const unsigned int m=coefficients.size();
   std::vector<number> a(coefficients);
   unsigned int j_faculty=1;
-  for (unsigned int j=0; j<values_size; ++j)
-    {      
+
+                                  // loop over all requested
+                                  // derivatives. note that
+                                  // derivatives @p{j>m} are
+                                  // necessarily zero, as they
+                                  // differentiate the polynomial
+                                  // more often than the highest
+                                  // power is
+  for (unsigned int j=0; j<std::min(values_size, m); ++j)
+    {
       for (int k=m-2; k>=static_cast<int>(j); --k)
        a[k]+=x*a[k+1];
       values[j]=j_faculty*a[j];
 
       j_faculty*=j+1;
     }
+
+                                  // fill higher derivatives by zero
+  for (unsigned int j=std::min(values_size,m); j<values_size; ++j)
+    values[j] = 0;
 }
 
 

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.