Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.57 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package modela;
  7.  
  8. import java.util.Vector;
  9.  
  10. /**
  11.  *
  12.  * @author HP
  13.  */
  14. public class ModelA {
  15.  
  16.     /**
  17.      * @param args the command line arguments
  18.      */
  19.     public static final Double[] z0 = {
  20.                            -1.0,-1.0,-1.0,-1.0,-1.0,
  21.                            -1.0, 1.0, 1.0, 1.0,-1.0,
  22.                            -1.0, 1.0,-1.0, 1.0,-1.0,
  23.                            -1.0, 1.0, 1.0, 1.0,-1.0,
  24.                            -1.0,-1.0,-1.0,-1.0,-1.0 //z1
  25.      };
  26.     public static final Double[] z1 = {
  27.                            -1.0,-1.0,-1.0,-1.0,-1.0,
  28.                            -1.0, 1.0, 1.0,-1.0,-1.0,
  29.                            -1.0,-1.0, 1.0,-1.0,-1.0,
  30.                            -1.0,-1.0, 1.0,-1.0,-1.0,
  31.                            -1.0,-1.0,-1.0,-1.0,-1.0  
  32.     };
  33.      public static final Double[] zprim0 = {
  34.                           -1.0, 1.0, 1.0, 1.0,-1.0,
  35.                            -1.0, 1.0,-1.0, 1.0,-1.0,
  36.                            -1.0, 1.0,-1.0, 1.0,-1.0,
  37.                            -1.0, 1.0, 1.0, 1.0,-1.0,
  38.                            -1.0,-1.0,-1.0,-1.0,-1.0 //z1
  39.                          
  40.     };
  41.      public static final Double[] zprim1 = {
  42.                            -1.0,-1.0, 1.0,-1.0,-1.0,
  43.                            -1.0,-1.0, 1.0,-1.0,-1.0,
  44.                            -1.0,-1.0, 1.0,-1.0,-1.0,
  45.                            -1.0,-1.0, 1.0,-1.0,-1.0,
  46.                            -1.0,-1.0, 1.0,-1.0,-1.0
  47. };
  48.    
  49.      static public Vector<Double> fill(Double[] a)
  50.     {
  51.         Vector<Double> wektor = new Vector<Double>();
  52.         for(int i = 0;i<25;i++)
  53.         {
  54.             wektor.add(a[i]);
  55.         }
  56.         return wektor;
  57.     }
  58.       static public Vector<Vector<Double>> fillW( Vector<Double> z0, Vector<Double> z1)
  59.     {
  60.         Vector<Vector<Double>> wVector = new Vector<Vector<Double>>();
  61.         Vector<Double> w = new Vector<Double>();
  62.         Vector<Double> temp = new Vector<Double>();
  63.        
  64.         for(int i = 0; i<25;i++)
  65.            {
  66.                
  67.                for(int j=0;j<25;j++)
  68.                {
  69.                    
  70.                    w.add(1.0/25.0 * (z0.get(i)*z0.get(j) + z1.get(i)*z1.get(j)));
  71.                    
  72.                }
  73.                wVector.add(w);
  74.                w = new Vector<Double>();
  75.            }
  76.         return wVector;
  77.     }
  78.       static public Vector<Double> F(Vector<Vector<Double>> w,Vector<Double> z)
  79.     {
  80.         Vector<Double> u = new Vector<Double>();
  81.         double value ;
  82.         //System.out.println(z);
  83.         for(int i =0; i<25;i++)
  84.         {
  85.             value = 0.0;
  86.             for(int j = 0;j<25;j++)
  87.             {
  88.                
  89.                 value+=w.get(i).get(j) * z.get(j);
  90.                
  91.             }
  92.             u.add(value);
  93.            
  94.         }
  95.        
  96.         u = sgn(u);
  97.         return u;
  98.     }
  99.      static final Vector<Double> sgn (Vector<Double> u)
  100.     {
  101.         for (int i=0; i<25; i++) {
  102.         if(u.get(i) >= 0.0) {
  103.             u.set(i, 1.0);
  104.         } else {
  105.             u.set(i, -1.0);
  106.         }
  107.  
  108.     }
  109.     return u;
  110.     }
  111.      
  112.     public static void interfejs(Vector<Double> u)
  113.     {
  114.       for (int i=0; i<25; i++) {
  115.         if (u.get(i) == -1.0) {
  116.             System.out.print("   ");
  117.         } else {
  118.             System.out.print(" * ");
  119.         }
  120.  
  121.         if (i%5 == 4) {
  122.            System.out.println("\n");
  123.         }
  124.       }
  125.     }
  126.      
  127.     public static void main(String[] args) {
  128.         // TODO code application logic here
  129.         Vector<Double> VecZ0, VecZ1, VecZ0prim, VecZ1prim, result;
  130.         Vector<Vector<Double>> Vec, Vecprim = new Vector<Vector<Double>>();
  131.         VecZ0 = fill(z0);
  132.         VecZ1 = fill(z1);
  133.         Vec = fillW(VecZ0,VecZ1);
  134.         //System.out.println(VecZ0 + "\n" + VecZ1 + "\n"  );
  135.         System.out.println("Dla z0");
  136.         result = F(Vec, VecZ0);
  137.         interfejs(result);
  138.        // System.out.println("\n");
  139.        System.out.println("Dla z1");
  140.         result = F(Vec, VecZ1);
  141.         interfejs(result);
  142.         System.out.println("Dla wartości zaburzonych");
  143.         VecZ0prim = fill(zprim0);
  144.         VecZ1prim = fill(zprim1);
  145.        
  146.          Vecprim = fillW(VecZ0prim,VecZ1prim);
  147.        
  148.         result = F(Vecprim, VecZ0prim);
  149.         interfejs(result);
  150.        
  151.         result = F(Vecprim, VecZ1prim);
  152.         interfejs(result);
  153.        
  154.     }
  155.    
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement