progueur
Messages postés7Date d'inscriptiondimanche 2 mars 2003StatutMembreDernière intervention18 avril 2003
-
18 avril 2003 à 19:48
CoreBreaker
Messages postés540Date d'inscriptiondimanche 23 mars 2003StatutMembreDernière intervention 5 octobre 2007
-
20 avril 2003 à 05:13
Bonjour,
Pour répondre à corebreaker, j'aurais besoin d'une classe Matrice dont les éléments sont reels.
Il me faudrait le calcul du determinant, de la matrice inverse en priorite.
Si possible décomposition LU, QR, calcul des valeurs propres.
CoreBreaker
Messages postés540Date d'inscriptiondimanche 23 mars 2003StatutMembreDernière intervention 5 octobre 20071 20 avril 2003 à 05:13
class MatriceError extends Error
{
final static int MATRICE_DIMX_GET= 1;
final static int MATRICE_DIMY_GET= 2;
final static int MATRICE_DIMX_SET= 3;
final static int MATRICE_DIMY_SET= 4;
final static int MATRICE_VIDE= 5;
final static int MATRICE_PAS_INV= 6;
String mMessage= "Type d'exception inconnu";
MatriceError(int aType)
{
this(aType, null);
}
MatriceError(int aType, int[] aParams)
{
switch(aType)
{
case MATRICE_DIMX_GET:
mMessage= "" + aParams[0];
mMessage+= " est un index de colonne invalide";
mMessage+= " pour avoir une valeur";
mMessage+= " (dimension= " + aParams[1] + ")";
break;
case MATRICE_DIMY_GET:
mMessage= "" + aParams[0];
mMessage+= " est un index de ligne invalide";
mMessage+= " pour avoir une valeur";
mMessage+= " (dimension= " + aParams[1] + ")";
break;
case MATRICE_DIMX_SET:
mMessage= "" + aParams[0];
mMessage+= " est un index de colonne invalide";
mMessage+= " pour mettre une valeur";
mMessage+= " (dimension= " + aParams[1] + ")";
break;
case MATRICE_DIMY_SET:
mMessage= "" + aParams[0];
mMessage+= " est un index de ligne invalide";
mMessage+= " pour mettre une valeur";
mMessage+= " (dimension= " + aParams[1] + ")";
break;
case MATRICE_VIDE:
mMessage= "Cette matrice est vide";
break;
case MATRICE_PAS_INV:
mMessage= "Cette matrice n'est pas inversible";
break;
}
}
public String toString()
{
return "Erreur de matrice: " + mMessage;
}
}
public class Matrice
{
// Calcule la signature sur 1 dimension
private static int getSignDim(int aIndex)
{
return ( (aIndex % 2) != 0 )?-1:1;
}
// Calcule la signature sur 2 dimensions
private static int getSign(int aX, int aY)
{
return getSignDim(aX) * getSignDim(aY);
}
private double[] mValues;
private int mDim= 0;
public Matrice(int aDim)
{
mDim= aDim;
if( mDim < 0 )
mDim= 0;
mValues= new double[mDim * mDim];
}
public double getVal(int aX, int aY) throws MatriceError
{
if( aX >= mDim )
throw new MatriceError(MatriceError.MATRICE_DIMX_GET, new int[] {aX, mDim});
if( aY >= mDim )
throw new MatriceError(MatriceError.MATRICE_DIMY_GET, new int[] {aY, mDim});
return mValues[(mDim * aY) + aX];
}
public void setVal(int aX, int aY, double aValue) throws MatriceError
{
if( aX >= mDim )
throw new MatriceError(MatriceError.MATRICE_DIMX_SET, new int[] {aX, mDim});
if( aY >= mDim )
throw new MatriceError(MatriceError.MATRICE_DIMY_SET, new int[] {aY, mDim});
mValues[(mDim * aY) + aX]= aValue;
}
// Extrait la matrice privée de la colonne aX et de la ligne aY
private Matrice extract(int aX, int aY) throws MatriceError
{
Matrice lRes= new Matrice(mDim - 1);
int lI, lJ, lK, lL;