Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author jfern096
- */
- import java.lang.Math;
- public class mine {
- double a [][];
- String alphabet = "ABCDEFGHIJKLMNOPQRSTU";
- double dis = 0;
- double minor = 0;
- int size ;
- public mine(int x,int y)
- {
- a = new double[x][y];
- a[0][0] = 1 ;
- a[0][1] = -3;
- a[0][2] = 2;
- a[0][3] = 4;
- a[1][0] = -2 ;
- a[1][1] = 2;
- a[1][2] = -1;
- a[1][3] = 1;
- a[2][0] = 3 ;
- a[2][1] = -3;
- a[2][2] = -2;
- a[2][3] = 2;
- a[3][0] = 2 ;
- a[3][1] = 5;
- a[3][2] = -3;
- a[3][3] = -4;
- }
- /** {{ 1, -3, 2},
- {-2, 2, -1 },
- { 3, -3, -2 },
- }; */
- public double calcD(mine b)
- {
- for(int j =0; j<b.a.length; j++ )
- {
- // make array smaller
- double temp[][] = new double[b.a.length-1][b.a.length-1];
- for(int i = 0; i < b.a.length-1; i++) //rows
- {
- boolean over = false;
- for(int k = 0; k < b.a.length-1; k++) // columns
- {
- if(k==j)
- {
- temp[i][k] = b.a[i+1][k+1]; // columns match, we must skip an element
- over = true;
- continue;
- }
- if(over)
- {
- temp[i][k] = b.a[i+1][k+1]; // element already skip, we continue with +1
- }
- else
- temp[i][k] = b.a[i+1][k];
- }
- }
- dis = dis + (Math.pow(-1, j+2)) * b.a[0][j] * cMinor(temp) ; /// minor missing
- }
- return dis;
- }
- public double cMinor(double b[][])
- {
- double firstM = b[0][0];
- double temp[][] = new double[b.length-1][b.length-1];
- minor = 0;
- if(b.length ==2)
- {
- minor = minor + ((b[0][0] * b[1][1]) -
- (b[0][1] * b[1][0]));
- return minor;
- }
- for(int j =0; j<b.length; j++ )
- {
- // make array smaller
- for(int i = 0; i < b.length-1; i++) //rows
- {
- boolean over = false;
- for(int k = 0; k < b.length-1; k++) // columns
- {
- if(k==j)
- {
- temp[i][k] = b[i+1][k+1]; // columns match, we must skip an element
- over = true;
- continue;
- }
- if(over)
- {
- temp[i][k] = b[i+1][k+1]; // element already skip, we continue with +1
- }
- else
- temp[i][k] = b[i+1][k];
- }
- }
- minor = minor + (Math.pow(-1, j+2)) * firstM * cMinor(temp);
- }
- return minor;
- }
- }
- //a1(b2c3-c2b3) - b1(a2c3-c2a3) + c1(a2b3-b2a3)
Add Comment
Please, Sign In to add comment