Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  lattice
Language: JAVA
Code:

import  java.util.Date;
/**
 * @author mquiroga
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class Lattices {
 /**
  * @param args
  */
 public static void main(String[] args) {
        long lDateTime = new Date().getTime();
        int scope = 10;
        double d;
        double distMenor = Double.MAX_VALUE;
        int[] p0 = {4, -1, 3, 8};
        int[] p1 = {-2, 3, 4, 5};
        int[] p2 = {8, 3, 1, 2};
        int[] p3 = {-4, 4, 2, -2};
        int[] p4 = {3, -3, 4, 1};
        int[] p5 = {11, -5, 7, 0};
        int[] x = {98, 30, 21, -30};
        int[] kr=new int[6];
        
        for (int k0 = -scope; k0 < scope; k0=k0+1) {
            for (int k1 = -scope; k1 < scope; k1=k1+1) {
                for (int k2 = -scope; k2 < scope; k2=k2+1) {
                    for (int k3 = -scope; k3 < scope; k3=k3+1) {
                        for (int k4 = -scope; k4 < scope; k4=k4+1) {
                            for (int k5 = -scope; k5 < scope; k5=k5+1) {
                                double radicando = 
                                          Math.pow((x[0] - k0 * p0[0] - k1 * p1[0] - k2 * p2[0] - k3 * p3[0] - k4 * p4[0] - k5 * p5[0]),2)
                                        + Math.pow((x[1] - k0 * p0[1] - k1 * p1[1] - k2 * p2[1] - k3 * p3[1] - k4 * p4[1] - k5 * p5[1]),2)
                                        + Math.pow((x[2] - k0 * p0[2] - k1 * p1[2] - k2 * p2[2] - k3 * p3[2] - k4 * p4[2] - k5 * p5[2]),2)
                                        + Math.pow((x[3] - k0 * p0[3] - k1 * p1[3] - k2 * p2[3] - k3 * p3[3] - k4 * p4[3] - k5 * p5[3]),2);
                                d = Math.pow(radicando, (1.0 / 2.0));
                                if (d < distMenor) {
                                    distMenor=d;
                                    kr[0]=k0;
                                    kr[1]=k1;
                                    kr[2]=k2;
                                    kr[3]=k3;
                                    kr[4]=k4;
                                    kr[5]=k5;
                                    System.out.println("Got a better distance:" + distMenor);
                                } // end if
                            } // end for k5
                        } // end for k4
                    } // end for k3
                } // end for k2
            }// end for k1
        } // end for k0
        System.out.print("(k0,k1,k2,k3,k4,k5)=(");
        System.out.println(kr[0]+","+kr[1]+","+kr[2]+","+kr[3]+","+kr[4]+","+kr[5]+")");
        lDateTime = new Date().getTime() - lDateTime;
        System.out.println("Time= " + lDateTime/1000 + " seconds. Distance= " + distMenor);
 } // end method main
} // end class Lattices
Comments: