Se soluciona un Sistema de Ecuaciones lineales por determinantes utilizando el lenguaje de programacion Java, Metodos Numericos, Analisis Numerico.
import javax.swing.table.DefaultTableModel;public class frmEcua extends javax.swing.JFrame {
DefaultTableModel modelA = new DefaultTableModel();
DefaultTableModel modelB = new DefaultTableModel();
DefaultTableModel modelX = new DefaultTableModel();
Deter D = new Deter();
public frmEcua() {
initComponents();
tblA.setModel(modelA);
tblB.setModel(modelB);
tblX.setModel(modelX);
cargaIni();
}
private void cargaIni() {
modelA.setColumnCount(3);
modelB.setColumnCount(1);
modelX.setColumnCount(1);
String titu[] = {"X"};
modelX.setColumnIdentifiers(titu);
String dat[] = new String[3];
String B[] = new String[1];
dat[0] = "1"; dat[1]="2"; dat[2]="3";
modelA.addRow(dat);
dat[0] = "1"; dat[1]="4"; dat[2]="9";
modelA.addRow(dat);
dat[0] = "1"; dat[1]="8"; dat[2]="27";
modelA.addRow(dat);
B[0] = "7"; modelB.addRow(B);
B[0] = "15"; modelB.addRow(B);
B[0] = "37"; modelB.addRow(B);
}
private void cargarM2() {
modelA.setRowCount(0);
modelB.setRowCount(0);
String titu[] = {"A","B"};
String dato1[] = {"0.55","1.55"};
String dato2[] = {"-0.55","3.55"};
String B[] = {"0.3545"};
modelB.addRow(B);
B[0] = "0.3595";
modelB.addRow(B);
modelA.setColumnIdentifiers(titu);
modelA.addRow(dato1);
modelA.addRow(dato2);
}
private void cargarM3() {
modelA.setRowCount(0);
modelB.setRowCount(0);
String titu[] = {"A","B","C"};
String dato1[] = {"0.55","1.55","2.55"};
String dato2[] = {"-3.55","4.55","-5.55"};
String dato3[] = {"5.55","-6.55","7.55"};
String B[] = {"1.1"};
modelB.addRow(B);
B[0] = "11.1";
modelB.addRow(B);
B[0] = "-15.1";
modelB.addRow(B);
modelA.setColumnIdentifiers(titu);
modelA.addRow(dato1);
modelA.addRow(dato2);
modelA.addRow(dato3);
}
private void cargarM4() {
modelA.setRowCount(0);
modelB.setRowCount(0);
String titu[] = {"A","B","C","D"};
String dato1[] = {"0.55","1.55","2.55","6.55"};
String dato2[] = {"-3.55","4.55","-5.55","7.55"};
String dato3[] = {"5.55","-6.55","7.55","8.55"};
String dato4[] = {"5","-6","7","2"};
modelA.setColumnIdentifiers(titu);
modelA.addRow(dato1);
modelA.addRow(dato2);
modelA.addRow(dato3);
modelA.addRow(dato4);
String B[] = {"3.5"};
modelB.addRow(B);
B[0] = "2.55"; modelB.addRow(B);
B[0] = "4"; modelB.addRow(B);
B[0] = "-2"; modelB.addRow(B);
}
private void cargarM5() {
modelA.setRowCount(0);
String titu[] = {"A","B","C","D","E"};
String dato1[] = {"0.55","1.55","2.55","6.55","2.55"};
String dato2[] = {"-3.55","4.55","-5.55","7.55","-5.55"};
String dato3[] = {"5.55","-6.55","7.55","8.55","1.55"};
String dato4[] = {"6.55","-6.55","7.55","8.55","10.55"};
String dato5[] = {"-8.55","-6.55","1.55","8.55","1.55"};
modelA.setColumnIdentifiers(titu);
modelA.addRow(dato1);
modelA.addRow(dato2);
modelA.addRow(dato3);
modelA.addRow(dato4);
modelA.addRow(dato5);
modelB.setRowCount(0);
String B[] = {"11.55"}; modelB.addRow(B);
B[0] = "12.55"; modelB.addRow(B);
B[0] = "4.55"; modelB.addRow(B);
B[0] = "-2.55"; modelB.addRow(B);
B[0] = "-5.55"; modelB.addRow(B);
}
private void btnCalActionPerformed(java.awt.event.ActionEvent evt) { int i,j;
int N = modelA.getRowCount();
double detA;
double detAx[] = new double[N];
String R[]= new String[1];
double B[] = new double[N];
double A[][] = new double[N][N];
double T[][] = new double[N][N];
modelX.setRowCount(0);
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
A[i][j] = Double.parseDouble(modelA.getValueAt(i, j).toString());
T[i][j] = A[i][j];
}
B[i] = Double.parseDouble(modelB.getValueAt(i, 0).toString());
}
detA = Math.round(D.deterM(A, N)*1000.0)/1000.0;
for(j=0;j<N;j++) {
for(i=0;i<N;i++) {
T[i][j] = B[i];
}
detAx[j] = Math.round(D.deterM(T, N)*1000.0)/1000.0;
copy(A,T,N);
}
for(i=0;i<N;i++) {
R[0]=detAx[i]/detA+"";
modelX.addRow(R);
}
}
private void cmbMActionPerformed(java.awt.event.ActionEvent evt) { int op = cmbM.getSelectedIndex();
switch (op){
case 0: cargarM2(); break;
case 1: cargarM3(); break;
case 2: cargarM4(); break;
case 3: cargarM5(); break;
}
}
private void copy(double A[][],double T[][],int N) {
int i,j;
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
T[i][j] = A[i][j];
}
}
}
Download Source Code
minuvasoft10@gmail.com - Miguel Nunez, se desarrolla proyectos software