Changeset 26467
- Timestamp:
- Dec 22, 2009, 9:52:30 AM (16 years ago)
- Location:
- branches/eam_branches/20091201/Ohana/src/opihi
- Files:
-
- 1 added
- 4 edited
-
cmd.data/hermitian1d.c (modified) (4 diffs)
-
cmd.data/hermitian2d.c (modified) (4 diffs)
-
include/data.h (modified) (1 diff)
-
lib.data/Makefile (modified) (1 diff)
-
lib.data/hermitian.c (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/Ohana/src/opihi/cmd.data/hermitian1d.c
r26463 r26467 1 # include " astro.h"1 # include "data.h" 2 2 3 3 int hermitian1d (int argc, char **argv) { 4 4 5 int i, order, Nvec, Poly; 6 int *inI; 7 float *out, inF; 8 float mean, sigma; 5 int i, N, order, Nvec, Poly; 6 opihi_int *inI; 7 opihi_flt *out, *inF; 8 opihi_flt mean, sigma, x; 9 double nf, norm; 9 10 Vector *xvec, *yvec; 10 11 … … 15 16 } 16 17 17 if (argc != 6) { 18 gprint (GP_ERR, "USAGE: hermitian1d (x) (y) (mean) (sigma) (order)\n"); 19 return (FALSE); 20 } 18 if (argc != 6) goto usage; 21 19 22 20 /* select input / output buffers */ … … 27 25 28 26 /* gaussian parameters */ 29 mean = atof (argv[3]);27 mean = atof (argv[3]); 30 28 sigma = atof (argv[4]); 31 29 order = atoi (argv[5]); 30 if (order < 0) goto usage; 31 if (order > 10) goto usage; 32 32 33 out = (float *) yvec[0].elements.Flt; 34 inF = (float *) xvec[0].elements.Flt; 35 inI = (int *) xvec[0].elements.Int; 33 out = yvec[0].elements.Flt; 34 inF = xvec[0].elements.Flt; 35 inI = xvec[0].elements.Int; 36 37 nf = exp(lgamma(order + 1)); 38 norm = 1.0 / sqrt(nf*sqrt(2*M_PI)*sigma); 36 39 37 40 // a little sub-optimal : split this up with macros? … … 44 47 *out = hermitian_polynomial (x, order); 45 48 if (!Poly) { 46 *out *= exp (-0.25*x*x);49 *out *= norm*exp (-0.25*x*x); 47 50 } 48 51 } 49 52 return (TRUE); 53 54 usage: 55 gprint (GP_ERR, "USAGE: hermitian1d (x) (y) (mean) (sigma) (order)\n"); 56 gprint (GP_ERR, " Note : only orders up to 10 are supported\n"); 57 return (FALSE); 58 50 59 } 51 60 52 // {\psi}_n(x) = \frac{1}{\sqrt{n! \, 2^n\sqrt{\pi}}}\, \mathrm{e}^{-x^2/2}H_n(x).\,\! 53 54 double hermitian_polynomial (double x, int order) { 55 double value; 56 switch (order) { 57 case 0: 58 value = hermitian_00(x); 59 break; 60 case 1: 61 value = hermitian_01(x); 62 break; 63 case 2: 64 value = hermitian_02(x); 65 break; 66 case 3: 67 value = hermitian_03(x); 68 break; 69 case 4: 70 value = hermitian_04(x); 71 break; 72 case 5: 73 value = hermitian_05(x); 74 break; 75 case 6: 76 value = hermitian_06(x); 77 break; 78 case 7: 79 value = hermitian_07(x); 80 break; 81 case 8: 82 value = hermitian_08(x); 83 break; 84 case 9: 85 value = hermitian_09(x); 86 break; 87 case 10: 88 value = hermitian_10(x); 89 break; 90 default: 91 value = NAN; 92 break; 93 } 94 return value; 95 } 96 97 double hermitian_00(double x) { 98 double value; 99 // H_0(x) = 1 100 value = 1; 101 return value; 102 } 103 double hermitian_01(double x) { 104 double value; 105 // H_1(x) = x 106 value = x; 107 return value; 108 } 109 double hermitian_02(double x) { 110 double value, x2; 111 // H_2(x) = x^2-1 112 x2 = x*x; 113 value = x2 - 1.0; 114 return value; 115 } 116 double hermitian_03(double x) { 117 double value, x2; 118 // H_3(x) = x^3-3x 119 x2 = x*x; 120 value = x*(x2 - 3.0); 121 return value; 122 } 123 double hermitian_04(double x) { 124 double value, x2; 125 // H_4(x) = x^4-6x^2+3 126 x2 = x*x; 127 value = (x2 - 6.0)*x2 + 3.0; 128 return value; 129 } 130 double hermitian_05(double x) { 131 double value, x2; 132 // H_5(x) = x^5-10x^3+15x 133 x2 = x*x; 134 value = ((x2 - 10.0)*x2 + 15.0)*x; 135 return value; 136 } 137 double hermitian_06(double x) { 138 double value, x2; 139 // H_6(x) = x^6-15x^4+45x^2-15 140 x2 = x*x; 141 value = ((x2 - 15.0)*x2 + 45.0*x2) - 15.0; 142 return value; 143 } 144 double hermitian_07(double x) { 145 double value, x2; 146 // H_7(x) = x^7-21x^5+105x^3-105x 147 x2 = x*x; 148 value = (((x2 - 21.0)*x2+105.0)*x2 - 105.0)*x; 149 return value; 150 } 151 double hermitian_08(double x) { 152 double value, x2; 153 // H_8(x) = x^8-28x^6+210x^4-420x^2+105 154 x2 = x*x; 155 value = ((((x2 - 28.0)*x2 + 210.0)*x2 - 420.0)*x2 + 105.0); 156 return value; 157 } 158 double hermitian_09(double x) { 159 double value, x2; 160 // H_9(x) = x^9-36x^7+378x^5-1260x^3+945x 161 x2 = x*x; 162 value = ((((x2 - 36.0)*x2 + 378.0)*x2 - 1260.0)*x2 + 945.0); 163 return value; 164 } 165 double hermitian_10(double x) { 166 double value, x2; 167 // H_{10}(x) = x^{10}-45x^8+630x^6-3150x^4+4725x^2-945 168 x2 = x*x; 169 value = (((((x2 - 45.0)*x2 + 630.0)*x2 - 3150.0)*x2 + 4725.0)*x2 - 945.0); 170 return value; 171 } 61 // {\psi}_n(x) = \frac{1}{\sqrt{n! \, 2^n\sqrt{\pi}}}\, \mathrm{e}^{-x^2/2}H_n(x).\,\! -
branches/eam_branches/20091201/Ohana/src/opihi/cmd.data/hermitian2d.c
r26463 r26467 3 3 int hermitian2d (int argc, char **argv) { 4 4 5 int i, j, N x, Ny, N;5 int i, j, N, Nx, Ny, Xorder, Yorder, Poly; 6 6 float *in; 7 double Sig_x, Sig_y, Theta; 8 double root1, root2, R, A1, A2, A3; 9 double Sx, Sy, Sxy; 10 double x, y, r, f, Xo, Yo; 7 double Xo, Yo, sigma; 8 double x, y, xf, yf, value, norm, weight; 9 double nf, mf; 11 10 Buffer *buf; 12 11 13 Poly = FALSE; 12 // optionally return the Hermitian Polynomial or the Hermitian Function 13 Poly = FALSE; 14 14 if ((N = get_argument (argc, argv, "-poly"))) { 15 15 Poly = TRUE; … … 26 26 } 27 27 28 if (argc > 5) { 29 gprint (GP_ERR, "USAGE: hermitian2d (buffer) (sigma) Xorder Yorder\n"); 30 return (FALSE); 31 } 28 if (argc != 5) goto usage; 32 29 33 30 /* select input / output buffers */ … … 43 40 Xorder = atof (argv[3]); 44 41 Yorder = atof (argv[4]); 42 if (Xorder < 0) goto usage; 43 if (Yorder < 0) goto usage; 44 if (Xorder > 10) goto usage; 45 if (Yorder > 10) goto usage; 46 47 nf = exp(lgamma(Xorder + 1)); 48 mf = exp(lgamma(Yorder + 1)); 49 norm = 1.0 / sqrt(nf*mf*2*M_PI) / sigma; 45 50 46 51 in = (float *) buf[0].matrix.buffer; … … 58 63 value = xf*yf; 59 64 if (!Poly) { 60 value *= xf*yf; 65 weight = norm*exp(-0.25*(x*x + y*y)); 66 value *= weight; 61 67 } 62 68 63 *in += xf*yf;69 *in += value; 64 70 } 65 71 } 66 72 67 73 return (TRUE); 74 75 usage: 76 gprint (GP_ERR, "USAGE: hermitian2d (buffer) (sigma) Xorder Yorder\n"); 77 gprint (GP_ERR, " Note : only orders up to 10 are supported\n"); 78 return (FALSE); 68 79 } -
branches/eam_branches/20091201/Ohana/src/opihi/include/data.h
r26418 r26467 165 165 void FreeBooks (void); 166 166 167 /* hermitian functions */ 168 double hermitian_polynomial (double x, int order); 169 double hermitian_00(double x); 170 double hermitian_01(double x); 171 double hermitian_02(double x); 172 double hermitian_03(double x); 173 double hermitian_04(double x); 174 double hermitian_05(double x); 175 double hermitian_06(double x); 176 double hermitian_07(double x); 177 double hermitian_08(double x); 178 double hermitian_09(double x); 179 double hermitian_10(double x); 180 167 181 # endif -
branches/eam_branches/20091201/Ohana/src/opihi/lib.data/Makefile
r26417 r26467 28 28 $(SDIR)/precess.$(ARCH).o \ 29 29 $(SDIR)/starfuncs.$(ARCH).o \ 30 $(SDIR)/hermitian.$(ARCH).o \ 30 31 $(SDIR)/gaussian.$(ARCH).o \ 31 32 $(SDIR)/graphtools.$(ARCH).o \
Note:
See TracChangeset
for help on using the changeset viewer.
