Changeset 1907 for trunk/psLib/src/dataManip/psMinimize.c
- Timestamp:
- Sep 27, 2004, 1:41:42 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/dataManip/psMinimize.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/dataManip/psMinimize.c
r1879 r1907 9 9 * @author George Gusciora, MHPCC 10 10 * 11 * @version $Revision: 1.4 8$ $Name: not supported by cvs2svn $12 * @date $Date: 2004-09-2 4 20:08:22 $11 * @version $Revision: 1.49 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2004-09-27 23:41:42 $ 13 13 * 14 14 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 53 53 /* DEFINE STATEMENTS */ 54 54 /*****************************************************************************/ 55 56 /** Preprocessor macro to generate error on a NULL 1DPolynomial */57 #define PS_CHECK_NULL_1DPOLY(NAME) \58 if (NAME == NULL || NAME->coeff == NULL) { \59 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \60 }61 62 /** Preprocessor macro to generate error on a NULL vector */63 #define PS_CHECK_NULL_VECTOR(NAME) \64 if (NAME == NULL || NAME->data.V == NULL) { \65 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \66 }67 68 /** Preprocessor macro to generate error for zero length vector */69 #define PS_CHECK_EMPTY_VECTOR(NAME) \70 if (NAME->n < 1) { \71 psError(__func__,"Invalid operation: %s has zero n value.", #NAME); \72 }73 74 /** Preprocessor macro to generate error on differing size vectors */75 #define PS_CHECK_VECTOR_SIZE_EQUAL(VEC1, VEC2) \76 if (VEC1->n != VEC2->n) { \77 psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \78 }79 80 /** Preprocessor macro to generate error on a NULL image */81 #define PS_CHECK_NULL_IMAGE(NAME) \82 if (NAME == NULL || NAME->data.V == NULL) { \83 psError(__func__,"Invalid operation: %s or its data is NULL.", #NAME); \84 }85 86 /** Preprocessor macro to generate error for zero length rows or columns */87 #define PS_CHECK_EMPTY_IMAGE(NAME) \88 if (NAME->numCols < 1 || NAME->numRows < 1) { \89 psError(__func__,"Invalid operation: %s has zero rows or columns (%dx%d).", #NAME, \90 NAME->numCols, NAME->numRows); \91 }92 55 93 56 /*****************************************************************************/ … … 692 655 } 693 656 657 658 /***************************************************************************** 659 CreateChebyshevPolys(n): this routine takes as input the required order n, 660 and returns as output as a pointer to an array of n psPolynomial1D 661 structures, corresponding to the first n Chebyshev polynomials. 662 663 XXX: The output should be static since the Chebyshev polynomials might be 664 used frequently and the data structure created here does not contain the 665 outer coefficients of the Chebyshev polynomials. 666 *****************************************************************************/ 667 static psPolynomial1D **CreateChebyshevPolys(int maxChebyPoly) 668 { 669 psPolynomial1D **chebPolys = NULL; 670 int i = 0; 671 int j = 0; 672 673 chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *)); 674 for (i = 0; i < maxChebyPoly; i++) { 675 chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD); 676 } 677 678 // Create the Chebyshev polynomials. 679 // Polynomial i has i-th order. 680 chebPolys[0]->coeff[0] = 1; 681 chebPolys[1]->coeff[1] = 1; 682 for (i = 2; i < maxChebyPoly; i++) { 683 for (j = 0; j < chebPolys[i - 1]->n; j++) { 684 chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j]; 685 } 686 for (j = 0; j < chebPolys[i - 2]->n; j++) { 687 chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j]; 688 } 689 } 690 691 return (chebPolys); 692 } 693 694 695 696 psPolynomial1D* p_psVectorFitPolynomial1DCheby(psPolynomial1D* myPoly, 697 const psVector* restrict x, 698 const psVector* restrict y, 699 const psVector* restrict yErr) 700 { 701 int j; 702 int k; 703 int n = x->n; 704 psPolynomial1D **chebPolys = CreateChebyshevPolys(myPoly->n); 705 ; 706 float fac; 707 float sum; 708 /* 709 fac = 2.0/((float) n); 710 for (j=0;j<n;j++) { 711 sum = 0.0; 712 for (k=0;k<n;k++) { 713 sum+= y->data.F64[k] * 714 cos(M_PI * ((float) j) * (0.5 + ((float) k)) / ((float) n)); 715 // sum+= y->data.F64[k] * 716 // cos(M_PI * ((float) j) * (-0.5 + ((float) k)) / ((float) n)) * 717 // cos(M_PI * (-0.5 + ((float) k)) / ((float) n)); 718 719 } 720 myPoly->coeff[j] = fac * sum; 721 722 } 723 return(myPoly); 724 */ 725 726 fac = 2.0/((float) n); 727 for (j=0;j<myPoly->n;j++) { 728 sum = 0.0; 729 for (k=1;k<n;k++) { 730 sum+= (y->data.F64[k] * 731 psPolynomial1DEval((float) x->data.F64[k], chebPolys[j])); 732 } 733 myPoly->coeff[j] = fac * sum; 734 } 735 return(myPoly); 736 } 737 694 738 /****************************************************************************** 695 739 psVectorFitPolynomial1D(): This routine must fit a polynomial of degree … … 704 748 705 749 XXX: Must do: if yErr==NULL, set all errors equal. 750 751 XXX: type is currently ignored. Must implement this for Chebyshev 752 polynomials. 706 753 *****************************************************************************/ 707 754 psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly, … … 710 757 const psVector* restrict yErr) 711 758 { 759 // XXX: Create a p_psVectorFitPolynomial1DOrd() function. Here, we 760 // should only be calling that or the Cheby function. 761 762 if (myPoly->type == PS_POLYNOMIAL_CHEB) { 763 return(p_psVectorFitPolynomial1DCheby(myPoly, x, y, yErr)); 764 } 765 712 766 int polyOrder = myPoly->n; 713 767 psImage* A = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
