Changeset 1902
- Timestamp:
- Sep 25, 2004, 1:04:45 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psFunc07.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psFunc07.c
r1900 r1902 7 7 XXX: figure out the memory deallocator 8 8 9 XXX: The interpolated values are not all that good. However, they do agree 10 with the NR version of the code. 9 XXX: Remove NR code. 11 10 *****************************************************************************/ 12 11 #include <stdio.h> … … 17 16 #include "psFunctions.h" 18 17 19 #define NUM_SPLINES 418 #define NUM_SPLINES 200 20 19 #define A 4.0 21 20 #define B -3.0 … … 24 23 #define MIN 1.0 25 24 #define MAX 30 25 #define ERROR_TOLERANCE 0.10 26 26 27 27 float myFunc(float x) 28 28 { 29 29 return(A + x * (B + x * (C + x * (D)))); 30 // return(A + x * (B + x * (C)));31 // return(A + x * (B));32 // return(A);33 30 } 34 35 31 36 32 /***************************************************************************** … … 107 103 float NRX[NUM_SPLINES+2]; 108 104 float NRY[NUM_SPLINES+2]; 109 float tmpY;110 float derivs[NUM_SPLINES+2];105 // float tmpY; 106 // float derivs[NUM_SPLINES+2]; 111 107 112 108 psTraceSetLevel(".", 0); … … 125 121 NRX[i+1] = x->data.F32[i] = tmpSpline->domains[i]; 126 122 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]); 128 124 } 129 125 for (i=0;i<NUM_SPLINES;i++) { … … 134 130 /* NR Code */ 135 131 /****************************************************************************/ 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], 150 135 &NRY[0], 151 &derivs[0],152 136 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 */ 161 157 /****************************************************************************/ 162 158 /* psLib Code */ … … 164 160 psVectorFitSpline1D(tmpSpline, x, y, NULL); 165 161 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]); 167 163 } 168 164 newY = psSpline1DEvalVector(newX, tmpSpline); 169 165 170 166 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])); 178 174 } 179 175
Note:
See TracChangeset
for help on using the changeset viewer.
