Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

In this page you can find the example usage for java.lang Math cos.

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

From source file:com.thalespf.dip.DeblurringTest.java

private static Complex[] motionBlur(double[] degradation, int width, int height) {
    Complex[] complex = new Complex[width * height];

    double[] temp = new double[2 * width * height];

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {

            double teta = Math.PI * ((x - width / 2) % width * A + (y - height / 2) % height * B);

            Sinc sinc = new Sinc();

            double real = Math.cos(teta) * sinc.value(teta) * T;
            double imaginary = Math.sin(teta) * sinc.value(teta) * T;

            Complex c = new Complex(real, imaginary);
            Complex cConj = c.conjugate();

            temp[2 * (x + y * width)] = cConj.getReal();
            temp[2 * (x + y * width) + 1] = cConj.getImaginary();
        }//from   ww  w .ja va2s . com
    }

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int xTranslated = (x + width / 2) % width;
            int yTranslated = (y + height / 2) % height;

            double real = temp[2 * (yTranslated * width + xTranslated)];
            double imaginary = temp[2 * (yTranslated * width + xTranslated) + 1];

            degradation[2 * (x + y * width)] = real;
            degradation[2 * (x + y * width) + 1] = imaginary;

            Complex c = new Complex(real, imaginary);
            complex[y * width + x] = c;
        }
    }

    return complex;
}

From source file:com.wattzap.model.GPXReader.java

/**
 * Calculate distance between two points in latitude and longitude taking
 * into account height difference. If you are not interested in height
 * difference pass 0.0. Uses Haversine method as its base.
 * /*from  w w w .  j a  v a2  s  .c  o  m*/
 * lat1, lon1 Start point lat2, lon2 End point el1 Start altitude in meters
 * el2 End altitude in meters
 * 
 * @returns Distance in Meters
 */
public static double distance(double lat1, double lat2, double lon1, double lon2, double el1, double el2) {

    final int R = 6371; // Radius of the earth

    Double latDistance = Math.toRadians(lat2 - lat1);
    Double lonDistance = Math.toRadians(lon2 - lon1);
    Double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
    Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double distance = R * c * 1000; // convert to meters

    double height = el1 - el2;

    distance = (distance * distance) + (height * height);

    return Math.sqrt(distance);
}

From source file:BackEnd.E_Spheres_calculation.java

public void priprava(int pocet_stupnov) throws DelaunayError {

    ArrayList<Double> U_real_list = new ArrayList<Double>();
    ArrayList<Double> U_image_list = new ArrayList<Double>();
    ArrayList<Integer> polohy_lan = new ArrayList<Integer>();

    //iteratory/*from w  w w. java  2 s.com*/
    int iterator_lan = 0;
    int elementarny_iterator = 0;
    //basic priprava vektorov 
    for (int cl1 = 0; cl1 < rozptie.getRetazovkaList().size(); cl1++) {

        //cyklus bundle   
        for (int cl2 = 0; cl2 < rozptie.getRetazovkaList().get(cl1).getBundle_over(); cl2++) {

            ArrayList<DPoint> R0_vectors_per_lano = new ArrayList<DPoint>(
                    rozptie.getRetazovka(cl1).getRo_vectors()); // nacitam jedno lano a upravim ho podla bundle konstant
            ArrayList<DPoint> R0_mirror_vectors_per_lano = new ArrayList<DPoint>(
                    rozptie.getRetazovka(cl1).getRo_mirror_vectors());
            polohy_lan.add(elementarny_iterator);
            // cyklus 
            for (int cl3 = 0; cl3 < rozptie.getRetazovka(cl1).getRo_vectors().size(); cl3++) {

                //  bundle korektura pre jeden druhy SMER  a korekcia
                double Y = (double) R0_vectors_per_lano.get(cl3).getY()
                        + (double) rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[1][cl2];
                double Z = (double) R0_vectors_per_lano.get(cl3).getZ()
                        + (double) Math.cos(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                double X = (double) R0_vectors_per_lano.get(cl3).getX()
                        + (double) Math.sin(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                DPoint R0 = new DPoint(X, Y, Z);

                //mirrorovanie len jedneho rozmeru pozor
                double Ym = (double) R0_mirror_vectors_per_lano.get(cl3).getY()
                        - (double) rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[1][cl2];
                double Zm = (double) R0_mirror_vectors_per_lano.get(cl3).getZ()
                        + (double) Math.cos(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                double Xm = (double) R0_mirror_vectors_per_lano.get(cl3).getX()
                        + (double) Math.sin(rozptie.getRetazovkaList().get(cl1).getBeta_over())
                                * rozptie.getRetazovkaList().get(cl1).getZY_cor_Bundle()[0][cl2];
                DPoint R0m = new DPoint(Xm, Ym, Zm);

                // nastavy U real a image do separatnych listov podla toho na akom vodi?i je ( tu sa bundle ignoruje )
                U_real_list.add(get_real(rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3));
                U_real_list.add(get_real(-rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3)); // add image voltage
                U_image_list.add(get_image(rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3));
                U_image_list.add(get_image(-rozptie.getRetazovkaList().get(cl1).getU_over(),
                        rozptie.getRetazovkaList().get(cl1).getPhi_over()) / Math.sqrt(3)); // add image voltage
                // nastavy polomery do jedej arraylistu
                this.polomery_lan.add(rozptie.getRetazovkaList().get(cl1).getR_over()); // realn
                this.polomery_lan.add(rozptie.getRetazovkaList().get(cl1).getR_over()); //image
                this.Ri.add(new DPoint(R0)); // add real
                this.Ri.add(new DPoint(R0m)); // add image to the total list

                //    elementarny_iterator = elementarny_iterator + 1;
            }

        }

    }

    //NULTY STUPEN Qi
    double pocitac = 0;
    for (int i = 0; i < Ri.size(); i++) {
        double qi_real = 4 * Math.PI * this.epsi0 * this.epsiR * polomery_lan.get(i) * U_real_list.get(i);
        double qi_image = 4 * Math.PI * this.epsi0 * this.epsiR * polomery_lan.get(i) * U_image_list.get(i);

        this.qi.add(new Complex(qi_real, qi_image));
        pocitac++;
    }
    System.out.println("pocet prvkov krok O =" + pocitac);
    pocitac = 0;

    //druhy stupen Qij
    for (int i = 0; i < Ri.size(); i++) {

        ArrayList<DPoint> R = new ArrayList<DPoint>();
        ArrayList<Complex> q = new ArrayList<Complex>();

        for (int j = 0; j < Ri.size(); j++) {

            if (i == j) {

            } else {

                double distance = get_distance(Ri.get(i), Ri.get(j));
                double distance2 = Math.pow(distance, 2);
                double Ai = polomery_lan.get(i);
                double Ai2 = Math.pow(Ai, 2);
                if (distance < rozptie.getRetazovka(0).getI_over()) {
                    double q_real = -(Ai / distance) * qi.get(j).getReal();
                    double q_image = -(Ai / distance) * qi.get(j).getImaginary();
                    double X = Ri.get(i).getX() - Ai2 * ((Ri.get(i).getX() - Ri.get(j).getX()) / distance2);
                    double Y = Ri.get(i).getY() - Ai2 * ((Ri.get(i).getY() - Ri.get(j).getY()) / distance2);
                    double Z = Ri.get(i).getZ() - Ai2 * ((Ri.get(i).getZ() - Ri.get(j).getZ()) / distance2);
                    DPoint Ri = new DPoint(X, Y, Z);

                    q.add(new Complex(q_real, q_image));
                    R.add(new DPoint(Ri));
                    pocitac++;

                }
            }

        }
        this.qij.add(new ArrayList<Complex>(q));
        this.Rij.add(new ArrayList<DPoint>(R));

    }
    System.out.println("pocet prvkov krok 1 =" + pocitac);
    pocitac = 0;

    //druhy stupen Qij
    for (int i = 0; i < Ri.size(); i++) {

        ArrayList<ArrayList<DPoint>> Rj = new ArrayList<ArrayList<DPoint>>();
        ArrayList<ArrayList<Complex>> qj = new ArrayList<ArrayList<Complex>>();

        for (int j = 0; j < Rij.size(); j++) {

            ArrayList<DPoint> R = new ArrayList<DPoint>();
            ArrayList<Complex> q = new ArrayList<Complex>();

            if (i == j) {

            } else {

                for (int k = 0; k < Rij.get(0).size(); k++) {
                    if (j == k) {

                    } else {
                        double distance = get_distance(Ri.get(i), Rij.get(j).get(k));
                        double distance2 = Math.pow(distance, 2);
                        double Ai = polomery_lan.get(i);
                        double Ai2 = Math.pow(Ai, 2);
                        if (distance < rozptie.getRetazovka(0).getI_over()) {
                            double q_real = -(Ai / distance) * qij.get(j).get(k).getReal();
                            double q_image = -(Ai / distance) * qij.get(j).get(k).getImaginary();

                            double X = Ri.get(i).getX()
                                    - Ai2 * ((Ri.get(i).getX() - Rij.get(j).get(k).getX()) / distance2);
                            double Y = Ri.get(i).getY()
                                    - Ai2 * ((Ri.get(i).getY() - Rij.get(j).get(k).getY()) / distance2);
                            double Z = Ri.get(i).getZ()
                                    - Ai2 * ((Ri.get(i).getZ() - Rij.get(j).get(k).getZ()) / distance2);
                            DPoint Ri = new DPoint(X, Y, Z);

                            q.add(new Complex(q_real, q_image));
                            R.add(new DPoint(Ri));
                            pocitac++;
                        }
                    }
                }
                qj.add(new ArrayList<Complex>(q));
                Rj.add(new ArrayList<DPoint>(R));
            }

        }
        this.qijk.add(new ArrayList<ArrayList<Complex>>(qj));
        this.Rijk.add(new ArrayList<ArrayList<DPoint>>(Rj));

    }
    System.out.println("pocet prvkov krok 2 =" + pocitac);
    pocitac = 0;

    //druhy stupen Qijkl
    for (int i = 0; i < Ri.size(); i++) {

        ArrayList<ArrayList<ArrayList<DPoint>>> Rjk = new ArrayList<ArrayList<ArrayList<DPoint>>>();
        ArrayList<ArrayList<ArrayList<Complex>>> qjk = new ArrayList<ArrayList<ArrayList<Complex>>>();

        for (int j = 0; j < Rijk.size(); j++) {

            ArrayList<ArrayList<DPoint>> Rj = new ArrayList<ArrayList<DPoint>>();
            ArrayList<ArrayList<Complex>> qj = new ArrayList<ArrayList<Complex>>();

            if (i == j) {

            } else {

                for (int k = 0; k < Rijk.get(0).size(); k++) {

                    ArrayList<DPoint> R = new ArrayList<DPoint>();
                    ArrayList<Complex> q = new ArrayList<Complex>();

                    if (j == k) {

                    } else {

                        for (int l = 0; l < Rijk.get(0).get(0).size(); l++) {
                            if (k == l) {

                            } else {
                                double distance = get_distance(Ri.get(i), Rijk.get(j).get(k).get(l));
                                double distance2 = Math.pow(distance, 2);
                                double Ai = polomery_lan.get(i);
                                double Ai2 = Math.pow(Ai, 2);
                                if (distance < rozptie.getRetazovka(0).getI_over()) {
                                    double q_real = -(Ai / distance) * qijk.get(j).get(k).get(l).getReal();
                                    double q_image = -(Ai / distance)
                                            * qijk.get(j).get(k).get(l).getImaginary();

                                    double X = Ri.get(i).getX()
                                            - Ai2 * ((Ri.get(i).getX() - Rijk.get(j).get(k).get(l).getX())
                                                    / distance2);
                                    double Y = Ri.get(i).getY()
                                            - Ai2 * ((Ri.get(i).getY() - Rijk.get(j).get(k).get(l).getY())
                                                    / distance2);
                                    double Z = Ri.get(i).getZ()
                                            - Ai2 * ((Ri.get(i).getZ() - Rijk.get(j).get(k).get(l).getZ())
                                                    / distance2);
                                    DPoint Ri = new DPoint(X, Y, Z);

                                    q.add(new Complex(q_real, q_image));
                                    R.add(new DPoint(Ri));
                                    pocitac++;
                                }
                            }
                        }
                        qj.add(new ArrayList<Complex>(q));
                        Rj.add(new ArrayList<DPoint>(R));
                    }

                }
            }

            qjk.add(new ArrayList<ArrayList<Complex>>(qj));
            Rjk.add(new ArrayList<ArrayList<DPoint>>(Rj));

        }
        this.qijkl.add(new ArrayList<ArrayList<ArrayList<Complex>>>(qjk));
        this.Rijkl.add(new ArrayList<ArrayList<ArrayList<DPoint>>>(Rjk));

    }
    System.out.println("pocet prvkov krok 3 =" + pocitac);
    pocitac = 0;

}

From source file:blue.soundObject.jmask.Table.java

double interpolateCosine(double r, double a, double b) {
    double erg, cx;

    cx = Math.cos(Math.PI * r + Math.PI) / 2.0 + 0.5;
    erg = a + cx * (b - a);/*  www  . j av a  2 s  .  c  o m*/
    return erg;
}

From source file:com.mousebird.maply.MaplyStarModel.java

public void addToViewc(GlobeController inViewC, MaplyBaseController.ThreadMode mode) {
    this.viewC = inViewC;
    this.addedMode = mode;

    //Julian date for position calculation
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    double jd = getJulianDateDouble(cal.getTimeInMillis());
    double siderealTime = Greenwich_Mean_Sidereal_Deg(jd);

    //Really simple shader
    Shader shader = new Shader("Star Shader", vertexShaderTriPoint,
            (image != null ? fragmentShaderTexTriPoint : fragmentShaderTriPoint), viewC);
    shader.setUniform("u_radius", 6.0);
    viewC.addShaderProgram(shader, "Star Shader");

    long shaderID = viewC.getScene().getProgramIDBySceneName("Star Shader");

    //Set up a simple particle system (that doesn't move)
    particleSystem = new ParticleSystem("Stars");
    particleSystem.setParticleSystemType(ParticleSystem.STATE.ParticleSystemPoint);
    particleSystem.setLifetime(1e20);//from  ww w  .j  a  va 2  s.  co m
    particleSystem.setTotalParticles(stars.size());
    particleSystem.setBatchSize(stars.size());
    particleSystem.setShaderID(shaderID);

    if (image != null) {
        particleSystem.addTexture(image);
    }

    particleSystem.addParticleSystemAttribute("a_position",
            ParticleSystemAttribute.MaplyShaderAttrType.MAPLY_SHADER_ATTR_TYPE_FLOAT3);
    particleSystem.addParticleSystemAttribute("a_size",
            ParticleSystemAttribute.MaplyShaderAttrType.MAPLY_SHADER_ATTR_TYPE_FLOAT);

    particleSystemObj = viewC.addParticleSystem(particleSystem, addedMode);

    //Data arrays for particles
    //We'll clear them out in case we don't fill them out completely
    float[] posData = new float[stars.size() * 3];
    float[] sizeData = new float[stars.size()];

    for (int i = 0; i < stars.size(); i++) {
        SingleStar singleStar = stars.get(i);

        //Convert the start from equatorial to useable lon/lat
        //Note: Should check this math
        double starLon = Math.toRadians(singleStar.ra - 15 * siderealTime);
        double starLat = Math.toRadians(singleStar.dec);

        double z = Math.sin(starLat);
        double rad = Math.sqrt(1.0 - z * z);
        Point3d pt = new Point3d(rad * Math.cos(starLon), rad * Math.sin(starLon), z);

        posData[i * 3] = (float) pt.getX();
        posData[i * 3 + 1] = (float) pt.getY();
        posData[i * 3 + 2] = (float) pt.getZ();
        float mag = (float) (6.0 - singleStar.mag);
        if (mag < 0.0)
            mag = (float) 0.0;
        sizeData[i] = mag;
    }

    //Set up the particle batch
    ParticleBatch batch = new ParticleBatch(particleSystem);
    batch.addAttribute("a_position", posData);
    batch.addAttribute("a_size", sizeData);
    viewC.addParticleBatch(batch, addedMode);

}

From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.GyroscopeOrientation.java

/**
 * Calculates a rotation vector from the gyroscope angular speed values.
 * //from w  w  w .  j  av  a  2s .c  o m
 * @param gyroValues
 * @param deltaRotationVector
 * @param timeFactor
 * @see http://developer.android
 *      .com/reference/android/hardware/SensorEvent.html#values
 */
private void getRotationVectorFromGyro() {
    // Calculate the angular speed of the sample
    float magnitude = (float) Math
            .sqrt(Math.pow(vGyroscope[0], 2) + Math.pow(vGyroscope[1], 2) + Math.pow(vGyroscope[2], 2));

    // Normalize the rotation vector if it's big enough to get the axis
    if (magnitude > EPSILON) {
        vGyroscope[0] /= magnitude;
        vGyroscope[1] /= magnitude;
        vGyroscope[2] /= magnitude;
    }

    // Integrate around this axis with the angular speed by the timestep
    // in order to get a delta rotation from this sample over the timestep
    // We will convert this axis-angle representation of the delta rotation
    // into a quaternion before turning it into the rotation matrix.
    float thetaOverTwo = magnitude * dT / 2.0f;
    float sinThetaOverTwo = (float) Math.sin(thetaOverTwo);
    float cosThetaOverTwo = (float) Math.cos(thetaOverTwo);

    deltaVGyroscope[0] = sinThetaOverTwo * vGyroscope[0];
    deltaVGyroscope[1] = sinThetaOverTwo * vGyroscope[1];
    deltaVGyroscope[2] = sinThetaOverTwo * vGyroscope[2];
    deltaVGyroscope[3] = cosThetaOverTwo;

    // Create a new quaternion object base on the latest rotation
    // measurements...
    qGyroscopeDelta = new Quaternion(deltaVGyroscope[3], Arrays.copyOfRange(deltaVGyroscope, 0, 3));

    // Since it is a unit quaternion, we can just multiply the old rotation
    // by the new rotation delta to integrate the rotation.
    qGyroscope = qGyroscope.multiply(qGyroscopeDelta);
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void cosDouble() {
    try {/*from  w  w w  .  j av  a 2s .  co  m*/
        Expression expression = getExpressionWithFunctionContext("cos(33.3)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.cos(33.3), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:jat.core.cm.TwoBodyAPL.java

public double ta_from_t(double t) {

    double M = meanAnomaly(t);
    double ea = solveKepler(M, this.e);

    double sinE = Math.sin(ea);
    double cosE = Math.cos(ea);
    double den = 1.0 - this.e * cosE;
    double sqrome2 = Math.sqrt(1.0 - this.e * this.e);
    double sinv = (sqrome2 * sinE) / den;
    double cosv = (cosE - this.e) / den;

    double ta = Math.atan2(sinv, cosv);
    if (this.ta < 0.0) {
        this.ta = this.ta + 2.0 * Constants.pi;
    }/*from  w  w  w . j  av a  2 s. co m*/

    return ta;
}

From source file:edu.umn.cs.spatialHadoop.nasa.SpatioAggregateQueries.java

/**
 * Performs a spatio-temporal aggregate query on an indexed directory
 * @param inFile/*from  w  w w  . j  av  a  2  s.c o m*/
 * @param params
 * @throws ParseException 
 * @throws IOException 
 * @throws InterruptedException 
 */
public static long selectionQuery(Path inFile, final ResultCollector<NASAPoint> output, OperationsParams params)
        throws ParseException, IOException, InterruptedException {
    // 1- Find matching temporal partitions
    final FileSystem fs = inFile.getFileSystem(params);
    Vector<Path> matchingPartitions = selectTemporalPartitions(inFile, params);

    // 2- Find the matching tile and the position in that tile
    final Point queryPoint = (Point) params.getShape("point");
    final double userQueryLon = queryPoint.x;
    final double userQueryLat = queryPoint.y;
    // Convert query point from lat/lng space to Sinusoidal space
    double cosPhiRad = Math.cos(queryPoint.y * Math.PI / 180);
    double projectedX = queryPoint.x * cosPhiRad;
    queryPoint.x = (projectedX + 180.0) / 10.0;
    queryPoint.y = (90.0 - queryPoint.y) / 10.0;
    final int h = (int) Math.floor(queryPoint.x);
    final int v = (int) Math.floor(queryPoint.y);
    final String tileID = String.format("h%02dv%02d", h, v);
    PathFilter rangeFilter = new PathFilter() {
        @Override
        public boolean accept(Path p) {
            return p.getName().indexOf(tileID) >= 0;
        }
    };

    final Vector<Path> allMatchingFiles = new Vector<Path>();

    for (Path matchingPartition : matchingPartitions) {
        // Select all matching files
        FileStatus[] matchingFiles = fs.listStatus(matchingPartition, rangeFilter);
        for (FileStatus matchingFile : matchingFiles) {
            allMatchingFiles.add(matchingFile.getPath());
        }
    }

    // All matching files are supposed to have the same resolution
    final int resolution = AggregateQuadTree.getResolution(fs, allMatchingFiles.get(0));

    final java.awt.Point queryInMatchingTile = new java.awt.Point();
    queryInMatchingTile.x = (int) Math.floor((queryPoint.x - h) * resolution);
    queryInMatchingTile.y = (int) Math.floor((queryPoint.y - v) * resolution);

    // 3- Query all matching files in parallel
    List<Long> threadsResults = Parallel.forEach(allMatchingFiles.size(), new RunnableRange<Long>() {
        @Override
        public Long run(int i1, int i2) {
            ResultCollector<AggregateQuadTree.PointValue> internalOutput = output == null ? null
                    : new ResultCollector<AggregateQuadTree.PointValue>() {
                        NASAPoint middleValue = new NASAPoint(userQueryLon, userQueryLat, 0, 0);

                        @Override
                        public void collect(AggregateQuadTree.PointValue value) {
                            middleValue.value = value.value;
                            middleValue.timestamp = value.timestamp;
                            output.collect(middleValue);
                        }
                    };

            long numOfResults = 0;
            for (int i_file = i1; i_file < i2; i_file++) {
                try {
                    Path matchingFile = allMatchingFiles.get(i_file);
                    java.awt.Rectangle query = new java.awt.Rectangle(queryInMatchingTile.x,
                            queryInMatchingTile.y, 1, 1);
                    AggregateQuadTree.selectionQuery(fs, matchingFile, query, internalOutput);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return numOfResults;
        }
    });
    long totalResults = 0;
    for (long result : threadsResults) {
        totalResults += result;
    }
    return totalResults;
}

From source file:es.udc.gii.common.eaf.benchmark.real_param.cec2005.CEC2005ObjectiveFunction.java

public double griewank(double[] x) {
    double sum = 0.0d;
    double prod = 1.0d;

    for (int i = 0; i < x.length; i++) {
        sum += x[i] * x[i];//from  ww  w.  j a  va 2 s.  com
        prod *= Math.cos(x[i] / Math.sqrt(i + 1.0));
    }
    return 1.0 + sum / 4000 - prod;
}