/* * Matrix33.java * */ package mathematics; public class Matrix33 { private double[][] matrix33 = new double[3][3]; public double[][] A = new double[3][3]; // si aucun argument entré, matrix33 initialisé comme matrice identité public Matrix33() { for (int i=0;i<3;i++){ for (int j=0;j<3;j++) { if (i==j) matrix33[j]=1; else matrix33[j]=0; } } } public double getValue(int posline, int posrow) { return matrix33[posline][posrow]; } public void setValue(int posline, int posrow, double value) { if((posline<0) || (posline>3)) { throw new IllegalArgumentException("Matrix33 index out of Bound"); } else { matrix33[posline][posrow]=value; } } public String toString() { return String.format("\n\t"+getValue(0,0)+"\t"+getValue(0,1)+"\t"+getValue(0,2)+ "\n\t"+getValue(1,0)+"\t"+getValue(1,1)+"\t"+getValue(1,2)+ "\n\t"+getValue(2,0)+"\t"+getValue(2,1)+"\t"+getValue(2,2)); } public double[][] getArray() { return matrix33; } /** Produit Matriciel : * A.ProduitMatriciel(B) = A*B * @param A matrix33 multiplicateur, second terme de la multiplication * @return matrix33 resultat de la multiplication */ public Matrix33 ProduitMatriciel(Matrix33 A) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); double[] A_colonne_j = new double[3]; double result = 0; // variable interne pour le calcul for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { A_colonne_j[j] = A.matrix33[j][i]; } for (int k=0;k<3;k++) { double[] mat33_line_k = matrix33[k]; result=0; for (int l=0;l<3;l++) { result = result+mat33_line_k[l]*A_colonne_j[l]; } C[k][i]=result; } } return mat; } public Matrix33 times(double s) { Matrix33 mat = new Matrix33(); double[][] M = mat.getArray(); double result = 0; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { M[i][j]=s*matrix33[i][j]; // mat.setValue(i,j,A.getValue(i,j)*s); } } return mat; } public Matrix33 setColumn(int c, VectorN vect) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); if ((c<0)||(c>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else if (vect.getLength()>3) { throw new IllegalArgumentException("Vector tow long"); } else { for(int i=0;i<3;i++) { for (int j=0;j<3;j++) { if (j!=c) { C[i][j] = matrix33[i][j]; } else if (j==c) { C[i][c]=vect.x[i]; } } } } return mat; } /** Change la ligne line de la matrice par le vecteur * @param line numéro de la ligne à changer * @param vect vecteur à mettre dans la matrice */ public Matrix33 setLine(int line, VectorN vect) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); if ((line<0)||(line>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else if (vect.getLength()>3) { throw new IllegalArgumentException("Vector tow long"); } else { for (int j=0;j<3;j++) { for(int i=0;i<3;i++) { if (i!=line) { C[i][j] = matrix33[i][j]; } else if (i==line) { C[i][j]=vect.x[j]; } } } } return mat; } /** Extrait la ligne d'une matrice * @param line numéro de la ligne * @return vecteur Vecteur extrait */ public VectorN getLine(int line) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { C[i][j]=matrix33[i][j]; } } VectorN result = new VectorN(3); if ((line<0)||(line>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else { for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { result.setValue(j,C[line][j]); } } } return result; } /** Extrait une colonne d'une matrice * @param col numéro de la colonne * @return vecteur Vecteur extrait */ public VectorN getColumn(int col) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { C[i][j]=matrix33[i][j]; } } VectorN result = new VectorN(3); if ((col<0)||(col>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else { for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { result.setValue(j,C[j][col]); } } } return result; } } // end of Matrix33 class <table border=0 cellspacing=0 cellpadding=4 bgcolor=#E0E0E0><tr><td class=code> D'un autre coté, nous avons la classe DCM, provenant du package [i] attitudeToolKit , qui étends la classe Matrix33 puisque les DCM doivet avoir les mémes fonctionnalités qu'une matrice 3* 3 mais ils doivent aussi avoir d'autres méthodes non détaillées ici? : <table border =0 cellspacing= 0 cellpadding=4 bgcolor=#E0E0E0><tr><td class=code> /* * DCM.java * */ package attitudeToolKit; import mathematics.*; public class DCM implements AttitudeToolKit { // création de la matrice DCM private Matrix33 DCM = new Matrix33(); /** Creates a new instance of DCM */ // si aucun paramètre n'est entré, on initialise tout à zéro. public DCM() { this.DCM = DCM; } public DCM(final double DCM_0_0, final double DCM_0_1, final double DCM_0_2, final double DCM_1_0, final double DCM_1_1, final double DCM_1_2, final double DCM_2_0, final double DCM_2_1, final double DCM_2_2) { this.DCM.setValue(0,0,DCM_0_0); this.DCM.setValue(0,1,DCM_0_1);this.DCM.setValue(0,2,DCM_0_2); this.DCM.setValue(1,0,DCM_1_0); this.DCM.setValue(1,1,DCM_1_1);this.DCM.setValue(1,2,DCM_1_2); this.DCM.setValue(2,0,DCM_2_0); this.DCM.setValue(2,1,DCM_2_1);this.DCM.setValue(2,2,DCM_2_2); } public String toString() { // return String.format("\t"+DCM.getValue(0,0)+"\t"+DCM.getValue(0,1)+"\t"+DCM.getValue(0,2)); return this.DCM.toString(); } } // end of DCM class
/* * test_attitude.java * */ package attitudeToolKit; import mathematics.*; public class test_attitudeToolKit { /** Creates a new instance of test_attitude */ public test_attitudeToolKit() { } /** * @param args the command line arguments */ public static void main(String[] args) { // cration d'un DCM DCM zz = new DCM(1,2,3,4,5,6,7,8,9); // affichage du DCM créé System.out.println("DCM= "+zz); // récupération de la valeur située ligne 1 colonne 2 System.out.println(zz.getValue(0,1)); // affichage ligne 1 System.out.println("ligne 1= "+zz.getLine(0)); // multiplication par 2 System.out.println("times 2= "+zz.times(2)); System.out.println("times 2= "+zz.times(zz,2)); } }
/* * Matrix33.java * */ package mathematics; public class Matrix33 { private double[][] matrix33 = new double[3][3]; public double[][] A = new double[3][3]; // si aucun argument entré, matrix33 initialisé comme matrice identité public Matrix33() { for (int i=0;i<3;i++){ for (int j=0;j<3;j++) { if (i==j) matrix33[j]=1; else matrix33[j]=0; } } } public double getValue(int posline, int posrow) { return matrix33[posline][posrow]; } public void setValue(int posline, int posrow, double value) { if((posline<0) || (posline>3)) { throw new IllegalArgumentException("Matrix33 index out of Bound"); } else { matrix33[posline][posrow]=value; } } public String toString() { return String.format("\n\t"+getValue(0,0)+"\t"+getValue(0,1)+"\t"+getValue(0,2)+ "\n\t"+getValue(1,0)+"\t"+getValue(1,1)+"\t"+getValue(1,2)+ "\n\t"+getValue(2,0)+"\t"+getValue(2,1)+"\t"+getValue(2,2)); } public double[][] getArray() { return matrix33; } /** Produit Matriciel : * A.ProduitMatriciel(B) = A*B * @param A matrix33 multiplicateur, second terme de la multiplication * @return matrix33 resultat de la multiplication */ public Matrix33 ProduitMatriciel(Matrix33 A) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); double[] A_colonne_j = new double[3]; double result = 0; // variable interne pour le calcul for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { A_colonne_j[j] = A.matrix33[j][i]; } for (int k=0;k<3;k++) { double[] mat33_line_k = matrix33[k]; result=0; for (int l=0;l<3;l++) { result = result+mat33_line_k[l]*A_colonne_j[l]; } C[k][i]=result; } } return mat; } public Matrix33 times(double s) { Matrix33 mat = new Matrix33(); double[][] M = mat.getArray(); double result = 0; for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { M[i][j]=s*matrix33[i][j]; // mat.setValue(i,j,A.getValue(i,j)*s); } } return mat; } public Matrix33 setColumn(int c, VectorN vect) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); if ((c<0)||(c>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else if (vect.getLength()>3) { throw new IllegalArgumentException("Vector tow long"); } else { for(int i=0;i<3;i++) { for (int j=0;j<3;j++) { if (j!=c) { C[i][j] = matrix33[i][j]; } else if (j==c) { C[i][c]=vect.x[i]; } } } } return mat; } /** Change la ligne line de la matrice par le vecteur * @param line numéro de la ligne à changer * @param vect vecteur à mettre dans la matrice */ public Matrix33 setLine(int line, VectorN vect) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); if ((line<0)||(line>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else if (vect.getLength()>3) { throw new IllegalArgumentException("Vector tow long"); } else { for (int j=0;j<3;j++) { for(int i=0;i<3;i++) { if (i!=line) { C[i][j] = matrix33[i][j]; } else if (i==line) { C[i][j]=vect.x[j]; } } } } return mat; } /** Extrait la ligne d'une matrice * @param line numéro de la ligne * @return vecteur Vecteur extrait */ public VectorN getLine(int line) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { C[i][j]=matrix33[i][j]; } } VectorN result = new VectorN(3); if ((line<0)||(line>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else { for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { result.setValue(j,C[line][j]); } } } return result; } /** Extrait une colonne d'une matrice * @param col numéro de la colonne * @return vecteur Vecteur extrait */ public VectorN getColumn(int col) { Matrix33 mat = new Matrix33(); double[][] C = mat.getArray(); for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { C[i][j]=matrix33[i][j]; } } VectorN result = new VectorN(3); if ((col<0)||(col>3)) { throw new IllegalArgumentException("Column out of Bound !"); } else { for (int i=0;i<3;i++) { for (int j=0;j<3;j++) { result.setValue(j,C[j][col]); } } } return result; } } // end of Matrix33 class
/* * DCM.java * */ package attitudeToolKit; import mathematics.*; public class DCM implements AttitudeToolKit { // création de la matrice DCM private Matrix33 DCM = new Matrix33(); /** Creates a new instance of DCM */ // si aucun paramètre n'est entré, on initialise tout à zéro. public DCM() { this.DCM = DCM; } public DCM(final double DCM_0_0, final double DCM_0_1, final double DCM_0_2, final double DCM_1_0, final double DCM_1_1, final double DCM_1_2, final double DCM_2_0, final double DCM_2_1, final double DCM_2_2) { this.DCM.setValue(0,0,DCM_0_0); this.DCM.setValue(0,1,DCM_0_1);this.DCM.setValue(0,2,DCM_0_2); this.DCM.setValue(1,0,DCM_1_0); this.DCM.setValue(1,1,DCM_1_1);this.DCM.setValue(1,2,DCM_1_2); this.DCM.setValue(2,0,DCM_2_0); this.DCM.setValue(2,1,DCM_2_1);this.DCM.setValue(2,2,DCM_2_2); } public String toString() { // return String.format("\t"+DCM.getValue(0,0)+"\t"+DCM.getValue(0,1)+"\t"+DCM.getValue(0,2)); return this.DCM.toString(); } } // end of DCM class
/* * test_attitude.java * */ package attitudeToolKit; import mathematics.*; public class test_attitudeToolKit { /** Creates a new instance of test_attitude */ public test_attitudeToolKit() { } /** * @param args the command line arguments */ public static void main(String[] args) { // cration d'un DCM DCM zz = new DCM(1,2,3,4,5,6,7,8,9); // affichage du DCM créé System.out.println("DCM= "+zz); // récupération de la valeur située ligne 1 colonne 2 System.out.println(zz.getValue(0,1)); // affichage ligne 1 System.out.println("ligne 1= "+zz.getLine(0)); // multiplication par 2 System.out.println("times 2= "+zz.times(2)); System.out.println("times 2= "+zz.times(zz,2)); } }