Está en la página 1de 3

import

import
import
import

javax.swing.*;
java.io.*;
java.lang.*;
java.math.*;

public class Mgaussseidel {


Mgaussseidel(){
double e1[]=new double[5],e2[]=new double[5],e3[]=new double[5],e4[]=new
double[5];
String v1,v2,v3,v4,r1,r2,r3,r4;
double uno,dos,tres,cuatro,a1,a2,a3,a4;
for(int f1=0;f1<4;f1++){
v1=JOptionPane.showInputDialog("ecuacion 1 \n Dame el valor de x"+(f1+1)
);
uno=Double.parseDouble(v1);
e1[f1]=uno;
}r1=JOptionPane.showInputDialog("Dame el resultado de eq1");a1=Double.pa
rseDouble(r1);
e1[4]=a1;
for(int f2=0;f2<4;f2++){
v2=JOptionPane.showInputDialog("ecuacion 2 \n Dame el valor de x"+(f2+1)
);
dos=Double.parseDouble(v2);
e2[f2]=dos;
}r2=JOptionPane.showInputDialog("Dame el resultado de eq2");a2=Double.pa
rseDouble(r2);
e2[4]=a2;
for(int f3=0;f3<4;f3++){
v3=JOptionPane.showInputDialog("ecuacion 3 \n Dame el valor de x"+(f3+1)
);
tres=Double.parseDouble(v3);
e3[f3]=tres;
}r3=JOptionPane.showInputDialog("Dame el resultado de eq3");a3=Double.pa
rseDouble(r3);
e3[4]=a3;
for(int f4=0;f4<4;f4++){
v4=JOptionPane.showInputDialog("ecuacion 4 \n Dame el valor de x"+(f4+1)
);
cuatro=Double.parseDouble(v4);
e4[f4]=cuatro;
}r4=JOptionPane.showInputDialog("Dame el resultado de eq4");a4=Double.pa
rseDouble(r4);
e4[4]=a4;
double
double
double
double
double

RI1[]=new double [4];


catch1[]=new double[4];
RI2[]=new double[4];
a[]=new double [4];
x0[]={0.0,0.0,0.0,0.0};

catch1[0]=(1.0/e1[0]);
System.out.print("ITERACION 1");
catch1[1]=(1.0/e2[1]);
RI1[0]=e1[4]/e1[0];
RI1[1]=catch1[1]*( (((e2[0]*RI1[0])+ (e2[1]*RI1[1])+(e2[2]*RI1[2])+(e2[3]*RI1[3]
))*(-1))+e2[4] );
catch1[2]=(1.0/e3[2]);
RI1[2]=catch1[2]*( (((e3[0]*RI1[0])+ (e3[1]*RI1[1])+(e3[2]*RI1[2])+(e3[3]*RI1[3]
))*(-1))+e3[4] );
catch1[3]=(1.0/e4[3]);
RI1[3]=catch1[3]*( (((e4[0]*RI1[0])+ (e4[1]*RI1[1])+(e4[2]*RI1[2])+(e4[3]*RI1[3]
))*(-1))+e4[4] );
System.out.print("\n x^1=("+RI1[0]+" , "+RI1[1]+" , "+RI1[2]+" , "+RI1[3]+" )");
double b,c,d,e;
b=Math.abs(RI1[0]-x0[0]); c=Math.abs(RI1[1]-x0[1]); d=Math.abs(RI1[2]-x0[2])
; e=Math.abs(RI1[3]-x0[3]);
// JOptionPane.showMessageDialog(null,"el valor absoluto es"+b+" "+c+" "+d+"
"+e);
double f=Math.max(b,c);
double g=Math.max(d,e);
double abs1=Math.max(f,g);
double h=Math.max(RI1[0],RI1[1]);
double k=Math.max(RI1[2],RI1[3]);
double abs2=Math.max(h,k);
double elrror=abs1/abs2;
System.out.print("\n el error absoluto es"+elrror);
//iteracion 2
System.out.print("\n \n ITERACION 2");
e1[0]=0.0;
RI2[0]=catch1[0]*( (((e1[0]*RI1[0])+ (e1[1]*RI1[1])+(e1[2]*RI1[2])+(e1[3]*RI1[3]
))*(-1))+e1[4] );
e2[1]=0.0;
RI2[1]=catch1[1]*( (((e2[0]*RI1[0])+ (e2[1]*RI1[1])+(e2[2]*RI1[2])+(e2[3]*RI1[3]
))*(-1))+e2[4] );
e3[2]=0.0;
RI2[2]=catch1[2]*( (((e3[0]*RI1[0])+ (e3[1]*RI1[1])+(e3[2]*RI1[2])+(e3[3]*RI1[3]
))*(-1))+e3[4] );
e4[3]=0.0;
RI2[3]=catch1[3]*( (((e4[0]*RI1[0])+ (e4[1]*RI1[1])+(e4[2]*RI1[2])+(e4[3]*RI1[3]
))*(-1))+e4[4] );
System.out.print("\n x^2=("+RI2[0]+" , "+RI2[1]+" , "+RI2[2]+" , "+RI2[3]+" )");
double l,m,o,p;
l=Math.abs(RI2[0]-RI1[0]); m=Math.abs(RI2[1]-RI1[1]); o=Math.abs(RI2[2]-RI1[
2]); p=Math.abs(RI2[3]-RI1[3]);
double q=Math.max(l,m);
double r=Math.max(o,p);
double abs3=Math.max(q,r);

double s=Math.max(RI2[0],RI2[1]);
double t=Math.max(RI2[2],RI2[3]);
double abs4=Math.max(s,t);
double elrror2=abs3/abs4;
System.out.print("\n el error absoluto es"+elrror2);

}//contructor
public static void main (String[] args) {
Mgaussseidel metodo=new Mgaussseidel();
}

También podría gustarte