public double e(double x) { return _a*_b*cos(_b*x); } public double emax() {
private static double h3(double r) { if (r==0.0) { return PIO6; } else { double pir = PI*r; return 0.5*PI*(sin(pir)-pir*cos(pir))/(pir*pir*pir); } } }
private float[][] makeCirclePoints() { int nt = 1000; double dt = 2.0*DBL_PI/(nt-1); float[] x = new float[nt]; float[] y = new float[nt]; for (int it=0; it<nt; ++it) { float t = (float)(it*dt); x[it] = cos(t); y[it] = sin(t); } return new float[][]{x,y}; } }
w2 = (double)(i2-m2)*mf2; theta = atan2(w1,w2); c = (float)cos(theta-thetan); c = TWO_THIRDS*c*c; cfout[i2][ir] = c*cfin[i2][ir];
private void phase(int sign1, float[] f) { double fx = _sx1.getFirst(); if (fx==0.0) return; int nk = (_complex)?_nfft1:_nfft1/2+1; double dp = sign1*2.0*PI*_sk1.getDelta()*fx; for (int i=0,ir=0,ii=1; i<nk; ++i,ir+=2,ii+=2) { float p = (float)(i*dp); float cosp = cos(p); float sinp = sin(p); float fr = f[ir]; float fi = f[ii]; f[ir] = fr*cosp-fi*sinp; f[ii] = fi*cosp+fr*sinp; } } private void phase(float[][] f) {
zz*0.105787412e-6))); double am = ax-2.356194491; double y = sqrt(0.636619772/ax)*(cos(am)*t1-z*sin(am)*t2); return (x<0.0)?-y:y;
RandomTensors2(int n1, int n2) { super(n1,n2); Random r = new Random(); for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { float a = 2.0f*FLT_PI*r.nextFloat(); float u1 = cos(a); float u2 = sin(a); float du = 0.0001f+0.0009f*r.nextFloat(); float dv = 0.0001f+0.9999f*r.nextFloat(); setEigenvectorU(i1,i2,u1,u2); setEigenvalues(i1,i2,du,dv); } } } }
RandomTensors2(int n1, int n2) { super(n1,n2); Random r = new Random(); for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { float a = 2.0f*FLT_PI*r.nextFloat(); float u1 = cos(a); float u2 = sin(a); float du = 0.01f+0.09f*r.nextFloat(); float dv = 0.01f+0.99f*r.nextFloat(); setEigenvectorU(i1,i2,u1,u2); setEigenvalues(i1,i2,du,dv); } } } }
private void phase(int sign1, int sign2, float[][] f) { double fx1 = _sx1.getFirst(); double fx2 = _sx2.getFirst(); if (fx1==0.0 && fx2==0.0) return; int nk1 = (_complex)?_nfft1:_nfft1/2+1; int nk2 = _nfft2; double dp1 = sign1*2.0*PI*_sk1.getDelta()*fx1; double dp2 = sign2*2.0*PI*_sk2.getDelta()*fx2; for (int i2=0; i2<nk2; ++i2) { double p2 = i2*dp2; float[] f2 = f[i2]; for (int i1=0,ir=0,ii=1; i1<nk1; ++i1,ir+=2,ii+=2) { float p = (float)(i1*dp1+p2); float cosp = cos(p); float sinp = sin(p); float fr = f2[ir]; float fi = f2[ii]; f2[ir] = fr*cosp-fi*sinp; f2[ii] = fi*cosp+fr*sinp; } } } private void phase(float[][][] f) {
/** * Computes eigenvalues of a symmetric 3x3 matrix using Cardano's * analytical method. */ private static void getEigenvaluesSymmetric33(double[][] a, double[] d) { double a00 = a[0][0], a01 = a[0][1], a11 = a[1][1], a02 = a[0][2], a12 = a[1][2], a22 = a[2][2]; double de = a01*a12; double dd = a01*a01; double ee = a12*a12; double ff = a02*a02; double c2 = a00+a11+a22; double c1 = (a00*a11+a00*a22+a11*a22)-(dd+ee+ff); double c0 = a22*dd+a00*ee+a11*ff-a00*a11*a22-2.0*a02*de; double p = c2*c2-3.0*c1; double q = c2*(p-1.5*c1)-13.5*c0; // 13.5 = 27/2 double t = 27.0*(0.25*c1*c1*(p-c1)+c0*(q+6.75*c0)); // 6.75 = 27/4 double phi = ONE_THIRD*atan2(sqrt(abs(t)),q); double sqrtp = sqrt(abs(p)); double c = sqrtp*cos(phi); double s = ONE_OVER_SQRT3*sqrtp*sin(phi); double dt = ONE_THIRD*(c2-c); d[0] = dt+c; d[1] = dt+s; d[2] = dt-s; }
private void phase(int sign1, int sign2, int sign3, float[][][] f) { double fx1 = _sx1.getFirst(); double fx2 = _sx2.getFirst(); double fx3 = _sx3.getFirst(); if (fx1==0.0 && fx2==0.0 && fx3==0.0) return; int nk1 = (_complex)?_nfft1:_nfft1/2+1; int nk2 = _nfft2; int nk3 = _nfft3; double dp1 = sign1*2.0*PI*_sk1.getDelta()*fx1; double dp2 = sign2*2.0*PI*_sk2.getDelta()*fx2; double dp3 = sign3*2.0*PI*_sk3.getDelta()*fx3; for (int i3=0; i3<nk3; ++i3) { for (int i2=0; i2<nk2; ++i2) { double p23 = i2*dp2+i3*dp3; float[] f32 = f[i3][i2]; for (int i1=0,ir=0,ii=1; i1<nk1; ++i1,ir+=2,ii+=2) { float p = (float)(i1*dp1+p23); float cosp = cos(p); float sinp = sin(p); float fr = f32[ir]; float fi = f32[ii]; f32[ir] = fr*cosp-fi*sinp; f32[ii] = fi*cosp+fr*sinp; } } } } }
private static void plot3() { SimplePlot plot = new SimplePlot(); plot.addGrid("H-.V-."); float[] f = sin(rampfloat(0.0f,0.1f,63)); plot.addPoints(f).setStyle("r-o"); float[] g = cos(rampfloat(0.0f,0.1f,63)); plot.addPoints(g).setStyle("b-x"); plot.setTitle("A simple plot of two arrays"); plot.setVLabel("array value"); plot.setHLabel("array index"); } }
public void testCosine() { float w = 0.02f*2.0f*FLT_PI; int n1 = 1001; float shift = 10.0f; float sigma = 8.0f*shift; float[] f = cos(rampfloat(w*shift,w,n1)); float[] g = cos(rampfloat(0.0f,w,n1)); float[] u = new float[n1]; float[] c = new float[n1]; float[] d = new float[n1]; int min1 = -2*(int)shift; int max1 = 2*(int)shift; LocalShiftFinder lsf = new LocalShiftFinder(shift); lsf.find1(min1,max1,f,g,u,c,d); for (int i1=n1/4; i1<3*n1/4; ++i1) { assertEquals(shift,u[i1],0.02f); assertEquals(1.0f,c[i1],0.02f); assertEquals(1.0f,d[i1],0.02f); } /* edu.mines.jtk.mosaic.SimplePlot.asPoints(f); edu.mines.jtk.mosaic.SimplePlot.asPoints(g); edu.mines.jtk.mosaic.SimplePlot.asPoints(u); edu.mines.jtk.mosaic.SimplePlot.asPoints(c); edu.mines.jtk.mosaic.SimplePlot.asPoints(d); */ } }
public void test2() { double sigma = 8.0; int n1 = 1+4*(int)(3*sigma); int n2 = n1+2; LocalOrientFilter lof = new LocalOrientFilter(sigma); float pi = FLT_PI; float[] dips = {-0.49f*pi,-0.20f*pi,-0.01f,0.01f,0.20f*pi,0.49f*pi}; for (float dip:dips) { float k = 0.3f; float c = k*cos(dip); float s = k*sin(dip); float[][] x = sin(rampfloat(0.0f,c,s,n1,n2)); float[][] theta = new float[n2][n1]; float[][] u1 = new float[n2][n1]; float[][] u2 = new float[n2][n1]; float[][] v1 = new float[n2][n1]; float[][] v2 = new float[n2][n1]; float[][] eu = new float[n2][n1]; float[][] ev = new float[n2][n1]; float[][] el = new float[n2][n1]; lof.apply(x,theta,u1,u2,v1,v2,eu,ev,el); assertEqual(dip,theta,0.01); assertEqual(cos(dip),u1,0.01); assertEqual(sin(dip),u2,0.01); assertEqual(-sin(dip),v1,0.01); assertEqual(cos(dip),v2,0.01); assertEqual(1.0f,el,0.01); } }
float ku1 = k*cos(dip); float ku2 = k*sin(dip)*cos(azi); float ku3 = k*sin(dip)*sin(azi); float[][][] x = sin(rampfloat(0.0f,ku1,ku2,ku3,n1,n2,n3)); assertEqual(dip,theta,0.02); assertEqual(azi,phi,0.02); assertEqual(cos(dip),u1,0.02); assertEqual(sin(dip)*cos(azi),u2,0.02); assertEqual(sin(dip)*sin(azi),u3,0.02); assertEqual(1.0,ep,0.02);
public static void demo1() { int n1 = 1; int n2 = 111; int n3 = 111; EigenTensors3 et = new EigenTensors3(n1,n2,n3,false); float eu = 1.00f, ev = 1.00f, ew = 0.01f; float u1 = 1.00f, u2 = 0.00f, u3 = 0.00f; float w1 = 0.00f, w2 = 0.00f, w3 = 1.00f; int i1 = 0; for (int i3=0; i3<n3; ++i3) { float a = i3*FLT_PI/2.0f/(n3-1); w2 = sin(a); w3 = cos(a); for (int i2=0; i2<n2; ++i2) { et.setEigenvalues(i1,i2,i3,eu,ev,ew); et.setEigenvectorU(i1,i2,i3,u1,u2,u3); et.setEigenvectorW(i1,i2,i3,w1,w2,w3); } } TensorsPanel tp = new TensorsPanel(et); AxisAlignedQuad aaq = new AxisAlignedQuad(Axis.Z, new Point3( 0, 0,i1), new Point3(n3-1,n2-1,i1)); aaq.getFrame().addChild(tp); show(aaq); }
public static void demo2() { int n1 = 111; int n2 = 1; int n3 = 111; EigenTensors3 et = new EigenTensors3(n1,n2,n3,false); float eu = 0.01f, ev = 1.00f, ew = 1.00f; float u1 = 1.00f, u2 = 0.00f, u3 = 0.00f; float w1 = 0.00f, w2 = 1.00f, w3 = 0.00f; int i2 = 0; for (int i3=0; i3<n3; ++i3) { float a = i3*FLT_PI/2.0f/(n3-1); u1 = cos(a); u3 = sin(a); for (int i1=0; i1<n1; ++i1) { et.setEigenvalues(i1,i2,i3,eu,ev,ew); et.setEigenvectorU(i1,i2,i3,u1,u2,u3); et.setEigenvectorW(i1,i2,i3,w1,w2,w3); } } TensorsPanel tp = new TensorsPanel(et); AxisAlignedQuad aaq = new AxisAlignedQuad(Axis.Y, new Point3( 0,i2, 0), new Point3(n3-1,i2,n1-1)); aaq.getFrame().addChild(tp); show(aaq); }
public static void demo3() { int n1 = 111; int n2 = 111; int n3 = 1; EigenTensors3 et = new EigenTensors3(n1,n2,n3,false); float eu = 0.01f, ev = 1.00f, ew = 1.00f; float u1 = 1.00f, u2 = 0.00f, u3 = 0.00f; float w1 = 0.00f, w2 = 0.00f, w3 = 1.00f; int i3 = 0; for (int i2=0; i2<n2; ++i2) { float a = i2*FLT_PI/2.0f/(n2-1); u1 = cos(a); u2 = sin(a); for (int i1=0; i1<n1; ++i1) { et.setEigenvalues(i1,i2,i3,eu,ev,ew); et.setEigenvectorU(i1,i2,i3,u1,u2,u3); et.setEigenvectorW(i1,i2,i3,w1,w2,w3); } } TensorsPanel tp = new TensorsPanel(et); AxisAlignedQuad aaq = new AxisAlignedQuad(Axis.X, new Point3(i3, 0, 0), new Point3(i3,n2-1,n1-1)); aaq.getFrame().addChild(tp); show(aaq); }
float[][][] ra = rampfloat(0.0f,1.0f,1.0f,1.0f,n1,n2,n3); cx = polar(rr,ra); float[][][] rx = cos(ra); float[][][] ry = sin(ra); cy = cmplx(rx,ry);