[Kst] kdeextragear-2/kst/plugins/fits/polynomial_weighted

Andrew Walker arwalker at sumusltd.com
Fri Jan 23 00:24:21 CET 2004


CVS commit by arwalker: 

Minor cosmetic changes


  M +24 -22    kstfit_polynomial_weighted.cpp   1.2


--- kdeextragear-2/kst/plugins/fits/polynomial_weighted/kstfit_polynomial_weighted.cpp  #1.1:1.2
@@ -9,7 +9,7 @@
 #include <gsl/gsl_multifit.h>
 
-#define X                                       0
-#define Y                                       1
-#define W                                       2
+#define XVALUES                 0
+#define YVALUES                 1
+#define WVALUES                 2
 
 #define YFIT                            0
@@ -45,17 +45,18 @@ int kstfit_polynomial_weighted(
   int j;
   int iOrder;
+  int   iStatus = 0;
   int   iLength;
   int iReturn = -1;
   
-  if (inArrayLens[Y] >= 2 && inArrayLens[X] >= 2) {
-    iLength = inArrayLens[Y];
-    if( inArrayLens[X] < iLength ) {
-      iLength = inArrayLens[X];
+  if (inArrayLens[YVALUES] >= 2 && inArrayLens[XVALUES] >= 2) {
+    iLength = inArrayLens[YVALUES];
+    if( inArrayLens[XVALUES] < iLength ) {
+      iLength = inArrayLens[XVALUES];
     }
-    if( inArrayLens[W] < iLength ) {
-      iLength = inArrayLens[W];
+    if( inArrayLens[WVALUES] < iLength ) {
+      iLength = inArrayLens[WVALUES];
     }
     
-    iOrder = (int)inScalars[0];
+    iOrder = (int)ceil( inScalars[0] );
     
     //
@@ -135,13 +136,14 @@ int kstfit_polynomial_weighted(
                     //
                     for( i=0; i<iLength; i++ ) {
-                      gsl_vector_set( pVectorY, i, inArrays[Y][i] );
-                      gsl_vector_set( pVectorWeights, i, inArrays[W][i] );
+                      gsl_vector_set( pVectorY, i, inArrays[YVALUES][i] );
+                      gsl_vector_set( pVectorWeights, i, inArrays[WVALUES][i] );
                       for( j=0; j<iOrder; j++ ) {
-                        dX = pow( inArrays[X][i], (double)j );
+                        dX = pow( inArrays[XVALUES][i], (double)j );
                         gsl_matrix_set( pMatrixX, i, j, dX );
                       }
                     }
 
-                    if( gsl_multifit_wlinear( pMatrixX, 
+                   
+                    iStatus = gsl_multifit_wlinear( pMatrixX, 
                                               pVectorWeights,
                                               pVectorY, 
@@ -149,5 +151,6 @@ int kstfit_polynomial_weighted(
                                               pMatrixCovariance, 
                                               &dChiSq, 
-                                              pWork ) != 0 ) {
+                                                    pWork );
+                    if( iStatus == 0 ) {
                       //
                       // fill in the output arrays and scalars...
@@ -160,5 +163,5 @@ int kstfit_polynomial_weighted(
                         }
                         outArrays[YFIT][i] = dY;
-                        outArrays[YRESIDUALS][i] = inArrays[Y][i] - dY;
+                        outArrays[YRESIDUALS][i] = inArrays[YVALUES][i] - dY;
                       }
                       





More information about the Kst mailing list