You are on page 1of 3

EJERCICIO 2.

PROBLEMA
Disear mediante matrices la resolucin a un sistema de ecuaciones de N incognitas.

COMPILACIN
Primera clase:

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.

package sistem;
public class Sistem {
public static void main(String[] args) {

sustre obj=new sustre ();


int N=5;
double[][]calificaciones =new double[N][N];
double[] b=new double [N];
double[] x=new double [N];
for(int col=0;col<b.length;col++)
{
{ b[col]=(Math.random()*90)+1;}
}
calificaciones =obj.ejecuta (notas);
x= obj.regre(notas,b,x);
obj.imprimir(notas,b,x);
}
}
package sistem;
public class sustre {
double[][] carga(double[][]not)
{
for(int fila=0;fila<not.length;fila++)
{ for(int col=0;col<not[fila].length;col++)
{ if(fila<=col)
{ not[fila][col]=(Math.random()*20)+1;}
}
}

39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.

return not;
}

double[] regre(double[][]not,double []b, double x[])


{
for(int i=not.length-2;i>=0;i-- )
{
double s=0;
double sfin;
for(int j=not.length-1;j>=0;j--)
{
x[not.length-1]= b[not.length-1]/not[not.length-1][not.length-1];
s=not[i][j]*x[j]+s;
a.
54. }
55.
56. x[i]=(b[i]-s)/not[i][i];
a.
57. }
58.
59. return x;
60. }
61.
62.
63. void imprimir(double[][]not, double []b, double x[] )
64. {
65. System.out.println("Se tiene el siguiente sistema de ecuaciones:");
66. System.out.println();
67. for( int fila=0; fila<not.length;fila++)
68. {
69. for( int col=0; col<not[fila].length;col++)
70. {
a. System.out.printf("%12f",not[fila][col]);
b. int c=col+1;
c. System.out.print(" X"+c);
d. if(col!=not[fila].length-1)
e. {System.out.print(" +");}
71.
72. }
73.
74.
75. System.out.printf(" =%12f",b[fila]);
76.
77. System.out.println();

78.
79.
80.
81.
82.
83.
84.
85.
86.

System.out.println();
System.out.println("respuestas ");
for( int col=0; col<b.length;col++)
{
a. int c=col+1;
b. System.out.print(" X"+c+"=");
c. System.out.printf("%11f ",x[col]);
d. System.out.println();
e.
87. }
88.
89. }
90.
91. }

You might also like