• # Réponse

    Posté par . En réponse au message Programme Déterminant matrice carrée. Évalué à -1.

    En principe, il faut trouver par soi-même mais bon :

    public class TestDet3 {
    	public static void main(String[] args) {
    		Mat matricetest = remplirmatrice();
    		afficherMatrice(matricetest);
    		
    		System.out.println("Le determinant est : "+determinant(matricetest));
    		afficherMatrice(matricetest);
    	}
    	public static int determinant(Mat matrice)
    	{
    		int determinant=0;
    		
    		if(matrice.col==1)
    			return matrice.T[0][0];
    		
    		for (int col = 0; col < matrice.col; col++) 
    		{
    			Mat sousMat=getSousMatrice(matrice,col,0);
    			int detSousMatrice=determinant(sousMat);
    			if(col%2==0)
    				determinant+=matrice.T[col][0]*detSousMatrice;
    			else
    				determinant-=matrice.T[col][0]*detSousMatrice;
    		}
    		return determinant;
    	}
    	private static Mat getSousMatrice(Mat matrice,int colToSupp,int rowToSupp)
    	{
    		Mat retour = new Mat();
    		retour.col=matrice.col-1;
    		retour.row=matrice.row-1;
    		retour.T=new int[retour.row][retour.col];
    		
    		for(int i=0;i<matrice.col;i++)
    			for(int j=0;j<matrice.row;j++)
    			{
    				if(j<rowToSupp && i<colToSupp)
    					retour.T[i][j]=matrice.T[i][j];
    				else if(j<rowToSupp && i>colToSupp)
    					retour.T[i-1][j]=matrice.T[i][j];
    				else if(j>rowToSupp && i>colToSupp)
    					retour.T[i-1][j-1]=matrice.T[i][j];
    				else if(j>rowToSupp && i<colToSupp)
    					retour.T[i][j-1]=matrice.T[i][j];
    			}
    		return retour;
    	}
    	
    	public static Mat remplirmatrice()
    	{
    		Mat retour=new Mat();
    		int [][] T={{-2,2,-3},{-1,1,3},{2,0,-1}};
    		//int [][] T={{-2,2,-3},{0,1,3},{0,0,-1}};
    		retour.T=T;
    		retour.col=3;
    		retour.row=3;
    		
    		return retour;
    	}
    	public static void afficherMatrice(Mat add) {
    		for (int row = 0; row < add.row; row++)
    		{
    			for (int col = 0; col < add.col; col++) 
    				System.out.print(" " +add.T[row][col]);
    			System.out.println();
    		}
    		System.out.println();
    	}
    }
    
    

    Ça ne doit fonctionner que pour les matrices carrées. Je te laisse faire les autres. Attention à la syntaxe, nom d'une classe commençant par une majuscule...

    En contrepartie, tu participeras au libre. Je suggère une dépêche linuxfr ou une page wikipedia de ton choix.