IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1902


Ignore:
Timestamp:
Sep 25, 2004, 1:04:45 PM (22 years ago)
Author:
gusciora
Message:

Added more splines to increase the accuracy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psFunc07.c

    r1900 r1902  
    77XXX: figure out the memory deallocator
    88 
    9 XXX: The interpolated values are not all that good.  However, they do agree
    10 with the NR version of the code.
     9XXX: Remove NR code.
    1110 *****************************************************************************/
    1211#include <stdio.h>
     
    1716#include "psFunctions.h"
    1817
    19 #define NUM_SPLINES 4
     18#define NUM_SPLINES 200
    2019#define A 4.0
    2120#define B -3.0
     
    2423#define MIN 1.0
    2524#define MAX 30
     25#define ERROR_TOLERANCE 0.10
    2626
    2727float myFunc(float x)
    2828{
    2929    return(A + x * (B + x * (C + x * (D))));
    30     //    return(A + x * (B + x * (C)));
    31     //    return(A + x * (B));
    32     //    return(A);
    3330}
    34 
    3531
    3632/*****************************************************************************
     
    107103    float NRX[NUM_SPLINES+2];
    108104    float NRY[NUM_SPLINES+2];
    109     float tmpY;
    110     float derivs[NUM_SPLINES+2];
     105    //    float tmpY;
     106    //    float derivs[NUM_SPLINES+2];
    111107
    112108    psTraceSetLevel(".", 0);
     
    125121        NRX[i+1] = x->data.F32[i] = tmpSpline->domains[i];
    126122        NRY[i+1] = y->data.F32[i] = myFunc(x->data.F32[i]);
    127         printf("DATA: (x, y) is (%f, %f)\n", x->data.F32[i], y->data.F32[i]);
     123        //        printf("DATA: (x, y) is (%f, %f)\n", x->data.F32[i], y->data.F32[i]);
    128124    }
    129125    for (i=0;i<NUM_SPLINES;i++) {
     
    134130    /*   NR Code       */
    135131    /****************************************************************************/
    136     printf("========================== NR Code =========================\n");
    137     spline(&NRX[0],
    138            &NRY[0],
    139            NUM_SPLINES+1,
    140            0.0,
    141            0.0,
    142            &derivs[0]);
    143     for (i=1;i<=NUM_SPLINES+1;i++) {
    144         printf("NR: derivs[%d] is %f\n", i, derivs[i]);
    145     }
    146 
    147     for (i=1;i<=NUM_SPLINES+1;i++) {
    148         printf("===================================================\n");
    149         splint(&NRX[0],
     132    /*
     133        printf("========================== NR Code =========================\n");
     134        spline(&NRX[0],
    150135               &NRY[0],
    151                &derivs[0],
    152136               NUM_SPLINES+1,
    153                newX->data.F32[i-1],
    154                &tmpY);
    155 
    156         printf("NR: p_psNRSpline1DEval(%f) is %f.  Should be %f\n",
    157                newX->data.F32[i-1], tmpY, myFunc(newX->data.F32[i-1]));
    158     }
    159 
    160 
     137               0.0,
     138               0.0,
     139               &derivs[0]);
     140        for (i=1;i<=NUM_SPLINES+1;i++) {
     141            printf("NR: derivs[%d] is %f\n", i, derivs[i]);
     142        }
     143     
     144        for (i=1;i<=NUM_SPLINES+1;i++) {
     145            printf("===================================================\n");
     146            splint(&NRX[0],
     147                   &NRY[0],
     148                   &derivs[0],
     149                   NUM_SPLINES+1,
     150                   newX->data.F32[i-1],
     151                   &tmpY);
     152     
     153            printf("NR: p_psNRSpline1DEval(%f) is %f.  Should be %f\n",
     154                    newX->data.F32[i-1], tmpY, myFunc(newX->data.F32[i-1]));
     155        }
     156    */
    161157    /****************************************************************************/
    162158    /*   psLib Code      */
     
    164160    psVectorFitSpline1D(tmpSpline, x, y, NULL);
    165161    for (i=0;i<NUM_SPLINES+1;i++) {
    166         printf("psLib: derivs[%d] is %f\n", i, tmpSpline->p_psDeriv2[i]);
     162        //       printf("psLib: derivs[%d] is %f\n", i, tmpSpline->p_psDeriv2[i]);
    167163    }
    168164    newY = psSpline1DEvalVector(newX, tmpSpline);
    169165
    170166    for (i=0;i<NUM_SPLINES+1;i++) {
    171         printf("===================================================\n");
    172         printf("EVAL: f(%f) is %f.  Should be %f\n",
    173                newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i]));
    174 
    175         tmpY = p_psNRSpline1DEval(tmpSpline, x, y, newX->data.F32[i]);
    176         printf("HMMM: p_psNRSpline1DEval(%f) is %f.  Should be %f\n",
    177                newX->data.F32[i], tmpY, myFunc(newX->data.F32[i]));
     167        if ( fabs( newY->data.F32[i] - myFunc(newX->data.F32[i]) ) > fabs( ERROR_TOLERANCE * myFunc(newX->data.F32[i]) ) ) {
     168            printf("ERROR[%d]: f(%f) is %f.  Should be %f\n", i,
     169                   newX->data.F32[i], newY->data.F32[i], myFunc(newX->data.F32[i]));
     170        }
     171        //        tmpY = p_psNRSpline1DEval(tmpSpline, x, y, newX->data.F32[i]);
     172        //        printf("HMMM: p_psNRSpline1DEval(%f) is %f.  Should be %f\n",
     173        //                newX->data.F32[i], tmpY, myFunc(newX->data.F32[i]));
    178174    }
    179175
Note: See TracChangeset for help on using the changeset viewer.