Index: trunk/psLib/test/dataManip/tst_psMinimize04b.c
===================================================================
--- trunk/psLib/test/dataManip/tst_psMinimize04b.c	(revision 1919)
+++ trunk/psLib/test/dataManip/tst_psMinimize04b.c	(revision 1919)
@@ -0,0 +1,99 @@
+/*****************************************************************************
+    This routine must ensure that the psVectorFitPolynomial1D works correctly.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psVector.h"
+#include "psImage.h"
+#include "psFunctions.h"
+#include "psMinimize.h"
+#include <math.h>
+#define NUM_DATA 15
+#define POLY_ORDER 10
+#define A 2.0
+#define B 3.0
+#define C 2.0
+#define D 4.0
+#define E 5.0
+
+double setData(double x)
+{
+    return(A + (B * x) + (C * x * x) + (D * x * x * x) + (E * x * x * x * x));
+}
+
+int main()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    psVector *yErr = NULL;
+    int i = 0;
+    //    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+    float sum=0.0;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_CHEB);
+    x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F64[i] = (double) i;
+        y->data.F64[i] = setData(x->data.F64[i]);
+        yErr->data.F64[i] = 1.0;
+    }
+    p_psNormalizeVectorF64(x);
+    for (i=0;i<NUM_DATA;i++) {
+        //        printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);
+    }
+
+    sum=0.0;
+    for (i=0;i<NUM_DATA;i++)
+        sum+=y->data.F64[i];
+    printf("c0 is %f\n", 2.0 * sum/((float) NUM_DATA));
+
+    sum=0.0;
+    for (i=0;i<NUM_DATA;i++)
+        sum+=y->data.F64[i] * x->data.F64[i];
+    printf("c1 is %f\n", 2.0 * sum/((float) NUM_DATA));
+    sum=0.0;
+
+    for (i=0;i<NUM_DATA;i++)
+        sum+=y->data.F64[i] * ((2.0 * x->data.F64[i] * x->data.F64[i]) - 1.0);
+    printf("c2 is %f\n", 2.0 * sum/((float) NUM_DATA));
+
+    psVectorFitPolynomial1D(myPoly, x, y, yErr);
+
+    for (i=0;i<POLY_ORDER+1;i++) {
+        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        printf("Fitted data %d: (%.1f %.1f) should be %.1f\n", i, x->data.F64[i],
+               psPolynomial1DEval((float) x->data.F64[i], myPoly), y->data.F64[i]);
+    }
+
+
+    //    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psMinimize functions",
+                "psMinimize(): no masks",
+                testStatus);
+
+    //    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psFree(yErr);
+
+    //    psMemCheckCorruption(1);
+    //    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    return (!testStatus);
+}
