Guest User

Untitled

a guest
Jan 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.17 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. /**
  7.  *
  8.  * @author jfern096
  9.  */
  10.  
  11.  
  12. import java.lang.Math;
  13. public class mine {
  14.  
  15.  
  16.    double a [][];
  17.     String alphabet = "ABCDEFGHIJKLMNOPQRSTU";
  18.     double dis = 0;
  19.    double minor = 0;
  20.     int size ;
  21.  
  22.  
  23.  
  24.     public mine(int x,int y)
  25.     {
  26.        a = new double[x][y];
  27.         a[0][0] = 1 ;
  28.         a[0][1] = -3;
  29.         a[0][2] = 2;
  30.         a[0][3] = 4;
  31.  
  32.          a[1][0] = -2 ;
  33.         a[1][1] = 2;
  34.         a[1][2] = -1;
  35.          a[1][3] = 1;
  36.  
  37.         a[2][0] = 3 ;
  38.         a[2][1] = -3;
  39.         a[2][2] = -2;
  40.         a[2][3] = 2;
  41.  
  42.         a[3][0] = 2 ;
  43.         a[3][1] = 5;
  44.         a[3][2] = -3;
  45.         a[3][3] = -4;
  46.     }
  47.  
  48. /**                {{ 1, -3,  2},
  49.                    {-2,  2, -1 },
  50.                    { 3, -3, -2 },
  51.                    }; */
  52.  
  53.     public double calcD(mine b)
  54.     {
  55.  
  56.  
  57.         for(int j =0; j<b.a.length; j++ )
  58.         {
  59.             // make array smaller
  60.            double temp[][] = new double[b.a.length-1][b.a.length-1];
  61.  
  62.             for(int i = 0; i < b.a.length-1; i++)  //rows
  63.  
  64.             {
  65.                  boolean over = false;
  66.  
  67.                  for(int k = 0; k < b.a.length-1; k++)  // columns
  68.             {
  69.                  if(k==j)
  70.                  {
  71.                     temp[i][k] = b.a[i+1][k+1];   // columns match, we must skip an element
  72.  
  73.  
  74.  
  75.                     over = true;
  76.  
  77.                     continue;
  78.                  }
  79.  
  80.                  if(over)
  81.                  {
  82.                      temp[i][k] = b.a[i+1][k+1]; // element already skip, we continue with +1
  83.                  }
  84.  
  85.             else
  86.                 temp[i][k] = b.a[i+1][k];
  87.             }
  88.             }
  89.  
  90.  
  91.  
  92.  
  93.          dis = dis + (Math.pow(-1, j+2)) * b.a[0][j] * cMinor(temp)  ;   /// minor missing
  94.  
  95.  
  96.         }
  97.  
  98.         return dis;
  99.     }
  100.  
  101.  
  102.  
  103.     public double cMinor(double b[][])
  104.     {
  105.          double firstM  = b[0][0];
  106.          double temp[][] = new double[b.length-1][b.length-1];
  107.          minor = 0;
  108.  
  109.  
  110.  
  111.  
  112.        if(b.length ==2)
  113.        {
  114.            minor = minor + ((b[0][0] *  b[1][1]) -
  115.                    (b[0][1] *  b[1][0]));
  116.  
  117.            return minor;
  118.        }
  119.  
  120.  for(int j =0; j<b.length; j++ )
  121.         {
  122.             // make array smaller
  123.  
  124.  
  125.             for(int i = 0; i < b.length-1; i++)  //rows
  126.  
  127.             {
  128.                  boolean over = false;
  129.  
  130.                  for(int k = 0; k < b.length-1; k++)  // columns
  131.             {
  132.  
  133.                      if(k==j)
  134.                  {
  135.                     temp[i][k] = b[i+1][k+1];   // columns match, we must skip an element
  136.  
  137.  
  138.  
  139.                     over = true;
  140.  
  141.                     continue;
  142.                  }
  143.  
  144.                  if(over)
  145.                  {
  146.                      temp[i][k] = b[i+1][k+1]; // element already skip, we continue with +1
  147.                  }
  148.  
  149.             else
  150.                 temp[i][k] = b[i+1][k];
  151.             }
  152.             }
  153.  
  154.  
  155.            minor = minor +  (Math.pow(-1, j+2)) * firstM * cMinor(temp);
  156.  
  157.  
  158.  
  159.     }
  160.            return minor;
  161. }
  162. }
  163. //a1(b2c3-c2b3) - b1(a2c3-c2a3) + c1(a2b3-b2a3)
Add Comment
Please, Sign In to add comment