1
40 System.out.printf("\t%.2f", m[i][j]);
41 }
42
43 }
44 System.out.println("");
45 }
46 System.out.println("");
47 System.out.println("");
48 }
49
50 public void llenarMatriz() {
51 Scanner entrada = new Scanner(System.in);
52 for (int i = 0; i < m.length; i++) {
53 for (int j = 0; j < m[i].length; j++) {
54 System.out.print("Ingrese el elemento [" + (i + 1) +
"," + (j + 1) + "]: ");
55 m[i][j] = entrada.nextInt();
56 }
57 }
58 System.out.println("");
59 }
/**
* Implementacin del algoritmo de Doolittle. Factorizacin LU.
* Factoriza una matriz de n x n como el producto de una matriz
triangular...
* ... inferior L y una matriz triangular superior U.
* @return ArrayList<double[][]> Lista que contiene las matrices L y
U.
*/
public ArrayList<double[][]> doolittle() {
int N = m.length;
U[0][0] = m[0][0];
2
for(int i=1; i<=N-2; i++) {
//-----------------------------------------------------------
sumaAux2 = 0.0;
sumaAux3 = 0.0;
}
}
//----------------------------------------------------------------
return matricesFactor;
}
//----------------------------------------------------------------------
public double[] sustitucionAdelante(double L[][], double b[]) {
int N = m.length;
double Y[] = new double[N];
Y[0] = b[0];
System.out.println("Y[1]: " + Y[0]);
double sumaAux;
for(int i=1; i<=N-1; i++) {
sumaAux = 0.0;
for(int j=0; j<=i-1; j++) {
sumaAux += L[i][j] * Y[j];
}
3
System.out.println("Y["+(i+1)+"]: " + Y[i]);
}
System.out.println("");
return Y;
}
//--------------------------------------------------------------------
public double[] sustitucionAtras(double U[][], double Y[]) {
int N = m.length;
double X[] = new double[N];
X[N-1] = Y[N-1] / U[N-1][N-1];
System.out.println("X["+N+"]: " + X[N-1]);
double sumaAux;
for(int i=N-2; i>=0; i--) {
sumaAux = 0.0;
X[i] = (Y[i]-sumaAux)/U[i][i];
System.out.println("X["+(i+1)+"]: " + X[i]);
}
return X;
}
4
2.- PRUEBA Y EJECUCIN.
Probamos el algoritmo resolviendo el siguiente sistema de ecuaciones de 4x4:
11 + 12 + 03 + 34 = 8
21 + 12 13 + 14 = 7
31 12 13 + 24 = 14
11 + 22 + 33 14 = 7
{
5
Una vez ingresada la matriz, el programa proceder a ejecutar el algoritmo de Doolittle,
resolviendo el sistema para el vector b = (8, 7, 14, -7):
X = (3, -1, 0, 2)